Apache2 web server Installation with php4 and php5 support in Ubuntu

Sponsored Link
Apache HTTP Server is a free software/open source web server for Unix-like systems, Microsoft Windows, Novell NetWare and other platforms. Apache is notable for playing a key role in the initial growth of the World Wide Web,and continues to be the most popular web server in use, serving as the de facto reference platform against which other web serversare designed and judged.

Apache features configurable error messages, DBMS-based authentication databases, and content negotiation. It is also supported by several graphical user interfaces (GUIs) which permit easier, more intuitive configuration of the server.

Install apache2 in Ubuntu server

sudo apt-get install apache2 apache2-common apache2-mpm-prefork apache2-utils ssl-cert

This will complete the installation of apache2 web server and now you need to know where the configuration files and document root for your apache web server.

By default all your configuration files are located at /etc/apache2

Default document root for apache2 is /var/www.If you want to change the default document root you need to edit the /etc/apache2/sites-available/default file and look for this line “DocumentRoot /var/www/” here you can change whereever you want to change.For example if you want to change /home/wwww the above line looks like this “DocumentRoot/home/www/”.

The main configuration file located at /etc/apache2/apche2.conf.

Bydefault Apache2 to Listen on port 80. If this is not desired, please edit /etc/apache2/ports.conf as desired.after changing you need restart apache server.

For example if you want to change your apache webserver port to 78 you need to edit /etc/apache2/ports.conf

sudo gedit /etc/apache2/ports.conf

Look for the following line

Listen 80

Replace with the following line

Listen 78

Save the edited file

sudo /etc/init.d/apache2 restart

Installing php and cgi support for apache2 in Ubuntu

you need to have universe source list in your sources.list file

For php4 support

sudo apt-get install libapache2-mod-php4 php4-cli php4-common php4-cgi

For php5 support

sudo apt-get install libapache2-mod-php5 php5-cli php5-common php5-cgi

Next we edit /etc/apache2/apache2.conf file and check the index files are correct

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml

If you want to enable some Apache modules (SSL, rewrite, suexec, and include)

sudo a2enmod ssl

sudo a2enmod rewrite

sudo a2enmod suexec

sudo a2enmod include

Restart Apache to make sure all is well.

sudo /etc/init.d/apache2 restart

Test your apache Server

You can access you apache using http://yourserverip/apache2-default/ it should appear the following screen

Test apache2 with PHP Support
To test php4 installed correctly or not create a test file using the following command
sudo gedit /var/www/test.php

Insert the following line into the new file

<?php phpinfo();?>

Save this file

Now access this page http://yourserverip/test.php you should see the following screen

Sponsored Link

Related posts

