In this article, I will show you how to install Apache 2.4, PHP 5.5 and MySQL. I’m running a standard Windows 8.1 64-bit setup without Xampp or Wamp. I will be showing you how to add PHP 5.5 as a module in Apache 2.4.
Step 1: Downloads
Apache: Download Apache 2.4 binaries from ApacheLounge.com. You should download the thread safe version as it contains a file required to run PHP as an Apache module. In my case, I needed httpd-2.4.10-win64-VC11.zip, you should download the version relevant to your operating system architecture.
PHP: Download PHP 5.5 binaries from the official PHP website, also VC11 (php-5.5.15-Win32-VC11-x64). It’s important to use both VC11 packages.
Visual C++ Redistributable: Download Visual C++ Redistributable for Visual Studio 2012 from Microsoft’s website available here.
Step 2: Installations
Apache: Unlike previous versions of Apache that included an installer, Apache 2.4 requires you to extract the compressed file to a directory on your computer. You should avoid folders like %Programfiles% to avoid permission issues. On my computer, I have all server related components on a different drive from my operating system’s but you should be fine extracting to “C:\Apache24”
- Open up a command prompt window
- Type “cd ../../apache24/bin” (without the quotes) -> Enter key.
- Type httpd.exe
Navigate your browser to http://127.0.0.1 or http://localhost.
You should see a message saying “It works!” if everything was setup correctly. On the command prompt window, hit CTRL + C to abort (stop the Apache server). Later, we will setup Apache as a Windows service. For now, let’s move on to install and configure the other components.
Update Windows: Install the file you downloaded from Microsoft earlier. Note that the installer should be relevant to your architecture, 32-bit or 64-bit. After this is installed, proceed to install PHP.
Install PHP: Similar to Apache, you have to extract PHP to a directory on your computer, say “C:\PHP”. From the PHP directory, make a copy of php.ini-development and rename that copy to “php.ini”.
Although not relevant to getting these components working, you may want to enable the short open tags in the “php.ini” configuration script depending on your requirements:
Search for the line that reads:
short_open_tag = Off
This directive tells PHP whether the short open tag (<?) of PHP should be allowed. When disabled, you must use the long form of the PHP open tag (<?php).
Considering that many third party PHP scripts use the short form (<?), It’s advisable to enable this. You can enable it by replacing “off” with “on”.
short_open_tag = On
The configuration file for Apache 2.4 is http.conf. If you extracted Apache to C:\, the configuration file would be at C:\Apache24\conf\http.conf – You may need to update some variables in this file as follows.
Update Port Variable
In http.conf around line 37, the ServerRoot variable should be updated with the correct directory to the Apache installation. In our case, that would be “C:\Apache24”. You should use the forward slash “/” within this configuration script.
Around line 58 of the http.conf file, you should have “Listen 80”. This defines the port Apache should listen on. I have mine set to 8088 because I already have port 80 assigned to Ruby and some other applications. What this means is that you would have to point your browser to “127.0.0.1:8088” or “localhost:8088” to access your local server. Of course, you can leave this set to “80” if you want to use just “127.0.0.1” or “localhost”.
PHP as an Apache module
Here we configure Apache to load PHP as a module to enable the web server parse your PHP scripts. Open the Apache configuration file, “httpd.conf”. Search for the section of the file that has a series of “LoadModule” statements. Statements prefixed by the hash “#” symbol are regarded as inactive.
You want to add a LoadModule statement for php5apache2_4.dll within the PHP directory.
LoadModule php5_module "C:/php/php5apache2_4.dll"
Note carefully the use of the forward slash character (“/”) instead of the traditional Windows backslash (“\”). This is not a typographical error.
Next search the document for “addtype” and add the following after the last addtype statement:
AddType application/x-httpd-php .php
Configuring the default index file
In most server environments and with just about every host, when a directory is requested, the web server returns the index.php or index.html files. To mimic this behavior on our web server, we need to update the “httpd.conf” file. Look for this line in the file:
And replace it with:
DirectoryIndex index.php index.html
Following this change and a restart of the Apache server, subsequent requests to the web server will search the directory for an index.php file, if that’s unavailable it would move on to search for an index.html file.
It is important to note that following any change to the configuration script(s), the web server must be restarted for the said change to take effect.
Install Apache as a Windows Service
To install Apache as a Windows Service, open a command prompt window with administrative privileges, navigate to Apache’s bin directory (C:\Apache24\bin) and run:
httpd.exe -k install
You should get the message “The Apache2.4 service is successfully installed.”
Now, hit Win + R on your keyboard and enter “services.msc”. In the Services window you will see Apache2.4 listed, we can simply right click on this item and select “start”. By default, Apache 2.4 is set to startup automatically after the service is installed, so you should not need to re-do again. However, it won’t hurt to check if the Startup Type is set to ‘Automatic’. Right click on Apache 2.4 and select ‘Properties’ to access those settings.
Test your Installation
Now we test our installation with a php file.
Save this file as info.php into the “htdocs” directory. The htdocs directory is inside the Apache directory and is defined in the http.conf file. Navigate to the file using the browser. In my case, it was http://127.0.0.1:8088/info.php – If you didn’t set a custom port, it would be http://127.0.0.1/info.php
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.
Due to how long this article turned out to be, I had to split it up to two parts. The second part will show you how to link MySQL to your Apache/PHP installation. See you around 🙂