If the Raspberry Pi is intended for hosting one web site. The user can simply place all web page contents in the
/var/www/html
folder. If otherwise for hosting more than one websites, the contents of the second web site must be placed elsewhere. For example, create a subfolder for a website
site_a
underneath
/var/www
and place all its contents to the subfolder. Then, change ownership to
www-data
as follows:
$ cd /var/www
$ mkdir site_a
$ chown -R www-data:www-data site_a
The
apache
web server can redirect the second web site to its subfolder using a configuration file of a virtual host located in
/etc/apache2/sites-available/
. It is recommended to create a site-specific virtual host file for each and every one of all websites to be hosted.
$ cd /etc/apache2/sites-available
All virtual host files must end with
.conf
. In theory, one can create as many as the unit can bear. For illustration purpose,
site_a.conf
with minimum information required is created as follows:
<VirtualHost *:80>
ServerName site_a.com
ServerAlias www.site_a.com
DocumentRoot /var/www/site_a
ServerAdmin webmaster@localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Likewise, create
site_b.conf
for another by modifying the highlighted context as shown above. To enable a virtual host,
$ a2ensite site_a.conf
$ systemctl reload apache2
To see the list of all enabled virtual hosts,
$ cd /etc/apache2/sites-enabled
$ ls -l *.conf
A virtual host if enabled will show up in this directory. In fact all are symbolic links to the
conf
files created in
../sites-available
. To disable a virtual host,
site_a for example:
$ a2dissite site_a.conf
$ systemctl reload apache2