Make working together PHP 5.X with Apache web server on windows and Linux machines

Rating: 5.00 Votes: 1
Apr 13, 2015
1378 Views
0 Comment

PHP has become now one of the most preferable programming languages to create small, medium and enterprise level web applications and portals ranging business from real estate to social network and job portals to retail sales. This attracts many of startup developers to develop source code in PHP. Web applications are published through the web server and Apache is considered the best friend of delivering the PHP generated web pages. Both are open sourced and community driven and available under certain license conditions depending on your use.

Though both of them are of open source, Apache web server installation does not contain the configuration for the PHP as its native or inbuilt. Developer or the server admin has to put efforts to work both of them together. How? Let’s review a part of the Apache web server configuration file bit closely. Identify `httpd.conf` file within your Apache web server configuration. It is mainly resides in the `conf` folder. There is a list of ‘LoadModule….’ kind of statements with their relative path looking something like,

LoadModule        actions_module        modules/mod_actions.so

This is an instruction to Apache web server for loading the module named “actions_module” and the relevant file for this module is at the “modules” folder named mod_actions.so. When the Apache starts, it reads the httpd.conf files and follows the instructions written in the file and create a web server context by loading the listed modules and other directives written in the file.

So now we need to ask Apache web server to load the PHP as an Apache module too and keep it in the web server context. Very easy, instruct Apache to load module with the name of “php5_module” and show where Apache can find the relevant file. So write a LoadModule line bellows the block of other LoadModule instructions are written. Typically looks like,

LoadModule    php5_module      "D:/webdev/php5523/php5apache2_4.dll"

Also specify bellow that, where is the PHP ini Directory or where the php.ini (configuration file for php) can be found.

PHPIniDir        "D:/ webdev /php5523/"

Now it is time to instruct Apache that what extension files are to be considered as PHP source code file. Add the line bellow that is,

AddHandler       application/x-httpd-php         .php

Instead of .php extension you can specify your own one if you have an access of the web server configuration. So over all the block should look like:

LoadModule     php5_module        "D:/webdev/php5523/php5apache2_4.dll"

PHPIniDir        "D:/webdev/php5523/"

AddHandler     application/x-httpd-php      .php

Mind well, you have modified the httpd.conf file and brought new things into Apache’s context. To get this implemented working, you need to restart Apache web server.

This is the most common method for PHP and Apache working in combination. Another method is working PHP installed as CGI. This depends how your PHP installation should work.

Using Linux!!

When you install apache in any of the Linux installation, it brings the PHP provision in it. ( installing apache2 on linux).

Check for the line in the httpd.conf at /etc/httpd/

LoadModule       php5_module         modules/libphp5.so

If already there in the file, uncomment this line removing # from the starting of the line to load the PHP 5 module.

Now instruct Apache that what extension files are to be considered as PHP source code file. Add the block bellow in the httpd.conf file

<FilesMatch    \.php$>

    SetHandler   application/x-httpd-php

</FilesMatch>

Now restart the Apache web server with

Service   httpd     restart

Listed is a common and standard technique of configuring PHP with Apache web server. If anyone fined any trouble shooting, send me the scenario which is causing trouble I may try it to get the answers for your queries.

Leave Comment

The date and time of submission and your device`s IP address will be recorded when you click Save comment.
You can enter your social network profile link here
Answer simple math : 20 + 12 = ?

0 Comment