Installing Apache2 and PHP5 on Ubuntu

Installing Apache2 and PHP5 on different platforms can be frustrating at times because of the differences involved in each platform. Especially true when you are new to a particular Operating System. Just today I had to install both these two software on my fairly newly installed Ubuntu laptop. And it took me some effort to accomplish that, which for an experienced user would have taken minutes. For those of you who might travel on this road too, here is the quick way to get Apache and PHP5 running on your Ubuntu computer.


sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart

Note: You may need first to add the extra repositories to your Ubuntu source.list file. This can be found in /etc/apt/sources.list. You need to comment out the following lines in the file:

deb http://us.archive.ubuntu.com/ubuntu dapper universe main restricted universe
deb http://security.ubuntu.com/ubuntu dapper-security universe

Once you have done that, run this command.

sudo apt-get update


After installing both Apache and PHP5, you will need to configure Apache for PHP5. To do that, these are the steps:

  • Using a text editor, in /etc/apache2/conf.d, create a file called php.conf
  • Your php.conf will contain the following lines
  • # PHP Configuration for Apache
    #
    # Load the apache module
    #
    LoadModule php5_module modules/libphp5.so
    #
    # Cause the PHP interpreter handle files with a .php extension.
    #
    AddHandler php5-script .php
    AddType text/html .php
    #
    # Add index.php to the list of files that will be served as directory
    # indexes.
    #
    DirectoryIndex index.php


Restart your apache server.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.