Friday, March 2, 2018

Running multiple websites on one apache using virtual host

cp -p /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.conf
mkdir -p /var/www/html/example

cat /etc/apache2/sites-available/example.conf

<VirtualHost *:80>
<Directory "/var/www/html/example">
    AllowOverride All
</Directory>

        ServerAdmin example@example.com
        ServerName example.com
        ServerAlias www.example.com
        DocumentRoot /var/www/html/example

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


cp -p /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/secondexample.conf
mkdir -p /var/www/html/secondexample

cat/etc/apache2/sites-available/secondexample.conf

<VirtualHost *:80>
<Directory "/var/www/html/secondexample">
    AllowOverride All
</Directory>

        ServerAdmin secondexample@secondexample.com
        ServerName secondexample.com
        ServerAlias www.secondexample.com
        DocumentRoot /var/www/html/secondexample

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


sudo a2ensite example.conf
sudo a2ensite secondexample.conf


sudo service apache2 restart


now both awesomesite and example with work from same apache as long as thier files are under correct document directory

No comments: