Can anyone recommend a easy CLI script to manage VHOSTS?
9 Replies
You could probably edit it for php and wordpress. I'm sure there are more out there.
#! /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
Looking for a CLI script for NGINX, installing WordPress is a bonus.
Curious what others might be using. Thanks!
@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.
@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…
@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:
Remember though - it's specifically for my own purposes so it might not fit what you're looking for