Install Apache Server on Ubuntu Linux
In this tutorial we will install the Apache web server on Ubuntu Linux machine. If you are looking for a manual that explains how you can install a web server with MySQL and PHP on Linux machine, you must visit our LAMP guide in the previous section.
Download and Install Apache
Open your Terminal (Applications > Accessories > Terminal) and run the following lines:
- sudo apt-get install apache2
[sudo] password for administrator: YOUR USER PASSWORD
After this operation, 10.3 MB of additional disk space will be used.
Do you want to continue [Y/n]? Y - Open your web browser and then enter the following into the web address: http://localhost
You will see a message saying "It works!".
Apache Configuration
By default, the apache DocumentRoot is “/var/www” directory. The files such as PHP or HTML will be placed in this directory and will be visible from the URL http://localhost. We want the “localhost” to point to another folder instead, /home/user/Public.
Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in the "/etc/apache2/sites-available" file. You can create many different site configurations available, and activate only those that you need.
We want the default site to be the "/home/user/Public/" directory (the "user directory" stands for your profile or your user name on linux).
- Create a new site, for example websol:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/websol - Edit the new configuration file in a text editor:
gksudo gedit /etc/apache2/sites-available/websol
Find the following lines:
DocumentRoot /var/www change to DocumentRoot /home/user/Public
<Directory /var/www/> change to <Directory /home/user/Public/> - Change all occurrence of "AllowOverRide None" to "AllowOverRide All" (to allow .htaccess file)
- Save the file
- Deactivate the old site
sudo a2dissite default - Activate the new site
sudo a2ensite websol - Enable the mod_rewrite module:
sudo a2enmod rewrite - Restart your apache
sudo /etc/init.d/apache2 restart - Test the new site, type console:
echo '<b>Hello! It is working!</b>' > /home/user/Public/index.html - Open your web browser and then enter the following into the web address: http://localhost and you will see a message saying "Hello! It is working!"
The following commands allow you to start, restart, stop Apache.
- sudo /etc/init.d/apache2 start
- sudo /etc/init.d/apache2 stop
- sudo /etc/init.d/apache2 restart


