/ Published in: Bash
![](/img/icon_sav.png?v3)
Add an Apache virtual host via command line. Run as ./create mysite.domain.com
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/bin/bash VHOST_CONF=/etc/httpd/conf/httpd-vhosts.conf ROOT_UID=0 E_NOTROOT=87 WWW_ROOT=/var/www/vhosts # Run as root if [ "$UID" -ne "$ROOT_UID" ] then echo "Must be root to run this script." exit $E_NOTROOT fi if [ -n "$1" ] # Test whether command line present then DOMAIN=$1 else echo "You must provide a full domain name for this site, i.e. 'mysite.domain.net'." exit fi # create site folder mkdir $WWW_ROOT/$DOMAIN mkdir $WWW_ROOT/$DOMAIN/public_html chown riddleftp:ftp-users $WWW_ROOT/$DOMAIN -R CONF="" #echo $CONF >> $VHOST_CONF CONF="\n\n##################\n# $DOMAIN\n##################\n<VirtualHost *:80>\n DocumentRoot \"$WWW_ROOT/$DOMAIN/public_html\"\n ServerName $DOMAIN\n</VirtualHost>\n" echo -e $CONF >> $VHOST_CONF apachectl restart
Comments
![RSS Feed for Comments RSS Icon](/images/rss.png?v3)