How to Install Apache 2 on Ubuntu 10.04 (with PHP5 and MySQL support) [Guide]

By Karthik P | How-to

Apache HTTP server is one among the most popular web server software. It is an open source software developed by an open community of developers. And it is easily available on a wide variety of operating systems, that of course includes Linux.

Here is another ubuntu guide for Ubuntu users on installing Apache 2. Assuming this to be your first shot at performing the install of Apache 2 on Ubuntu 10.04, I’ve written a very detailed and step by step (lengthiest, I know) guide.

Okay, so installing an Apache server with PHP5 and MySQL support can help you create your own home server for testing your files. That being said, lets get things right off the bat:

1. Quickly Installing Apache2

Entering a simple command in the Terminal will start the installation process. Follow the steps below to install Apache2.

i. Navigate to Applications > Accessories > Terminal to fire up the terminal window.

ii. Enter the following command to start the installation:

sudo apt-get install apache2

It will ask for your password. Enter the password and hit Enter. Further, follow the instructions that appear on the screen.

iii. Once the installation is completed, close the Terminal window. Open your web browser and enter the following URL to test if the installation is successful:


If successful, you will see the Apache2 placeholder page. (Image below)

Apache2 Placeholder Page

Apache’s default Document Root on Ubuntu is /var/www/. Document Root is the directory is designated to hold web pages.

Changing the default Document Root

Apache allows you to change the default document root to any location on your PC. Changing the document root requires you to edit the configuration files. Here’s how you can do it.

i. Choose the location on your PC that you would like to use as the document root. (For ex: /home/<user>/server)

ii. Now, enter the following command :

sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/webserver

This command copies the contents of the default configuration file to a new file (webserver).

iii. Edit the new configuration file using gedit.

sudo gedit /etc/apache2/sites-available/webserver

iv. In the configuration file change the Document Root to point to the location you want.

DocumentRoot /home/<user>/server/

v. Also change the Directory to point to the new location.

<Directory /home/<user>/server/>

vi. Save the file. To deactivate the default configuration file and activate the new file enter :

sudo a2dissite default && a2ensite webserver

vii. Restart the Apache HTTP Server for changes to take place.

sudo /etc/init.d/apache2 reload

That’s it! You can now copy your web pages to the specified directory.

2. Installing PHP5

PHP is a widely used scripting language used by a lot of web developers for designing dynamic web pages. Most of the modern web servers support PHP. Follow the given steps to install PHP5.

i. Enter the following command to install PHP5 and Apache PHP5 module :

sudo apt-get install php5 libapache2-mod-php5

ii. Restart Apache2.

sudo /etc/init.d/apache2 reload

To test if PHP5 is working, let’s create a small php file called phpinfo.php. This file gives you useful details of your PHP installation.

i. Create the phpinfo.php file using gedit.

sudo gedit /home/<user>/server/phpinfo.php

ii. Copy the following code into the file and save it.

<?php phpinfo(); ?>

iii. Now, open your web browser and enter the following URL.


You will get a web page as shown below.

PHP Info

This shows that PHP5 has been successfully installed on your OS.

3. Installing MySQL

MySQL is one among the most secure and reliable database management systems. Many high traffic sites like Google, Flickr, Facebook,etc. use MySQL for data storage and logging of user data. The following are the steps to install MySQL on Ubuntu.

i. Fire up the Terminal and enter the following command:

sudo apt-get install mysql-server mysql-client

During the installation, you will be asked to provide a password for the MySQL “root” user. This password will be used to login to MySQL.

ii. After installing MySQL, you need to configure PHP to use MySQL. Installing the php5-mysql package enables MySQL support in PHP. It enables you to use PHP to connect to MySQL databases.

sudo apt-get install php5-mysql

iii. Installing phpMyAdmin : phpMyAdmin is a web interface for managing your MySQL databases. It can perform various actions such as creating, deleting, modifying databases etc. To install phpMyAdmin enter the following command :

sudo apt-get install phpmyadmin

During the installation use the following options:

Web server to configure automatically: Apache2

Configure database for phpmyadmin with dbconfig-common?: No

iv. To access phpMyAdmin, open your browser and enter the following URL:



That’s it! Apache2 has been successfully installed on your Ubuntu 10.04. Start testing your web pages on your own home server.

If you are experiencing any problems during installation, do let us know.

About the Author

Karthik is a 19 year old blogger from Karnataka, India. He's a hardcore tech addict and always keeps himself up-to date with the latest technology; be it the latest tech news or the newly released gadgets. He's also a social networking enthusiast and can be found active on twitter @k_karthikp

Leave a Comment:

(26) comments

Meriem March 8, 2015

Now it s working but I cant find the folder “server” anywhere! I feel like the changes didnt occur and, since I cant find “server” I dont know where to place my web page in ordre to display it, please help 🙁

Meriem March 7, 2015

