Tags

,

Create Virtual Host Files
By default, Apache comes with a default virtual host file called 000-default.conf. We will copy the 000-default.conf file contents to our new virtual host files.

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.local.conf
# Make the relevant changes that reflect to the site.
sudo vi /etc/apache2/sites-available/mysite.local.conf
# Add the following scripts below to mysite.local.conf
<VirtualHost *:8081>
ServerAdmin webmaster@mysite.local
ServerName mysite.local:8081
ServerAlias www.mysite.local
DocumentRoot /var/www/html/mysite.local/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Edit ports.conf, add port for our site

sudo vi /etc/apache2/ports.conf
Listen 8081

After modifying the virtual hosts files, you can enable it now:

##To enable the site:
$ cd /etc/apache2/sites-available
$ sudo a2ensite mysite.local.conf
$ service apache2 reload
##To disable the site:
$ sudo a2dissite mysite.local.conf

Finally, restart the apache service.

sudo service apache2 restart      # for Ubuntu 14.10
sudo systemctl restart apache2    # for Ubuntu 15.04
sudo /etc/init.d/apache2 restart  # for Ubuntu 15.04

Thats it, the site is ready to serve!! Type the url in your browser
mysite.local:8081. If it does not appear then there’s something wrong in the configuration. Check the error log for debugging..

$ tail -f /var/log/apache2/error.log

How to list all vHosts Currently enabled In Apache.

$ apache2ctl -S   # for Ubuntu/Debian
$ httpd -S        # for CentOS

If you encountered an error that says “apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message”
Solution:

$ sudo vi /etc/apache2/apache2.conf

# Add this line and then restart it
ServerName localhost

$ sudo /etc/init.d/apache2 restart
artheman@ub3c:/etc/apache2/sites-available$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting apache2 (via systemctl): apache2.service.
artheman@ub3c:/etc/apache2/sites-available$ apache2ctl -S
VirtualHost configuration:
*:80 localhost (/etc/apache2/sites-enabled/000-default.conf:1)
*:8081 ciblog.local (/etc/apache2/sites-enabled/ciblog.local.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl 
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
Advertisements