41 thoughts on “Apache2 web server Installation with php4 and php5 support in Ubuntu

  1. if you give the option that you can change the port on which the apache is listening,
    you should replace you with for testing.

    This is trivial for some, but can also be confusing, so if you mention one, you should make some sort of comment about this.


  2. Surely if you want to enable Virtual Hosts for SSL support, then you have to create an “ssl-site” configuration file and add 443 to ports.conf so that Apache will listen to this port for secure connections.

    You also have to run this command to create your self-signed certificate…

    sudo apache2-ssl-certificate

    Unless you go for an official one.

    To activate your SSL site once you have created the configuration file “ssl-site” or whatever you want to call it, then you need this command…

    sudo a2ensite ssl

    If you haven’t got your configuration file correct, then Apache will complain when you relaunch it.

  3. I have been trying for hours to install PHP5 on (K)Ubuntu i’ve tried some really simple methods and some rather lengthy ones. I currently have executed the above instructions. All attempts result in the same thing. Instead of loading the test script, the browser tries to download the script file. I notice that my ssh window is griping about it when I try to load the script:

    servicetype application/x-httpd-php not found

    Any suggestions?

  4. I noticed that libphp5.so is in /usr/lib/apache2/modules. However, mod_php5.so is not. I noticed that most configuration instructions refer to mod_php5.so, not libphp5.so. Does anyone have any idea what’s going on?

  5. I have the same problem – or similar – to the one above – “All attempts result in the same thing. Instead of loading the test script, the browser tries to download the script file.”

    Any ideas here?

  6. you need to check /etc/apache2/apache2.conf file in search for DirectoryIndex in that you should be having php if you don’t have place that and restart apache server using the following command

    /etc/init.d/apache2 restart

  7. I’ve added the DirectoryIndex line to the conf file, but when I try to force a reload on Apache2, I get the following…

    apache2: Could not reliably determine the server’s fully qualified domain name, using for ServerName
    httpd (no pid file) not running
    apache2: Could not reliably determine the server’s fully qualified domain name, using for ServerName
    (98)Address already in use: make_sock: could not bind to address
    no listening sockets available, shutting down
    Unable to open logs [fail]

    Firefox still wants to try to download the script instead of running it. The real killer is that when I first downloaded phpsysinfo, it worked. After installing a few (seemingly) unrelated packages and not playing around with it over the weekend, I seem to have borked it. 🙁

  8. The error you have menctioned is another application using port 80 you can check this using the following command

    Run the following command

    sudo netstat -lnp | grep ‘’

    check the output and kill the other application

    One more thing check apache server(not apache2) is running

  9. Admin – thanks for the suggestion. It turns out that the other process using port 80 was apache. If I killed that process I was able to restart apache 2 with the modified .conf file. At that point, I was able to load the test.php file as above, but not the phpsysinfo. After a restart of the machine, # ps -A showed that Apache was running, but not Apache 2, I’m presuming because of the port collision as above. Any suggestions? Thanks!

  10. what was the exact problem with phpsysinfo?i personally believe it might have been messed up with apache,apache2 versions

  11. When trying to access ‘http://[computer IP]/phpsysinfo’, Firefox pops a Open with/Save to disk window. It doesn’t show a filename that it’s trying to open, just that it’s a PHTML file.

  12. JohnnyO: I had the same problem. Try with another browser, and if it’s OK, try to empty Firefox cache.

  13. How about, if you test the server and get a 403 error “Forbidden”
    I feel like the access rules must be off.

    My /var/www file is linked to a second hard drive
    lrwxrwxrwx 1 root root 19 2007-04-03 03:23 www -> /media/hdb1/wwwroot

    root@72:/home/wolf# ls -l /media/hdb1/
    total 12
    drwxr-xr-x 9 wolf wolf 4096 2007-04-03 03:14 hdb1.1
    drwxr-xr-x 2 root root 4096 2007-02-20 12:35 Recycled
    drwxr-xr-x 4 root root 4096 2007-05-10 21:41 wwwroot

    My webserver name appears to be off as well. Note that the user@host is root@72 and 72 is the first octet of the IP

    I want to run virtual sites at this server, and want it to be useful as a development server.
    BTW this is based on 6.06LTS

    The restart of the server shows
    root@72:/home/wolf# /etc/init.d/apache2 restart
    * Forcing reload of apache 2.0 web server… [Fri May 11 13:05:10 2007] [warn] NameVirtualHost *:0 has no VirtualHosts

  14. Hey guys, I got the Firefox trying to download my sites error, so I tried everything you guys suggested but now I get an Internal Error. Any more suggestions, pls? 🙂

  15. sorry guys I’m new to this apache and php stuff , I’m using apache2 , php5 and also phpmyadmin , but i ran into trouble while trying to connect to my computer from another computer the homepage is flawless , but every link will be redirected to , I’ve tried to edit /etc/apache2/apache2.conf but didn’t find anything related to my own ip address , so please help me out !!!
    here’s my apache2 information:

    thank you:)

  16. Hi people,

    i had the same problem (firefox didn’t open correctly php files in localhost when apache2 was running ok) but i cleaned cookies and temporals files (cache) and now it works fine… what a stupid thing, isn’t i?
    Thanks Claude!!!!

  17. gr8 finally worked for me.

    it was the cache problem with firefox,once i cleared the cache it showed 403 Forbidden error.

    i ran “$sudo chmod -R 777 .”in the /var/www directory……which was my apache’s home and it worked.

  18. I had the same problem where PHP files were not being loaded, but instead being downloaded but the web browser. To fix this what i noticed was that when i installed the php libraries and what not they were in /etc/apache2/mod-available and needed to be moved to /etc/apache2/mods-enabled

  19. Please run the following to enable php 4/5

    sudo a2enmod php5 or sudo a2enmod php4

    depending on which one you want enabled.

  20. Could not reliably determine the server’s fully qualified domain name, using for Servername

    what does this mean?

  21. Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch mod_ssl/2.2.11 OpenSSL/0.9.8g Server at Port 80

    i can’t test my Apache… the above message appears…

    can you help me with this?

    i test my php and it worked with

Leave a comment

Your email address will not be published. Required fields are marked *