Setting up Apache with PHP, MySQL and (Mod_)Perl
Written by Mario
Thursday, 20 November 2008 10:14
Setting up Apache with PHP, MySQL and (Mod_)Perl
[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 and navigate to the BIN folder of Apache. Now, uninstall the service:
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).
Install the Microsoft VC++ RedistributableThe reason for this is because it is NOT included in the latest versions of Windows; and the builds are compiled using Microsoft Visual C++ 2008. See the Readme in the httpd-2.2.x-win32-x86-ssl.zip from http://www.apachehaus.com/index.php?option=com_content&view=article&id=49&Itemid=55
Apache SetupDownload httpd-2.2.x-win32-x86-ssl.zip from http://www.apachehaus.com/index.php?option=com_content&view=article&id=49&Itemid=55
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:\Apache2. 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:
- At the prompt enter [b]httpd[/b]
- If there's anything seriuosly wrong Apache will not start, if nothing major is wrong in your configuration 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!".
- 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 proceeding.
PHP SetupNote: 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 from PHP.net you want this file: php-5.x.yy-Win32.zip (where x relates to the latest stable version number)
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-recommended. FIND the extension_dir directive and change so that it properly locates the EXT folder:
extension_dir = "C:\php5\ext"
Save the file as php.ini
THIS MUST BE ACCOMPLISHED (see note below):
Add the folder that you put the PHP files into in the PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
- Variable name: Path
- Variable value: C:\php5;%SystemRoot%\system32;.....
Note: DO NOT WORRY with coping files over to the Windows folders, the reason for this to begin with is because Windows folder is already in the Path. Since you have added the PHP folder to the Path you do not need to copy or move files to the Windows folder. This will make upgrading PHP simpler as well and allows you to keep PHP all together. To upgrade PHP in the future, all you need to do is overwrite the contents of the PHP folder with the new files/folders extracted from the contents of the new PHP versioned zip.
Finally, this should be the last step, edit the Apache CONF file (httpd.conf) with:
LoadModule php5_module "c:/php5/php5apache2_2.dll"
AddHandler application/x-httpd-php .php
# configure the path to php.ini
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
!!!To ensure that the PATH addition is set, PLEASE reboot your PC!!!
Now Start Apache.
If you receive no errors, and you want to run Apache as a Service then open a command prompt and navigate to the BIN folder of Apache. Now, install the service:
httpd -k install
That command will add Apache2 to the Services MSC.
If do not want Apache starting automatically at start-up/reboot:
- START | RUN
- Type in services.msc, hit Enter or click OK
- Locate Apache2 service and double-click (or right-click for Properties)
- Find the caption Startup type: (in the middle of the dialog box), use the pull-down and select Manual
- Click OK
Basic PHP TroubleshootingWhen Apache IS NOT processing PHP script, you will usually get a dialog box asking to save the file or which application to use to open. This is usually caused by a missing or inappropriate handler (i.e. - php5apache2_2.dll).
Another problem is that people many times use OLD PHP script that uses 'short tags'. That is when the PHP declarative starts with . Since at least PHP 4, the default for opening PHP script has been . If you are using script with short tags, then you can do one of two things. Either change ALL of your opening tags to , or edit you PHP.INI file changing short_open_tag to ON.
The 'blank page' behavior is caused an error in your PHP script. The reason for the blank page is because display_errors directive is set to OFF by default. If you set display_errors to ON errors will be displayed in the browser. However, it is not considered safe to do so except on well tested code since certain things can be revealed that you might no want revealed. I suggest setting the ERRORS section of the PHP.INI to something similar to this:
log_errors = On
error_log = "C:/php5/error.log"
Everything else set to defaults. You will still get a blank page, but when you do you can open the error log to see what happened.
When the script is being displayed in the browser instead of actually processing the script, this is usually caused by the PHP file not having a PHP extension. Example:
PHP files should have .php as the extension. Such as phpfile.php
- Download from mysql.com community downloadpage --> Windows downloads -- Without installer (unzip in C:\) --> Â» No thanks, just take me to the downloads!
- Unzip the mysql-noinstall-5.x.xx-win32.zip to e.g. C:\ rename it to mysql
- Uninstall any previous MySQL Windows service
- mysqld-nt.exe --remove
- Copy one of the MySQL\*.ini files (usually my-large.ini) to MySQL\my.ini
- Edit my.ini and change any parameters for your site. You can install mysqld.exe as a Windows service with (see also : http://dev.mysql.com/doc/refman/5.0/en/windows-start-service.html )
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.
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
Deny from All
Allow from 192.168 127.0.0.1
so no one can access that, but from your network and the server itself.
Other users can access htdocs folder via ftp.
8b. unzip it to C:\Apache2\ and rename it to phpmyadmin
edit the httpd.conf add:
Alias /mydbdmanager/ "C:/Apache2/phpmyadmin/"
Options Indexes MultiViews
Deny from All
Allow from 192.168 127.0.0.1
9b. install phpmyadmin with the installer script in http://yourdomain.tld/mydbdmanager/scripts/setup.php
10b. Delete the scripts folder in phpmyadmin.
11. Now you should have access over http://http://yourdomain.tld/phpmyadmin/ or http://yourdomain.tld/mydbdmanager/
Mod_Perl Setup1. first of all, you must have a working Perl 5.8.x (http://www.activestate.com)
2.1 Uninstall mod_perl if you have already an installed mod_perl by typing in a Dos box: C:\>ppm uninstall mod_perl
2.2 ppm install http://theoryx5.uwinnipeg.ca/ppms/mod_perl.ppd
Generating HTML for mod_perl-2.0.3...done
Updating files in site area...done
Downloading mod_perl-2.0.3 install script...done
Running mod_perl-2.0.3 install script...
The Apache2 module mod_perl.so is needed to complete the installation,
and should be placed in your Apache2 modules directory. I will
now fetch and install this for you.
Fetching http://theoryx5.uwinnipeg.ca/ppms/x86/mod_perl.so ... done!
Where should mod_perl.so be placed? [D:/Apache2/modules] C:/PROGRA~1/APACHE~1/Apache2.2/modules
mod_perl.so has been successfully installed to C:/PROGRA~1/APACHE~1/Apache2.2/modules.
3. Add to your httpd.conf
LoadModule perl_module modules/mod_perl.so
Configuration see: http://perl.apache.org/docs/2.0/os/win32/config.html
4. restart apache
This is how I put together the WAMP(P), and I do it often (web application tester).
I hoped this helped.
If you still have a question please ask in our forum
Last Updated on Monday, 15 December 2008 00:00