Apache2 web server with php support in ubuntu

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

sudo apt-get install libapache2-mod-php4 php4-cli php4-common php4-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

[thumb:475:c:l=p]

Test apache with PHP
To test if php4 installed correctly

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

[thumb:476:c:l=p]

Sponsored Link

15 thoughts on “Apache2 web server with php support in ubuntu

  1. you need to install ftp server or if you have files on ftp server you need to install ftp client on your apache server

  2. i want to convert my pc into webserver i had installed apache2 with php support. i can access my site by typing 127.0.0.1 ip address in my url. But now how can i make static ip address for my server or give domain name to my server so that world can access my web site???

  3. @Vrjesh

    You have to assign the public ip address for your server and you can also enter the hostname.If you want to view your webserver over the internet you can view through ip or domain name.If you want to domain name you need to register this in DNS

  4. Dears
    Right now I installed Ubuntu on my server completely with every needed services but I need such a toturial which have a step by step guide for using web services in Ubuntu. for example when I want to know how can I define a new DNS, I can follow those steps and do my task. and also for other services.
    for example in such version of Linux it is possible to use Plesk for managing every task in the operation system environment so easy but I can not use it now. there is no problem to do everything manually but if I can have a good manual.
    thanks for your attention. I am waiting for your help.
    Neisan

  5. Hi , I need to run php files from the command line with the default configuration which we have after installing the LAMP server. Can anyone help me in this? I tried installing PHP4 by using apt-get, but was not able to configure properly, resulting in a total screup of the system. Can anyone help me??

  6. @Jalpesh

    if you follow the procedure menctioned above it will work without any problem if you want to run php script from command line you need to make sure you have installed php4-cli and run the script with “php scriptname”

  7. Hi. The way I gave my server a domain name is I use DynDNS. This service allows you to use a subdomain for free or you can purchase or transfer a domain that will keep up with your ip address. Using DHCP your PC’s ip address changes. This service will point the chosen domain name to your server even when it changes. All for free.

  8. What Ellann says is a crucial point for most people who want to set up a home pc as a web server and the posters on this thread seem to be. Nearly all broadband access or dial up for that matter is allocated an address on the internet on a temporary basis. All web servers have and need a static IP address allocated. The only way around this is a service like DynDNS as mentioned above. It checks back with the service every so often and keeps your allocated IP ‘in sync’ with the IP associated with your Web site address. It is a little trick to set up but the alternative is a rented server/space or a leased IP address, both of which are a lot more expensive.

  9. hey i installed apache server but unable to run the cgi programs there,can u pls tell the procedure 2 run cgi prog??

    Thanks in advance

  10. Can “apache2” be named as “httpd”. Don’t who thought is a bright idea to change it!!!!

  11. I have installed LAMP in ma ubuntu 9.10. How do I check the webpages which I have designed in php??????? Please help me.

    Thanks in advance.

Leave a comment

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