In this tutorial I am going to show you how to install PHP 5.4.30, Apache 2.4.9, MySQL 5.6.19 and phpMyAdmin 4.2.2 on a Windows 7 machine. This is a standard set of software that is required for PHP development.
When you read this tutorial it is quite likely that there are newer versions available of the software I used. In most cases if you download the latest version it shouldn’t change the installation procedure…but you can never know, so if you run into problems, read up on possible solutions or try to use the versions listed here and see if it helps.
Installing Apache
You can download the latest 2.4 Apache for Windows from this site: http://www.apachelounge.com/download/. You will also need the VC11 Visual C++ Redistributable for Visual Studio 2012. You can download it from here: http://www.microsoft.com/en-us/download/details.aspx?id=30679.
First install the VC11 Visual C++ Redistributable for Visual Studio 2012, then download and extract the Apache web server. The extracted folder contains a folder named Apache24, copy this where you want Apache to reside. I’ll have it under the following path: C:/Software/Apache24.
Next, we need to register Apache as a service. In your command line (open it as an Administrator) navigate to the bin directory of your Apache installation. In my case it is: C:/Software/Apache24/bin, and issue the following command:
httpd -k install
The -k option tell Apache to start the service immediately after installing it. If the installation is successful, you will recieve an output similar to the following:
Installing the Apache2.4 service
The Apache2.4 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
httpd: Syntax error on line 37 of C:/Software/Apache24/conf/httpd.conf: ServerRoot must be a valid directory
As you can see it notifies you that the ServerRoot must be a valid directory. This is because by default the configuration specifies c:/Apache24 as the Apache installation directory. Open the httpd.conf file in your conf directory and replace all occurrences of c:/Apache24 with the path to your actual installation directory.
Run the services.msc command to see if Apache is really installed. You should see Apache2.4 in the list of services.
Remember that we recieved an error when we installed it so it couldn’t start then. Right click on the Apache service and start it.
Type localhost or 127.0.0.1 in your browser and you should see a blank page with an “It works!” message. This HTML page is located in the htdocs directory. It is served by the Apache web server, so it works correctly. Although, currently it is only capable of serving static content.
Installing PHP
You can download PHP for Windows from this site: http://windows.php.net/download/. Choose the latest 5.4 thread safe version that is available. At the time of writing the latest 5.4 release is 5.4.30. I know that 5.5 has been around for a long time, but I have come across a couple of hosting providers where the highest available version is 5.4 so for compatibility reasons I am sticking with that.
Download PHP, extract it, and move it to the desired location. I moved PHP to the C:/Software/php-5.4.30 directory. In the root of this directory find the php.ini-development file and rename it to php.ini, this will contain the configuration of PHP.
The next thing to do is to enable Apache the serving of PHP pages. For this, add the following lines to the end of your httpd.conf file:
#Configure the PHP module
LoadModule php5_module "C:/Software/php-5.4.30/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
#Configure the path to php.ini
PHPIniDir "C:/Software/php-5.4.30"
Change the paths according to the directory structure you have. Apache needs a module to support PHP pages, this is why we load php5apache2_4.dll, it is in the root of your PHP installation directory.
If you don’t find the dll, then you probably donwloaded the not thread safe version of PHP.
While we are at it, we configure Apache to use index.html and index.php as welcome pages. This means that if you point your browser to a directory that contains one of these files, Apache will automatically display it rather then showing the directory structure. This requires the following config:
DirectoryIndex index.html index.php
To try out if PHP works, rename the index.html located in the htdocs directory to index.php and place some PHP code in it. Then open localhost in your browser. If all went well, you should see the result of you interpreted PHP code.
I used the following php code:
<html>
<body>
<?php phpinfo(); ?>
</body>
</html>
And this is what I see:
Installing MySQL
Download the MySQL Community Server. You can download the latest version (at the time of writing 5.6.19) from this site: http://dev.mysql.com/downloads/mysql/.
Installing MySQL is a pretty straightforward process, just download the Windows installer and follow the steps. After the installation is completed the MySQL server instance configuration wizard opens.
Choose the Detailed configuration, but just accept most of the default settings. The only changes you should make is to set the character encoding to utf8 and provide a password.
At the end of the wizard, the MySQL service will be registered and started automatically.
Checking the MySQL connection
To check the connection I suggest you to install MySQL Workbench. This is a great tool for administering your databases and designing your database schemas.
To test your MySQL server, create a new connection:
- Hostname: 127.0.0.1
- Port: 3306
- Username: root
Then click on Test Connection and type in the password you provided during installation.
phpMyAdmin
Download the latest version from here: http://www.phpmyadmin.net/home_page/downloads.php. You can check on the download page if it is compatible with the PHP version you are using.
Extract the downloaded archive, rename the folder to phpmyadmin and copy it to the htdocs directory. Type localhost/phpmyadmin/setup/index.php in your browser. You should see the following error message:
Fatal error: Call to undefined function mb_detect_encoding() in
C:\Software\Apache24\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc on line 177
To fix this open php.ini and perform the following changes:
- Set your extension_dir to the correct path according to your PHP installation. In my case it is: extension_dir = “C:/Software/php-5.4.30/ext”
- Enable the php_mbstring.dll extension by uncommenting it.
If you restart your Apache, your should now be able to load the page. However, there are still two errors displayed:
Bzip2 Bzip2 compression and decompression requires functions (bzopen, bzcompress) which are unavailable on this system.
Cannot load or save configuration Please create web server writable folder config in phpMyAdmin top level directory as described in documentation.
Otherwise you will be only able to download or display it.
To solve the first one, enable the php_bz2.dll extension in your php.ini and restart Apache. For the second one, create a directory called “config” in your phpmyadmin folder. If you refresh your browser, the errors are gone. Leave everything on default and open localhost/phpmyadmin. There you can see another error 🙂
The mysqli|mysql extension is missing.
There is a quick fix for this also. Enable the php_mysql.dll and php_mysqli.dll extensions and restart Apache. Now phpmyadmin should work correctly.
This completes our setup.
Conclusion
As you can see, installing these software seperately involves a few gotchas, but leaves you with complete control over your development environment. You can easily swich any of the components to newer versions at any time.
If you would rather like a quicker installation, then check out WAMP or XAMPP. They are ready made packages containing all of the software we have just installed but you will have much less control over the individual components.