VirtualHost Generator
VirtualHost generator









Create VirtualHost

nano /etc/apache2/sites-available/001-www.example.com.conf

<VirtualHost *:80>
    ServerAdmin root@example.com
    ServerName www.example.com
    ServerAlias example.com
    Protocols h2 http/1.1

    <If "%{HTTP_HOST} == 'example.com'">
        Redirect permanent / http://www.example.com/
    </If>

    DocumentRoot /var/www/www.example.com/public_html
    <Directory "/var/www/www.example.com/public_html/">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/www.example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/www.example.com-access.log combined
</VirtualHost>
Enable site and restart Apache
  1. a2ensite 001-www.example.com.conf
  2. mkdir -p /var/www/www.example.com/public_html ; echo 'Hello World!' > /var/www/www.example.com/public_html/index.html
  3. apache2ctl configtest
  4. service apache2 restart; service apache2 status