Set Up Apache Virtual Host on Ubuntu 14.04 LTS

We have to install apache2 for own server

# sudo apt-get update
# sudo apt-get install apache2

Create new folder for site

# sudo mkdir -p /var/www/example.com/public_html

If you would like change permission you do that

# sudo chown -R $USER:$USER /var/www/example.com/public_html

 Add read access www folder

# sudo chmod -R 755 /var/www

Create a page

# sudo nano /var/www/example.com/public_html/index.html

Insert this text into index.html file:

<html>
<head>
<title>Welcome to
Example.com!</title>
</head>
<body>
<h1>Success! The
example.com virtual host is working!</h1>
</body>
</html>

You need create a Virtual Host file (in older version 000-default.conf was simple default file, but in the new version we have to use the new, and *.conf extension)

# sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

Edit config file

# sudo nano /etc/apache2/sites-available/example.com.conf

In the simple config file we can see like this

Apach2ConfigFile

Apache2 default config file

Add new lines to config file, and if you want, delete comments.
“ServerName” is usually your domain name like in IIS hostheader
“ServerAlies” this is a alternative name, this help matching for example www a record
“DocumentRoot” is a place where you going to store your website (in this example index.html)

<VirtualHost *:80>

ServerAdmin admin@example.com
ServerName example.com
ServerAlias http://www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

We have to enable site

# sudo a2ensite example.com.conf

Restart service

# sudo service apache2 restart

After restart you will see something like this

* Restarting web server apache2
AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message

Don’t worry, this is OK.

I checked my site on server

Edit host file, add you server’s ip address into host file

# sudo nano /etc/hosts

YOURIP example.com

Check: ping example.com, and if you getting answer, your host file settings are ready

# w3m example.com (w3m is a command line browser, i checked my site by this tool)

press “q” to quit from w3m browser

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s