Apache2 installation and configuration with php support

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 servers are 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.

Apache2 installation in debian

#apt-get install apache2

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 where ever 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.

Installing php and cgi support for apache2

If you want to add support of php and cgi scripts install the following packages libapache2-mod-php4,php4-cli,php4-common,php4-cgi

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

This will complete the installation of php support for apache2

If you want to allow the different index files types check for the following line in /etc/apache2/apache2.conf file DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.shtml

Restart the apache server

#/etc/init.d/apache2 restart

Testing your apache Server

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

“If you can see this, it means that the installation of the Apache web server software on this system was successful. You may now add content to this directory and replace this page.
Recomended module

apache2-mpm-worker

The worker MPM provides a threaded implementation for Apache2. It is considerably faster than the traditional model,and is the recommended MPM.You can install this using the following command.

#apt-get install apache2-mpm-prefork
Other files and folder located under /etc/apache2

conf.d/

Files in this directory are included by this line in apache2.conf:# Include generic snippets of statements Include

/etc/apache2/conf.d

This is a good place to add additional configuration directives.

httpd.conf Empty file.

magic

Magic data for mod_mime_magic Apache module, documented in htdocs/manual/mod/mod_mime_magic.html. You probably don’t need to touch this.

mods-available/

This directory contains a series of .load and .conf files.The .load files contain the Apache configuration directive necessary to load the module in question. The respective .conf files contain configuration directives necessary to utilize the module in question.

mods-enabled/

To actually enable a module for Apache2, it is necessary to create a symlink in this directory to the .load (and .conf, if it exists) files associated with the module in mods-available/.For example:cgi.load -> /etc/apache2/mods-available/cgi.load ports.conf Configuration directives for which ports and IP addresses to listen to.

sites-available/

Like mods-available/, except it contains configuration directives for different virtual hosts that might be used with apache2. Note that the hostname doesn’t have to correspond exactly with the filename. ‘default’ is the default host.

sites-enabled/

Similar in functionality to mods-enabled/, sites-enabled contains symlinks to sites in sites-available/ that the admnistrator wishes to enable.

Example:test -> /etc/apache2/sites-available/test

Enable and Disable modules and sites in apache2

a2enmod and a2dismod are available for enabling and disabling modules utilizing the above configuration system.

a2ensite and a2dissite have been added, which do essentially the same thing as the above tools, but for sites rather than modules.

Sponsored Link

10 thoughts on “Apache2 installation and configuration with php support

  1. Excellent website. I just got lucky to find an oncampus job that deals with debian. This website gives me all the transition knowledge needed for a guy who has had a Redhat background. Thank you, sir.

  2. After installing Ubuntu LAMP, (downloaded) I go to a remote and log on – I get the Apache screen and I get the message that The Apache documentation has been included with this distribution and all I have to do is click the Documentation link I supposed, but this does not work and I end up with a page not found.

    What did I miss ????

  3. I am new to Apache2 and do not use unix or lenix. How can I translate your information to Windows XP Pro? I have installed Apache2 successfully and it is running all services but I cannot make any sense of this document root stuff. I want to install cake but just placing the cake folder under htdocs doesn’t work. How do I transalate /var/www into a windows directory? The cake docs tell me to place the cake folder in the documentroot directory. But where is that on a windows system?

  4. @Jerry Ross: Well, the document root folder should be the “htdocs” folder under your Apache2 directory. For example: C:/Program Files/Apache Software Foundation/ Apache2.2/htdocs

    Cheers!

  5. I realize this post was made quite a while ago, but to update it, all instances of “php4” should be replaced with “php5”.

  6. Hey, Devin, thanks a lot!
    I was just about to give up on the php installation. I replaced, the 4 with 5 and apt is getting it now.

  7. The worker MPM provides a threaded implementation for Apache2. It is considerably faster than the traditional model,and is the recommended MPM.You can install this using the following command.

    #apt-get install apache2-mpm-prefork

    !!
    you mean
    #apt-get install apache2-mpm-worker

Leave a comment

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