53849_Automatically Add Apache Vhost Container

Expand / Collapse
Alternatively to manually adding an apache vhost container, you may be able to use the vhostadd script.

Log into the web server the site is to be added to.
Sudo su - to the root user, permissions may be required:
sudo su -
Verify the file can be run, if you do not find the file, please contact our support to have it installed:
which vhostadd
The usage of the script is as follows:
# vhostadd
usage:  vhostadd <domain> <ip>

Running the script to configure the server for the site:
vhostadd example.com
The process continues as follows:

domain: example.com

are you sure these are correct? y/n > y

Note: Answering "N/NO/n/no" will halt the script, answering "Y/YES/y/yes" will output the below content. Ensurethe spelling of the domain and the IP address are correct, answer "Y"to continue.

domain and ip accepted.

DOMAIN: example.com

ROOT: /var/www/clients/example.com
WEBROOT: /var/www/clients/example.com/html
CGI-BIN: /var/www/clients/example.com/cgi-bin


CONF: /etc/httpd/sites/example.com.conf
As seen above, the script outputs useful information on the setup added. It creates a basicindex.html page, and an info.php page that displays details of PHP if installed.

NOTICE:  Apache must be restarted in order for the site to work.

If the script next requests for you to restart apache:
restart apache? y/n > choose 'n'.  The reason to this is that we want to verify the added configuration is safe and then restart apache

Check that the configuration is still valid and restart Apache if it is.
apachectl configtest
You want to ensure it responds with 'Syntax OK' prior to restarting Apache:
/etc/init.d/httpd restart

Version 2 of Script:
If you would like to use the newest version of this script, please contact Support.
The newer version of the script will offer you to perform a configtest, and with a passing result, Apache should be able to be restarted safely:

configtest apache? [y/n] > y
configtesting apache
Syntax OK
NOTICE:  you must restart apache in order for the site to work.

restart apache? [y/n] > y
restarting apache
Stopping httpd:                                            [  OK  ]
Starting httpd:                                             [  OK  ]

Additionally, the newer version of the script will create a user based on the domain entered and change the permissions for the directories created to that user.************************************************
subdomain.example.com username is: subdomain
The password for subdomain is:
Note: The shell for subdomain is set to /sbin/nologin for security reasons. This can be changed in /etc/passwd if needed.

If you happen to encounter issues restarting Apache, checking the main error_log for details will aid in troubleshooting.

/etc/init.d/httpd restart ; tail -f /var/log/httpd/error_log

Rate this Article:

Category: Apache

Last Modified:Monday, September 09, 2013 11:58 AM


Level: Beginner

Rated 5 stars based on 1 vote

Article has been viewed 5,525 times.

Email Article Email Article

Social Bookmarks Social Bookmarks