Running PHP 5 as a CGI Binary
If you have configured PHP 5 to run as an Apache module, skip forward to the next section. This section is for those who want to configure PHP to run as a CGI binary.
The procedure is the same whether you are using the Apache 1.x series or one of the 2.x series.
Search for the portion of your Apache configuration file which has the ScriptAlias section. Add the line from the box below immediately after the ScriptAlias line for "cgi-bin". If you use Apache 2.2.x, make sure that the line goes before the closing for that
section.
Note that if you installed PHP elsewhere, such as "c:\Program Files\php\", you should substitute the appropriate path in place of "c:/php/" (for example, "c:/Program Files/php/"). Observe carefully that I used forward slashes ("/") instead of the usual Windows backslashes ("\") below. You will need to do the same.
ScriptAlias /php/ "c:/php/"
Apache needs to be configured for the PHP MIME type. Search for the "AddType" comment block explaining its use, and add the AddType line in the box below after it. For Apache 2.2.x, you can find the AddType lines in the section. Add the following line just before the closing for that section.
AddType application/x-httpd-php .php
As in the case of running PHP as an Apache module, you can add whatever extensions you want Apache to recognise as PHP scripts, such as:
AddType application/x-httpd-php .phtml
Next, you will need to tell the server to execute the PHP executable each time it encounters a PHP script. Add the following somewhere in the file, such as after the comment block explaining "Action". If you use Apache 2.2.x, you can simply add it immediately after your "AddType" statement above; there's no "Action" comment block in Apache 2.2.x.
Action application/x-httpd-php "/php/php-cgi.exe"
Note: the "/php/" portion will be recognised as a ScriptAlias, a sort of macro which will be expanded to "c:/php/" (or "c:/Program Files/php/" if you installed PHP there) by Apache. In other words, don't put "c:/php/php.exe" or "c:/Program Files/php/php.exe" in that directive, put "/php/php-cgi.exe".
If you are using Apache 2.2.x, look for the following section in the httpd.conf file:
AllowOverride None
Options None
Order allow,deny
Allow from all
Add the following lines immediately after the section you just found.
AllowOverride None
Options None
Order allow,deny
Allow from all
Configuring the Default Index Page
This section applies to all users, whether you are using PHP as a module or as a CGI binary.
If you create a file index.php, and want Apache to load it as the directory index page for your website, you will have to add another line to the "httpd.conf" file. To do this, look for the line in the file that begins with "DirectoryIndex" and add "index.php" to the list of files on that line. For example, if the line used to be:
DirectoryIndex index.html
change it to:
DirectoryIndex index.php index.html
The next time you access your web server with just a directory name, like "localhost" or "localhost/directory/", Apache will send whatever your index.php script outputs, or if index.php is not available, the contents of index.html.
Restart the Apache Web Server
Restart your Apache server. This is needed because Apache needs to read the new configuration directives for PHP that you have placed into the httpd.conf file. The Apache 2.2 server can be restarted by doubleclicking the Apache Service Monitor system tray icon, and when the window appears, clicking the "Restart" button.
Testing Your PHP Installation
Create a PHP file with the following line:
Save the file as "test.php" or any other name that you fancy, but with the ".php" extension, into your Apache htdocs directory. If you are using Notepad, remember to save as "test.php" with the quotes, or the software will add a ".txt" extension behind your back.
Open your browser and access the file by typing "localhost/test.php" (without the quotes) into your browser's address bar. Do not open the file directly on the hard disk — you'll only see the words you typed in earlier. You need to use the above URL so that the browser will try to access your Apache web server, which in turn runs PHP to interpret your script.
If all goes well, you should see a pageful of information about your PHP setup. Congratulations — you have successfully installed PHP and configured Apache to work with it. You can upload this same file, test.php, to your web host and run it there to see how your web host has set up his PHP, so that you can mimic it on your own machine.
If for some reason it does not work, check to see whether your PHP setup or your Apache setup is causing the problem. To do this, open a Command Prompt window (found in the "Accessories" folder of your "Start" menu) and run php-cgi.exe on test.php with a command line like "c:\php\php-cgi test.php" (without the quotes).
If invoking PHP from the command line causes a large HTML file with all the PHP configuration information to be displayed, then your PHP set up is fine. The problem probably lies with your Apache configuration. Make sure that you have restarted the Apache server after making configuration changes. Verify that you have configured Apache correctly by looking over, again, the instructions on this page and the steps given in How to Install and Configure Apache 1.x for Windows (for Apache 1.x users) or How to Install and Configure Apache 2 on Windows (for Apache 2.x users).
Kaynak: http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml
Hiç yorum yok:
Yorum Gönder