Installing Apache and PHP on Ubuntu

This code and article have been tested and work for Ubuntu 9.10

Installing Apache on Ubuntu is relatively simple and can be done in four or five commands with little or no experience.

First we install Apache

sudo apt-get install apache2

This will install and start the web server, create the /var/www directpry for your web pages, create the Apache2 service and install apache2ctl a command line tool to controlĀ  the web server.

To test the installation is working open your browser to http://localhost/ you should see a plain page that says “It works!”. That will let you know your web server is running and serving up static HTML pages. Any web pages you put in /var/www/ will be available to view under http://localhost/

If you only want to develop static web pages this will be enough, if however you would like to create scripted pages with PHP you will need to install the PHP 5 binaries and the libraries needed for Apache integration.

sudo apt-get install php5

Will install PHP 5

sudo apt-get install libapache2-mod-php5

will install the Apache PHP module to glue the two pieces together.

Assuming you got no errors you should be setup and ready to develop PHP applications on an Apache server. Restart Apapche for the changes to take effect with

sudo apache2ctl restart

To test that PHP pages are being correctly executed create the file create a test php file.

sudo gedit /var/www/test.php

Put the following code into the file and nothing else

<?php
phpinfo();
?>

open your web browser to http://localhost/test.php if you see a purple page with your System and PHP information on it you have a fully functional development environment.

Congratulations and get your code on!

VN:F [1.9.17_1161]
Rating: 0.0/5 (0 votes cast)
Share the Love
Get Free Updates

Related posts:

  1. Installing a SSH Server on Ubuntu 8.10 or 9.10
  2. Installing and Running Aptana on Ubuntu 8.10 (Ubuntu Intrepid)
  3. Installing and Running Firefox 2 on Ubuntu 8.10
  4. How to build a complete website

Tags: ,

7 Responses to “Installing Apache and PHP on Ubuntu”

  1. Fadli says:

    It worked very well on my laptop.
    Thank you so much.

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
    • Jim says:

      Hi,
      I downloaded the 'httpd-2.2.11.tar.gz', & 'httpd-2.2.11.tar.gz.asc' files, but on doing an "sudo apt-get install apache2", what I get is "E: Couldn't find package apache2".

      Please help !!
      Jim

      VA:F [1.9.17_1161]
      Rating: 0 (from 0 votes)
  2. Chad says:

    Doesn't work for me. The browser wants to download the PHP file rather than open it in the browser. Believe it or not, I have been battling this for two days now and finally purged my LAMP set-up and used this guide to re-install Apache/PHP.

    I'm disappointed that I can't seem to find anyone to help me, i've posted in the Ubuntu forum but nobody seems to be able to assist. I've read countless tutorials and chapters but cannot find resolution.

    Linux just seems woefully inconsistent – what works for one user won't work for another. I've never seen such disparity in terms of suggestions/tutorials and what actually works. I guess Windows really is the best, most consistent OS.

    What other outlook can I possible take based upon my recent experience?

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
  3. holibut says:

    So useful and clear a document!

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
  4. Dcpower says:

    I followed the steps and in less than 5 Min I was able to get it up and running on ubuntu 8.10… and i don't have any know how of this before… dough … that's why i was here…..

    THANKS>>… this was just too easy… :)

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
  5. Timo says:

    WORKS!!! Thanks a lot!

    - only one message came up when I restarted with sudo apache2ctl restart: " Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName" (I checked my etc/hosts file and 127.0.1.1 is set to localhost …). that's minor though; the important part is it works ^^

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)
  6. Vern says:

    I did the install and By Thunder it Works! no problems. Good job guys.

    VA:F [1.9.17_1161]
    Rating: 0 (from 0 votes)

Leave a Reply