logo
Apache Lounge
Webmasters

 


About

Forum Index Downloads Search Register Log in  RSS Apache Lounge
 



Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored by anyone.

Your donations will help to keep this site alive and well, and continuing the building of the binaries.



A Fast, Reliable and Proven Setup :: Apache PHP MySQL Perl

 
Post new topic   Reply to topic    Apache Forum Index -> How-to's & Documentation & Tips



View previous topic :: View next topic  
Author Message
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6143
Location: Germany, Next to Hamburg

PostPosted: Sat 12 Apr '08 17:13    Post subject: A Fast, Reliable and Proven Setup :: Apache PHP MySQL Perl Reply with quote

One of the biggest topics here at Apache Lounge is running PHP on Apache.
It is a topic that is constant and for some reason often confused.
Confused namely by varying ways to accomplish the same thing.
The following has been tested numerous times, and seems (at least so far) to be easy to follow.Mr. Green

IF YOU PREVIOUSLY INSTALLED APACHE USING A MSI FILE THEN (otherwise skip down to CONTINUE section):
I have not tested Apache Software Foundation (ASF) MSI installation applications lately,
but the last time I tested the MSI FAILED to remove to some things that can cause problems later on during
the Un-Install process. BEFORE you UN-INSTALL the MSI file, open a command prompt run as administrator and navigate to
the BIN folder of Apache. Now, uninstall the service:
Code:

httpd -k uninstall

Now that the service is removed, uninstall Apache and then ALL PHP entries
(files [php5ts.dll and others depending on what each person has done in the past] that you copied
from where ever to where ever - usually into the Windows\System32 folder).

ArrowCONTINUE:

Install the Microsoft VC++ Redistributable

For 2.4.x VC11/14 , download Win 32 bit (x86) or Win 64 bit (x64) 2.4 from http://www.apachelounge.com/download/


Apache Setup
Download httpd-2.4.x-winYY-VCxx.zip from http://www.apachelounge.com/download/

Note: you can substitue drive letters to what will work best for you or your situation. I advise however, that you DO NOT place PHP in the Apache root though.

Unzip this ZIP file in a new folder called something like C:\Apache24. Then, read the file named Read Me First !!.txt. It will tell you how to setup the service for Apache.
If you want or need ApacheMonitor you can create shortcuts however you like. Before installing ANYTHING else, ensure Apache will start.
Open a command prompt and navigate to the BIN folder of Apache:

    1. At the prompt enter httpd
    2. If there's nothing seriously wrong, Apache will start: the cursor will drop down one line and blink (you should be able to use your browser and navigate to http://localhost and see "It Work!".
    3. With focus on the Command Prompt window - Hold down CTRL hit the C key then release both - within a couple of seconds the prompt will be released (Apach will Stop).


After you validate that Apache starts, stop it before proceding.

PHP Setup

Note: you can substitue drive letters and folder names to what will work best for you or your situation. I advise however, that you DO NOT place PHP in the Apache root though.
If you are still with me, now download PHP 5.x/6.x/7.x from http://windows.php.net/download/ you want this file: php-5/6/7.x.xx-Win32-VC11/14-x86/64.zip (where x relates to the latest stable version number)

Yes there is a way to install PHP as module, but it has been proved best to install PHP over mod_fcgid (fastcgi, best practice)

Please download the VC11/14 x86/x64 Non Thread Safe OR VC11/VC14 x86/x64 Thread Safe if you need to run PHP as module.

Extract the contents of this file and move the contents to where you intend to use PHP such as C:\PHP5.

Navigate to the PHP folder and edit the php.ini-production. FIND the extension_dir directive and change so that it properly locates the EXT folder. Enter a full path.

extension_dir = "C:\php5\ext"

If you want to use the mysql extension you have to enable it un commenting it (removing ";") in that line of php.ini. A good start is ot enbale mysql and mysqli

Code:

extension=php_mysql.dll
extension=php_mysqli.dll


Save the file as php.ini.

Ensure you can run PHP from the Windows Command Line (
Code:
php -m
should work and produce a list of modules loaded).

Finally, this should be the last step, edit the Apache CONF file (httpd.conf) with
make sure you load mod fcgid. ( mod_fcgid is an additional download)
Code:

LoadModule fcgid_module modules/mod_fcgid.so

<IfModule fcgid_module>


   FcgidMaxProcesses 300
   FcgidMaxProcessesPerClass 300

   FcgidOutputBufferSize 65536
   FcgidConnectTimeout 10
   FcgidProcessLifeTime 0
   FcgidMaxRequestsPerProcess 0
   FcgidMinProcessesPerClass 0
   FcgidFixPathinfo 0
   FcgidProcessLifeTime 0
   FcgidZombieScanInterval 20
   FcgidMaxRequestLen 536870912
   FcgidIOTimeout 120
   FcgidTimeScore 3

   FcgidPassHeader Authorization

   FcgidInitialEnv PHPRC "C:\\php5"
   FcgidInitialEnv PATH "C:\\php5;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;"
   FcgidInitialEnv SystemRoot "C:\\Windows"
   FcgidInitialEnv SystemDrive "C:"
   FcgidInitialEnv TEMP "C:\\WINDOWS\\TEMP"
   FcgidInitialEnv TMP "C:\\WINDOWS\\TEMP"
   FcgidInitialEnv windir "C:\\WINDOWS"
   <Files ~ "\.php$">
      Options Indexes FollowSymLinks ExecCGI
      AddHandler fcgid-script .php
      FcgidWrapper "C:/php5/php-cgi.exe" .php
   </Files>
</IfModule>

