This is an Update for Article: http://www.flash-db.com/ApachePHPSQL/
Note: This can get a little tricky with all the new versions - In some case's you might want to think about just using Apache 1.3.x as things are a bit easier. Feel free to post comments and questions below - as their's bound to be many on this process.Apache 2.0.39 Web Server
"Apache has been the most popular web server on the Internet since April of 1996. The May 2002 Netcraft Web Server Survey found that 56% of the web sites on the Internet are using Apache, thus making it more widely used than all other web servers combined" - Apache HTTP Server Project. Version 2 has many new improvements for the Windows Environment which make it run more effectively than in previous versions. 2.0.39 is the latest release after a security hole was found in the 2.0.36 Apache release. PHP 4.2.2:
PHP is a server side scripting language that allow you to interact with the server and write text files, insert info into a database, send email etc. PHP is extremely powerful and content rich. For Apache 2.0.39 to work with PHP I have installed the 4.2.2 Stable version as 4.2.1 does not work (only with 2.0.36 and previous versions) How do I install Apache 2?
The Windows Installer version (MSI) can be downloaded from the following list: http://www.apache.org/dist/httpd/binaries/win32
The latest Version is apache_2.0.39-win32-x86-no_ssl.msi
- Download this file to your desktop then double click on it.
- This will start to run through some setup options. When you get to a screen that asks for some Server Information. Use "localhost" for the Network Domain and Server Name (you can change this later). Then enter your email address in the Administrator's Email field.
- Select the 'Typical' installation option on the next screen.
- On the next screen select the default Destination Folder - this will be 'C:\Program Files\Apache Group\' you can choose a different folder if needed but we will be working with this one.
- After this the setup should be complete - Hit the install button and you'll get a success message when it's complete. Click finish.
- A couple of options should have been added to your start menu. Find the Apache option on the Start menu and then the 'Control Apache' Submenu. Press the Start option from that submenu. The apache services monitor should also have been added. With this you can easily start, stop, and restart the Apache Web server. You'll see what looks like a feather with either a green or red stop sign on your task bar. Green means the server is running, red means that it's stopped.
Then open up a web browser and type in the address: http://localhost/
You should see a default Apache page appear in your web browser. It easiest if you create a shortcut to this URL on your desktop for future use. (In the off chance that you have a different web server running such as PWS or IIS running on your computer - make sure to stop that service before starting apache). Since two web servers can not run on the same port (80) at the same time.
Since we want to display our own page instead of the default page - find your way to the htdocs folder located at: C:\Program Files\Apache Group\Apache2\htdocs folder. You can just delete all of the default index.html.lang files and all the other files in this directory and replace this with your own index.html page you want to display as the default. The htdocs folder is your main web directory - you can use this just as if you where uploading files to a server somewhere else. It sometimes makes things easier if you place a shortcut to this folder on your desktop as well.
The next step is to become familiar with the httpd.conf file (Located: C:\Program Files\Apache Group\Apache2
onf\httpd.conf). This contains a set of directives and configuration settings for your server. For the most part you will not have to change this much when just using apache for testing/development. It is however a good idea to become familiar with this file and look it over. So open it up with Notepad or your favorite text editor and have a look.
Changing the default directory page:
Normally the default directory page is index.html. As an intro to using the httpd.conf file we will going to change the default page apache serves when a directory is requested to something else.
Open up the httpd.conf file (Located: C:\Program Files\Apache Group\Apache2
onf\httpd.conf) with Notepad - then do a search for index.html. (Any line that starts with the # symbol in the configuration file is a Comment). This should bring you to a line of code that looks like this:
DirectoryIndex index.html index.html.var
and change to: DirectoryIndex index.php index.html index.htm
Change the following line in httpd.conf which is a single line on its own:
Change AllowOverride None to AllowOverride All
(This allows us to use .htaccess files in any directory).
How do I Install PHP 4.2.2 and configure with Apache 2?
Download PHP 4.2.2 from the following List:http://snaps.php.net/win32/
It MUST be the ZIP package as opposed to the installer package. The Latest stable version is:http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
PHP documentation can be found at:http://www.php.net/manual/en/
Editing the PHP.ini file and the Apache httpd.conf file
- After you have downloaded the zip file. Unzip all of these files to the C:\ directory. This will create a directory structure like: C:\php-4.2.2-Win32. Rename this folder to C:\PHP
- Copy the file C:\PHP\php.ini-recommended to your windows folder: c:\winnt or c:\windows.
- Rename this file (php.ini-recommended) to php.ini once you have placed it within the windows folder. You can rename the file with Notepad.
- Copy the file C:\PHP\php4ts.dll and all the files in c:\PHP\dlls\ folder to your windows system folder: c:\winnt\system32 or c:\windows\system, for XP and ME it's the windows\system folder. Getting this step right is one of the most important - and Confusing.
Open up the httpd.conf file that we where working with when we first installed Apache with Notepad. Look for a block of LoadModule commands (this is located near the beginning of this file). Then insert the following line right after all the the other LoadModule commands: LoadModule php4_module c:/PHP/sapi/php4apache2.dll
Make sure to use forward slashes for this path instead of Back Slashes.
Please note that you must use the php4apache2.dll and NOT the php4apache.dll. With earlier versions of PHP (before 4.2.0 and Apache 2.0 you do however use the php4apache.dll). This is an important change to keep in mind when using earlier versions of Apache with PHP.
We have to add one last item to the httpd.conf file before we are finished.
Add the following Line to your httpd.conf file (somewhere after the LoadModule command we just added and after the line AddType application/x-tar .tgz); AddType application/x-httpd-php .php .php3 .phtml .php4
Next Edit the PHP.ini File.
First add the 'doc_root' path (Search the file for doc_root to find it faster). Add the path to the htdocs folder. This path will be something like: C:\Program Files\Apache Group\Apache2\htdocs so that the line now looks like:
doc_root = C:\Program Files\Apache Group\Apache2\htdocs
Change Register Globals to Register Globals=On
You can keep register Globals to off (which is now recommened - but it may cause some errors with scripts written before this was an option).
Update the path to the extensions: extension_dir = c:\PHP\extensions
Set the temp directory for sessions - Ensure the directory exists!: session.save_path = c:/temp
That should be it. At least it should be enough so that PHP will be running in conjunction with the Apache web server. To test this try the following.
Create a file named PHPInfo.php. Include the following in that file:
Then add this file to your htdocs folder. Make sure Apache is started, open up a browser and type in the following URL http://localhost/PHPInfo.php
If everything went successfully you'll see a long list of all your PHP settings and server information. When starting Apache you should also see a small note that the PHP 4.2.2 module has loaded, also when your viewing the 'Apache Service Monitor' you should see a small note at the bottom indicating that PHP 4.2.2 is running. Sending Email with PHP from your local computer
This will work depending on if your ISP does not specifically restrict it. Open up the PHP.ini (c:\windows\PHP.ini) file and find the following lines that look like this:
; For Win32 only.
SMTP = localhost
; For Win32 only.
sendmail_from = email@example.com
Change this to:
; For Win32 only.
SMTP = mail.yourISP.com
; For Win32 only.
sendmail_from = YourName@YourSite.com
The SMTP setting 'mail.yourISP.com' should be the same outgoing SMTP setting you have specified in Outlook. As long as you can send and recieve email from Outlook and have the username and password set in Outlook, you'll be able to do the same with PHP. If you run your own mailserver you can use those details. NOTE - you need to restart the Apache server to register any changes to the httpd.conf or php.ini file.
If you have any questions - post them below.