Having a dedicated Linux box without any form of control panel on it is becoming the norm for me. To help me out, I created a small shell script to create the necessary files in the right places.
It takes 2 inputs at the command line.
The first is a domain name – this is used to create a folder and within the “sites-available” definition.
The second is a username. A new FTP only (i.e. locked out of SSH) user is created.
The script doesn’t really have much validation in it and is probably very easy to break.
The script relies on a default site definition (~/sites-available.txt) with the keyword “MYWEBSITE” where the script replaces the domain name. It also relies on a default template (~/TEMPLATE/) for the site. For me, this just includes 3 folders – httpdocs, conf and logs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#!/bin/bash if [ -z "$1" ]; then echo usage: $0 domainname - friendly! exit fi if [ -z "$2" ]; then echo usage: $0 second arguement should be a user to create! exit fi # MAKE THE DIRECTORY mkdir /var/www/vhosts/$1 cp -R ~/TEMPLATE/* /var/www/vhosts/$1 chown username:groupname -R /var/www/vhosts/$1 # CHECK THAT THE USER DOESN'T ALREADY EXIST egrep "^$2" /etc/passwd >/dev/null if [ $? -eq 0 ]; then echo "$2 exists!" exit 1 else # CREATE A NEW FTP USER FOR THIS FOLDER /usr/sbin/useradd -d /var/www/vhosts/$1/httpdocs/ -s /dev/null $2 > /dev/null 2>&1 passwd $2 fi chown $2:$2 /var/www/vhosts/$1/httpdocs/ cp ~/sites-available.txt /etc/httpd/sites-available/$1 sed -i "s/MYWEBSITE/$1/g" /etc/httpd/sites-available/$1 ln -s /etc/httpd/sites-available/$1 /etc/httpd/sites-enabled/$1 nano /etc/httpd/sites-available/$1 |
Image Credit: Rosa Menkman
Comment or tweet @douglasradburn