Save the httpd.conf file. Start Apache.

set in your php.ini
Code:


cgi.fix_pathinfo = 1


To ensure that the PATH addition is set, PLEASE reboot your PC!!! (this applies only to 2000,XP,2003,Vista.)

Now test apaches config file and see if everything loads. Open the command line again, and enter
Code:

httpd -S


If you have an issue like

Quote:

mod_fcgid: HTTP request length 131400 (so far) exceeds MaxRequestLen (131072)


You need to adjust FcgidMaxRequestLen bytes

The default value 131072 (bytes) which is 128 kB to inscrease this for example to 15MB (15728640 (bytes)).

e.g.
Code:

FcgidMaxRequestLen 15728640


For running mod_php and fcgid combined and or multiple php versions see https://www.apachelounge.com/viewtopic.php?t=3430

Configuration, see http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html


FOR PHP as module

For Apache 2.4 use:

    LoadModule php5_module "c:/php5/php5apache2_4.dll"
    AddHandler application/x-httpd-php .php
    # configure the path to php.ini
    PHPIniDir "c:/php5"


Save the httpd.conf file. Start Apache.

***Since some have asked where to place this in the httpd.conf - Here's what I do:
***
*** LoadModule directive goes at the end of the long list of LoadModule directives
*** I add a blank line after the LoadModule directive then add the AddHandler directive
*** I place the PHPIniDir directive right after the AddHandler directive
***



END PHP Setup


If you receive no errors, and you want to run Apache as a Service then open a command prompt run as administrator and navigate to the BIN folder of Apache. Now, install the service:
Code:
httpd -k install

That command will add Apache2 to the Services MSC.

If do not want Apache starting automatically at start-up/reboot:

    1. START | RUN
    2. Type in services.msc, hit Enter or click OK
    3. Locate Apache2 service and double-click (or right-click for Properties)
    4. Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
    5. Click OK



If you have troubles with your PHP script take a look at Basic PHP Troubleshooting

MySQL Setup


    1. Download from mysql.com community downloadpage --> Windows downloads -- Without installer (unzip in C:\) --> No thanks, just take me to the downloads!
    2.Unzip the mysql-noinstall-5.x.xx-win32.zip to e.g. C:\ rename it to mysql
    3. Uninstall any previous MySQL Windows service
    Code:

    mysqld.exe --remove

    4. Copy one of the MySQL\*.ini files (usually my-large.ini) to MySQL\my.ini
    5. Edit my.ini and change any parameters for your site.
    6. You can install mysqld.exe as a Windows service with
    (see also : http://dev.mysql.com/doc/refman/5.6/en/windows-start-service.html )


Code:

mysqld.exe --install


After you install the service be sure to:

Secure the initial MySQL accounts MySQL access controls. Be aware that default both root and the anonymous account are set up with no password, so anyone can connect to the MySQL server as root.


Optional:

    7. Download phpmyadmin which is a good interface over your browser to mysql.

    Only you can access the htdocs folder from the server or ftp
    8a. unzip it to C:\Apache2\htdocs\ and rename it to phpmyadmin

    9a. install phpmyadmin with the installer script in http://yourdomain.tld/phpmyadmin/scripts/setup.php

    10a. Delete the scripts folder in phpmyadmin. Create a .htaccess with

    Code:

    <RequireAll>
       Require ip 192.168 127.0.0.1
    </RequireAll>


    so no one can access that, but from your network and the server itself.



Other users can access htdocs folder via ftp.


On Windows 10 there is sometimes an error that port 80 is blocked, it might be W3SVC service. Set it to "manual" starting.

Code:
french name is: "Service de publication World Wide Web"
english name is: "World Wide Web Publishing Services"
german name is: "WWW-Publishingdienst"
Polish name is: "Usluga publikowania w sieci WWW"
Russian name is "Служба веб-публикаций"


Enjoy,

James Blond

Admin note:
If you still have issues or find something confusing, please post in one of the other forums


Last edited by James Blond on Mon 19 Sep '16 14:58; edited 25 times in total
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6143
Location: Germany, Next to Hamburg

PostPosted: Wed 10 Jul '13 14:44    Post subject: Reply with quote

I've updated the tutorial by some suggestions. Also thanks to Steffen and user TAB.

If you find any issues please report in the normal forum (not in How-to's & Documentation & Tips NOR this topic)
Back to top
XenonKilla



Joined: 06 Apr 2012
Posts: 8

PostPosted: Fri 29 Jan '16 3:39    Post subject: Reply with quote

Hey James,

Just a heads up, you've got "FcgidIOTimeout" in there twice as shown in the screenshot below.


Back to top
XenonKilla



Joined: 06 Apr 2012
Posts: 8

PostPosted: Fri 29 Jan '16 4:08    Post subject: Reply with quote

You've also got the FcgidOutputBufferSize 64 and I'm assuming you want 64KB however simply putting "64" would only give you 64 bytes not kilobytes. The correct value would be FcgidOutputBufferSize 65536 for 64KB which is also the default value.

You've also got ProcessLifeTime 0 which should be FcgidProcessLifeTime 0

Ok that's all the critiquing I have for you. Laughing

Thanks for this guide!
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 6143
Location: Germany, Next to Hamburg

PostPosted: Thu 04 Feb '16 17:36    Post subject: Reply with quote

Thanks a lot. I have changed that.

Well once upon a time there wasn't the prefix Fcgid for all directives... I wonder that so many ppl read it and never noticed it.
Back to top


Post new topic   Reply to topic    Apache Forum Index -> How-to's & Documentation & Tips
Page 1 of 1