eHow launches Android app: Get the best of eHow on the go.

How To

How to Configure an Apache Server for PHP

Contributor
By eHow Contributing Writer
(0 Ratings)
Configure an Apache Server for PHP
Configure an Apache Server for PHP
http://www.venezuela.net.ve/softwarelibre/images/apache1.gif

The ability to run server side scripts on a web page makes the browsing experience more interactive and enjoyable. Common packages for such scripts are CGI and PHP, which allow developers to perform tasks such as gathering user information and designing games, forums and blogs. However, to run scripts, the server must be configured to do so. In the case of executing PHP scripts on an Apache server, only a couple of lines need to be added to the configuration.

Difficulty: Moderately Easy
Instructions

Things You'll Need:

  • A text editor, i.e., Notepad, Emacs, ConText

    Configure Apache for PHP

  1. Step 1
     

    Open the "conf" directory. Go to the "Apache" directory, and you should see a sub directory called "conf." Open the "conf" sub directory.

  2. Step 2
     

    Open "httpd.conf." Once you have entered the "conf" directory, you will see a file called "httpd.conf." This is the file where you will have to add code to configure PHP. Open this file in a text editor, preferably one that will conserve the file extension.

  3. Step 3
     

    Configure for PHP. Find the section of the file where the PHP information is listed and add the following lines of code (for PHP5):
    c:/php/php5apache2.dll
    AddType application/x-httpd-php .php

  4. Step 4
     

    Specify path to PHP and save. Now you have to tell the server where PHP is located on the box. To specify the path to PHP, add the following code:
    PHPIniDir "C:/Windows"
    Save the httpd.conf file to the same location. Make sure that your PHPIniDir is under C:/Windows. This is the standard path configuration, but it is always wise to check because your programs will not run otherwise.

  5. Step 5

    Test the installation. You can do this by running a basic PHP script on the server. To do this, copy the following code in an empty text document and save as "test.php."
    <html>
    <head>
    <title>Test Apache Configuration</title>
    </head>
    <body>
    <?php echo '<p>PHP is now installed</p>'; ?>
    </body>
    </html>
    Load the file to your html directory as you would any other web page. After loading, open the page by typing in the address, e.g., "www.your_domain.com/your_root/test.php." If Apache has been properly configured, you should get a printout that reads "PHP is now installed." If it has not been installed, your browser will attempt to download the "test.php" file.

Tips & Warnings
  • My favorite text editor is ConText because it is free and is designed for programming. It takes some time to get the feel, but I can't program on anything else. Emacs also is very good but somewhat complex to learn. If you are using a MacOS, the config file is usually under the /etc/ directory.
  • Make sure to fill in with the correct versions of your server. For example, you will need to do this if you are using a different version of Apache. This is a standard path setup. It may be different on your machine.
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2010 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy .   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. † requires javascript

eHow Computers
eHow_eHow Technology and Electronics