January 10, 2007 · Server · Email This Post

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

Incoming search terms:

Related posts

41 Comments to “Apache2 web server Installation with php4 and php5 support in Ubuntu”

  1. joinkzz says:

    i tested http://localhost/apache2-default/

    This message appears:

    The requested URL /apache2-default/ was not found on this server.

    I can’t access the Apache screen…

    thank you, Sir

    [Reply]

  2. Cyril says:

    I don’t know about http://localhost/apache2-default/. Mine works and I get a 404 on that (which proves it works anyway). Either do the /var/www/phptest.php or just go to http://yourserverip/ and you should see “It works”

    [Reply]

  3. joinkzz says:

    yes. i have already tried that…

    http://localhost/ and showed “It works”

    I browse through the /var/www/

    but the folder doesn’t consist phptest.php

    and still i cannot get the screen for the apache server using http://yourserverip/apache2-default

    please help me..

    thank you so much

    [Reply]

  4. Kevin says:

    This guide helped me get PHP up and running (I was trying just using Synaptic Package Manager).

    Thanks for the guide.

    [Reply]

  5. robbieb says:

    I needed all of the above to get me going but the permissions was the final clincher.

    HTH

    Rob

    [Reply]

  6. ang says:

    run “http://localhost/test.php” with browser
    or
    in a terminal run
    firefox http://localhost/test.php

    [Reply]

  7. Shane says:

    Thanks – pushed me in the right direction.

    As with anything on the net, things change and some of the directions are not available anymore.

    The initial line:

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

    needs to become

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

    as the original apache2-common file has been obsoleted.

    Could not find the directoryindex list in any of the .conf files I looked at, so Iwill do some reading and add these to the correct one later.

    Neither did apache2-default appear – again I will look at the docs and work out why.

    My ubuntu system (JJ 9.04) does not include gedit, so I substituted vi for it and had no problem creating the file (I was introduced to vi in 1983 and can still work my way around it when I have to).

    Thanks again
    Shane

    [Reply]

  8. something says:

    now, how do we get the “www.” in front of the domain name so that others can see it? or is it already visible on other networks?

    [Reply]

  9. David says:

    Worked a treat. Thanks for posting this…

    [Reply]

Leave a Reply