Can anyone recommend a easy CLI script to manage VHOSTS?

Just wondering if anyone can recommend a lightweight command line script for managing Apache on Ubuntu boxes? Bonus would be for deploying WordPress installations :P

9 Replies

This is the only one I know of off the top of my head:

https://github.com/coto/server-easy-install#readme

You could probably edit it for php and wordpress. I'm sure there are more out there.

I use a script from http://commandlineidiot.com which I have modified to fit my needs. It just adds domains, but I have been meaning to add a function to remove domains.

#! /bin/bash 
# 
# =======================
# Siteup Script 0.5
# Written by Command Line Idiot
# http://commandlineidiot.com
# You may use, modify, and redistribute this script freely
# Released: August 2007
# Modified by Josh Price
# Re-Release: July 2012
# =======================

# =======================
# Root check
# =======================
# init
FILE="/tmp/out.$"
GREP="/bin/grep"

if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi
# End Root Check

# =======================
#    set functions
# =======================
#    make_index is the function to create a basic index.html file
#     within the documents directory of the new domain. The variable
#     for domain name is passed into the file at $dname. You can alter
#    any of the code between the terms _EOF_ and it will be reflected
#    in the index.html file.
function make_index
{
cat <<- _EOF_

    <title>$dname</title>
    $dname Coming Soon. 

_EOF_
} 
# =======================
# End make_index
# =======================

#    make_vhost is the function to create a config file that
#    Apache2 can interpret. The variable for the domain name is passed
#    into the file at $dname, and the system-wide variable for username
#    is passed into the file at $USER. You may wish to replace the
#    ServerAdmin email address with your own email address. You may alter
#    any of the code between the terms _EOF_ to build your own preferred 
#    standard config file.  

function make_vhost
{
cat <<- _EOF_
     <virtualhost *:80=""># Admin email, Server Name (domain name), and any aliases
        ServerAdmin support@$dname
        ServerName  www.$dname
        ServerAlias $dname

         # Index file and Document Root (where the public files are located)
          DirectoryIndex index.html index.php
          DocumentRoot /home/USERNAME/sites/$dname/public_html

          # Log file locations
          LogLevel warn
          ErrorLog  /home/USERNAME/sites/$dname/log/error.log
          CustomLog /home/USERNAME/sites/$dname/log/access.log combined</virtualhost> 
_EOF_
}

# =======================
#         header
# =======================
clear  
echo "***      Site Setup      ***"

# =======================
# set domain name variable
# =======================
echo -n "==> Enter new domain name (domain.com): "
read dname
echo "Setting up files for $dname"

# =======================
# create needed directories
# =======================
mkdir -vp /home/USERNAME/sites/$dname
mkdir -vp /home/USERNAME/sites/$dname/log
mkdir -vp /home/USERNAME/sites/$dname/public_html
touch /home/USERNAME/sites/$dname/log/access.log 
echo "created /home/USERNAME/sites/$dname/log/access.log"
touch /home/USERNAME/sites/$dname/log/error.log 
echo "created /home/USERNAME/sites/$dname/log/error.log"

# =======================
# build index file
# =======================
make_index > /home/USERNAME/sites/$dname/public_html/index.php
echo "created /home/USERNAME/sites/$dname/public_html/index.php"

# =======================
# build vhost config file
# =======================
make_vhost > /etc/apache2/sites-available/$dname
echo "created /etc/apache2/sites-available/$dname"

# =======================
# Add site to Apache
# =======================
a2ensite $dname

# =======================
# Restart Apache
# =======================
/etc/init.d/apache2 reload

# =======================
#    exit
# =======================

echo "***      Finished setting up files for $dname. Goodbye!"
exit

Edit as you need. Replace USERNAME with your username.

You could easily add wordpress installation to this

I'd like to bump this as it's been a while. Still haven't found anything that really fits a need.

Looking for a CLI script for NGINX, installing WordPress is a bonus.

Curious what others might be using. Thanks!

You know how to make it manually right? Why not adjust the script yourself to fit your purposes. Just read it, it really isn't that hard :)

@mattm:

I'd like to bump this as it's been a while. Still haven't found anything that really fits a need.

Looking for a CLI script for NGINX, installing WordPress is a bonus.

Curious what others might be using. Thanks!

I use vi.

Well you did ask.

It's really to give to a support type person, so they can create the domain(s) without me having to worry about them having direct access. Thanks anyway! ;)

Well, different users want different things. I have a script I use for nginx that creates a user and SFTP chroots them on Debian. It creates public_html/tmp/logs directories and sets up a PHP-FPM pool for them. It doesn't install Wordpress. I could pass along that one for you, but I can't guarantee it'll work for you, plus you may have a different configuration SFTP / PHP-FPM wise.

@Nuvini:

Well, different users want different things. I have a script I use for nginx that creates a user and SFTP chroots them on Debian. It creates public_html/tmp/logs directories and sets up a PHP-FPM pool for them. It doesn't install Wordpress. I could pass along that one for you, but I can't guarantee it'll work for you, plus you may have a different configuration SFTP / PHP-FPM wise.

I have nginx and I am looking for a script to manage it.

It would be a kindness if you were to share it here on the forum…


Free hosting

@snippet:

@Nuvini:

Well, different users want different things. I have a script I use for nginx that creates a user and SFTP chroots them on Debian. It creates public_html/tmp/logs directories and sets up a PHP-FPM pool for them. It doesn't install Wordpress. I could pass along that one for you, but I can't guarantee it'll work for you, plus you may have a different configuration SFTP / PHP-FPM wise.

I have nginx and I am looking for a script to manage it.

It would be a kindness if you were to share it here on the forum…
Here you go:

http://pastebin.com/vcbVacGB

Remember though - it's specifically for my own purposes so it might not fit what you're looking for :)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct