Join David Gassner for an in-depth discussion in this video Installing PHP with Apache on Windows, part of Installing Apache, MySQL, and PHP.
- The most recent version of PHP as of the time of this recording is PHP 5.6. You can get the Windows binaries for PHP from this web page at windows.php.net/download. There are multiple packages available for each PHP version. You'll find PHP 5.6 at the top, and then PHP 5.5, 5.4, and so on.
I'll only be dealing with the most recent version here. There are versions for 32-bit and 64-bit Windows, and there are both Non Thread Safe and Thread Safe versions. Even though I'm working on 64-bit Windows, I'm going to be using the 32-bit version of PHP. It matches the 32-bit version of Apache that I already installed, and most importantly the 64-bit builds are marked as experimental. By using the 32-bit versions, you'll be using a version that's stable.
Download the Thread Safe version. That's the version that's compatible with Apache. I'm using this file, VC11 x86 Thread Safe. It downloads as a zip archive file. Just as with Apache, you can install it by simply extracting it to your hard disk. I've already downloaded it to my hard disk. This zip archive does not contain a top-level folder. Its files are just children of the archive itself.
So when you extract it, you'll need to create a folder to contain the files. The safest way is to right-click on the zip file, and then choose Extract All, and type the name of the folder that you want to extract to. I'm creating a folder called c:\php, and I'll click extract. There aren't that many files so it should just take a few moments to complete the installation.
After the files have been extracted, Windows Explorer or File Explorer should open to show you the new folder. If it doesn't, open it yourself, and scroll down toward the bottom. You'll find this file, php5apache2_4.dll. This is a DLL that's used to connect to Apache at run time. You'll need to know the name of that file and its location to connect Apache and PHP to each other.
To make it work all together, you'll need to add some information to your Apache configuration file. Go to your Apache installation folder. I installed Apache to c:\apache. Then go to the conf folder. That's where your configuration files are. Then open the file httpd.conf in any text editor. Then scroll down all the way to the bottom.
I'll be adding three new directives to this file. It takes a bit of typing so to make this a little bit easier, I've included a file in the exercise files. I'll go to the exercise files folder then to the Apache subfolder, and I'll open this file. Then I'll select and copy all three lines, and then I'll go back to my httpd configuration file, and I'll paste those lines into place at the bottom of the file.
There are three directives. The LoadModule directive loads that DLL I described. Notice that the name and location of the DLL are included. If you installed Apache somewhere else on your hard disk, change this line to match your installation folder. The AddHandler directive says that when a file with the .php file extension is requested, this is its mime type. This is how we report to the browser what's being processed on the server.
Finally, PHPIniDir is a directive that says where the php.ini configuration file is stored. This is very important. It's how you configure PHP, and Apache needs to know where it is. Once again, I've included the name of the folder. I'm going to conform those two lines so they both use C in uppercase, but they'll work either way. Notice, I don't have a trailing slash, and I've also used a forward slash instead of a backslash in this directive.
Now that file, php.ini, isn't created for you automatically in PHP 5.6. You have to create it yourself. But rather than typing it from scratch, we're going to use an existing version. I'll go to my c:\php folder, and I'll scroll down a bit. I'll see that there are two INI files here. One is called php.ini-development, and the other is called php.ini-production.
I'm going to use the development version. It has settings that are appropriate for development on a local computer. I'll copy and paste the file with Control-C and Control-V. Then I'll go to the new version and I'll name it php.ini. This is the required name of the PHP configuration file. On most Windows computers when you do this, the .ini extension will be hidden by default, but it's there.
If you click on the file and then press Alt-Enter to look at the file properties, you'll see that the file type is configuration settings with an extension of .ini. Now I'm finally ready to test. I'll need a simple PHP script, and I've provided it in the free exercise files that accompany the course. It's in the PHP subfolder, and it's named phpinfo.php. Once again, I'll look at the properties and verify the PHP file extension.
Then I'll open the file in a text editor. It has a simple PHP command, phpinfo. This command outputs information about the current PHP installation. I'll close the text editor. Then I'll copy the file to the clipboard. Then I'll go back to my Apache folder. From there I'll go to htdocs.
This is my document root folder when working with the individual Windows installation. I'll paste that phpinfo.php file into place. All my configurations are done, and I've placed a PHP script that I can use to test. Now I need to make sure that Apache is running. If you're running from a command prompt like I am, go there now. If you're already running Apache, press Control-C to stop it.
Then type httpd to start it up again. If you're running Apache as a Windows service, go to the Control Panel and restart if from there. Then go to a browser and navigate to the URL localhost/phpinfo.php, and you should see this output. There's a lot of information here, but most importantly take a look at your loaded configuration file and verify that it displays as c:\php\php.ini.
You'll also see a setting called Configuration File Path, but you could ignore that. If you see this under Loaded Configuration File, then you know that that's the initialization file that you're using for your copy of PHP. If that's all working, you're ready to go to the next step, installing MySQL.
- Installing Apache, PHP, and MySQL separately
- Activating Apache and PHP on Mac OS X
- Installing and configuring phpMyAdmin
- Installing WampServer
- Installing MAMP
- Configuring MAMP's Apache and MySQL server ports
- Installing XAMPP for Windows and Mac OS X
- Managing MySQL security through XAMPP
- Installing Bitnami for Windows and Mac
- Detecting and handling port conflicts
- Working with Apache and IPv6 in Windows 8