Server Side
Now Reading
Install and Configure Apache on Ubuntu with Virtual Hosts
0

Install and Configure Apache on Ubuntu with Virtual Hosts

by Adrian RandallMay 13, 2015

Setting up a web server is always made out to be a lot more complicated than what it has to be. If you’re not looking to fine tune and harden it for a live deployment and just want to get something setup for a development environment it shouldn’t take longer than 5 mins (unless you have a terrible internet connection).

I’m assuming you’re running Ubuntu, but if you’re not and you’re using Mac you can just swap out the ‘apt-get’ to ‘brew’ in most cases if you have it installed.

  1. Make sure you don’t have another web server installed such as NGINX. You can test this by running ‘nginx -v’ and you’ll get an error if there is no other ones installed.
  2. sudo apt-get update
  3. sudo apt-get install apache2
  4. Check it worked by running ‘apache2 -v’. You will see some Apache Version print to the console if it’s working.
  5. Run “sudo nano /etc/apache2/apache2.conf” ensure the following line is uncommented “IncludeOptional sites-enabled/*.conf”. You can search for text by pressing ‘ctrl+w’ in nano text editior. If this is commented then you can’t add virtual hosts. 
  6. cd /etc/apache2/sites-available
  7. Create a file to store your config in and remember to add .conf as the extension so it is picked up by Apache “sudo nano dev.wordpress.com.conf”
  8. Enter the following config

<VirtualHost *:80>
ServerAdmin name@example.com
ServerName dev.wordpress.com
ServerAlias www.dev.wordpress.com
DocumentRoot /home/user/wordpress

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory /home/user/wordpress>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Allow from all #add this is your directory is outside /var/www/html/*
</Directory>

</VirtualHost>

  1. Change to the sites-enabled directory

cd /etc.apache2/sites-enabled

  1. We need to create a symbolic link (kinda like a shortcut) to the conf file we just created so Apache can pick it up

sudo ln -s ../sites-available/dev.cordpress.com.conf

  1. Restart Apache to pickup our latest changes

sudo service apache2 restart

Tip:

Depending on how you set it up or the state of your server you may see the PHP files rendering as text. If this happens you probably just need to Apache PHP Module so run:

sudo apt-get install libapache2-mod-php5

If your rewrites aren’t working (internal pages) and you’ve setup a .htaccess file then maybe you need to enable mod_rewrite. Run:

sudo a2enmod rewrite

sudo service apache2 restart

If we’ve missed anything please let me know below.

About The Author
Adrian Randall
I'm a digital marketing specialist, love working on digital business and coding on just about anything. I'm the founder of Arcadian Digital and this site shares some of our knowledge and practices.

Leave a Response