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

Related posts

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

  1. tinbox says:

    What if it does not work?

    mine just show the line that just been typed in

  2. admin says:

    if nothing is showing then your php is not enabled for your apache server

  3. tinbox says:

    Thanks.

    It was a mistype when I check on the DirectoryIndex.

    All is working fine now

  4. idokus says:

    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.

    Greets

  5. guyran says:

    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.

  6. squiggs says:

    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?

  7. squiggs says:

    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?

  8. BobScott says:

    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?

  9. admin says:

    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

  10. JohnnyO says:

    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 127.0.1.1 for ServerName
    httpd (no pid file) not running
    apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
    (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
    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. 🙁

  11. admin says:

    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 ‘0.0.0.0:80’

    check the output and kill the other application

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

  12. JohnnyO says:

    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!

  13. admin says:

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

  14. JohnnyO says:

    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.

  15. Claude says:

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

  16. Wolf says:

    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

    [email protected]:/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 [email protected] is [email protected] 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
    [email protected]:/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

  17. Cronco says:

    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? 🙂

  18. Manwe says:

    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 127.0.0.1 , 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: http://85.15.46.57/test.php

    thank you:)

  19. kelvalok says:

    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!!!!

  20. ElEsSaR says:

    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.

  21. Pat says:

    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

  22. ams says:

    Please run the following to enable php 4/5

    sudo a2enmod php5 or sudo a2enmod php4

    depending on which one you want enabled.

  23. martin says:

    command ‘a2enmod php5’ amazingly solved my headache.thanx for the tips Ams!

  24. liam` says:

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

    what does this mean?

  25. joinkzz says:

    http://yourserverip/apache2-default/

    i do not understand this…

    how would i know my “yourserverip?”

  26. admin says:

    use ifconfig from commnd line to check your machine ip address

  27. joinkzz says:

    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 10.100.100.39 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

    http://10.100.100.39/test.php

  28. joinkzz says:

    this is my netstat result

    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3243/apache2

  29. joinkzz says:

    any help out there?

  30. admin says:

    what help do you need your test page is working now

Leave a Reply

  • Recent comments