Thanks for the tutorial, unfortunately it hasnt worked for me, it shows Not Found 404 while it worked perfectly before I tried the commands to change its default document root, I think because of this command :sudo a2dissite default && a2ensite webserver

I tried it also with sudo su, and the suggestion Claudio gave in the comments, still not working; any other suggestions, I never used Apache before :/

Bogdan April 22, 2011

ubuntu@ubuntu-laptop:~$ sudo /etc/init.d/apache2 reload
apache2: Syntax error on line 230 of /etc/apache2/apache2.conf: Syntax error on line 41 of /etc/apache2/sites-enabled/webserver: Expected but saw
Action ‘configtest’ failed.
The Apache error log may have more information.

Bogdan April 22, 2011

Syntax error on line 230 of /etc/apache2/apache2.conf: Syntax error on line 41 of /etc/apache2/sites-enabled/webserver: Expected but saw
Action ‘configtest’ failed.
The Apache error log may have more information.

hasssan March 8, 2011

thanks for your post man, this is first time i set up server on my machine manually. recently i’ve used lampp for my server.

steve December 7, 2010

Dude! Very nice! the only hiccup I had was a permission issue at the “sudo a2dissite default && a2ensite webserver”.
I just did a “sudo su” and voila. Thanks again.

    jitu March 22, 2011

    sudo apt-get install mysql-server
    is not working on my laptop.It says—
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    mysql-server: Depends: mysql-server-5.1 but it is not going to be installed
    E: Broken packages

zfray November 21, 2010

always got trouble every time I setup ubuntu as a web server, I always forgot the packages to install in it.. thanks for this post.. ^_^

Pradeep Kumar November 5, 2010

You have done the excellent job. You have given a Nice article.

But There is an error message telling Access Denied while using This command:

sudo a2dissite default && a2ensite webserver

This command should be given as root (i.e after being root) using “su” Command.

Thank you

girish October 15, 2010

Nice article dude..
good description in brief..

Vishal October 3, 2010

Nice tutorial. Just edit the localhost to the IP of the vps/server you are using so it will be better to ones who have problem.

swathi October 3, 2010

thank u.I found it very useful.

TjK September 23, 2010

look here if you get error while testing phpmyadmin

TjK September 23, 2010

I have Ubuntu 10.04 installed in in Windows with Virtualbox.
I am a newbie as far PHP, Mysql, and Apache are concerned.

I followed the steps but I have a problem at the end.
When testing phpmyadmin by entering http://localhost/phpmyadmin/
I have the error :
Not found
The requested URL /phpmyadmin/ was not found on this server.
Apache/2.2.14/ (ubuntu) Server at localhost Port 80

Your assistance will be greatly appreciated.


manu August 19, 2010


have you had a go at getting Bugzilla up and running on Ubuntu. It uses all the components – Apache2, MySQL and PHP. Bugzilla is a free trouble ticketing application.

– manu

alex August 3, 2010

This was quite good tutorial. I used webmin to set up my apache and MSQL server but i reinstalled using ur codes both apache and msql and php. how ever the code “sudo a2dissite default && a2ensite webserver” dint work for me but some how managed to get the site up.. and my php is also working but when i access it, it asks for username and password. i tried my root user paswd but dint let me in. can u sugest any solution to this..

chitalian July 28, 2010

I installed phpmyadmin, but when I tried accessing it from http://localhost/phpmyadmin, I got a 404 error. Any ideas?

Santtu July 9, 2010

Nice and clear even for an ubuntu newbie like me =)

Claudiu T. July 1, 2010

Nice guide, but shouldn’t this:

sudo a2dissite default && a2ensite webserver

sudo a2dissite default && sudo a2ensite webserver

    Karthik P July 1, 2010

    Thanks for the suggestion Claudiu. But I guess both work pretty much the same.

      cheese September 7, 2010

      just came to say Claudiu T. is right, until i’ve found his suggestion, Apache has shown 404 error and nothing else

Trevor June 30, 2010

Great little tutorial. Thanks! 🙂

pramod June 25, 2010


I am a beginner in this field. I am trying to make my machine a server. I followed the steps and everything worked fine. How can I know the ip address of my machine and test it from a different machine. I did ifconfig and took the inet address, typed in the address bar to see if it works. I got this error message for all the inet addresses.


You don’t have permission to access / on this server.
Apache/2.2.14 (Ubuntu) Server at Port 80

Awaiting your reply.


    Karthik P July 1, 2010

    If you wanna know your IP address just try visiting or else go to your Terminal and type “plog”. (without the inverted commas). Copy your IP address and paste it into your browser. You will be able to access your webpages from any computer as long as you are connected to the internet.

Srikanth AD June 23, 2010

Thanks for the useful tutorial. I believe it is much easier to install Apache, MySQL and PHP using XAMPP on Ubuntu.


Pete June 22, 2010

Thanks mate. Nice guide.

Add Your Reply

Leave a Comment: