Apache Vhost
1. First create a directory where all the vhost will be stored (mine will be in /etc/httpd/sites
mkdir /etc/httpd/sites
2. Create a new file with servername.conf
using:
vim /etc/httpd/sites/servername.conf
3. Usually it should have following content:
- <VirtualHost *:80>
- ServerName example.com
- ServerAlias www.example.com
- DocumentRoot /path/to/website/directory
- ErrorLog /path/to/error/log
- CustomLog /path/to/access/log
- <Directory /path/to/website/directory>
- AllowOverride None
- DirectoryIndex index.html index.php
- Require all granted
- </Directory>
- </VirtualHost>
- It is the opening block for the vhost and it listens on port 80 (can also be 443 or 8080 depending on the application)
- It will be the servername which is usually the domain name of the website
- Another name which will point to the same website and same documentroot. Common examples is www.example.com
- Where your website files is stored
- Where error log will be stored
- Where access log will be stored
- Start of directory block where information about the directory is found
- Option to either allow all access to website or allow access to only authenticated users using .htpasswd and .htaccess
- Specifies which file will be displayed on eterring the website (usually index.html or index.php)
- Access control
- Closing of directory block
- Closing of Vhost block
4. The following line should then be addeed so that Apache
can load the vhosts:
IncludeOptional relative/path/to/file/*.conf
It will load all files with extension .conf
found int the directory specified.