Apache, MySQL and PHP on Windows 8

Technology
Updated:

My good web admins. Please allow me to share with you an Apache, MySQL, PHP installation success story. It’s a story that shouldn’t be exclusive to any one person, and an experience that should be easily recreated by anyone, and the instructions of which should be easily findable through your favorite search engine. But the technological world changes ever so rapidly and up-to-date guides quickly go out of date. I expect this guide to be subject to the same fate. I fully understand that any and all links I post here might be inactive a few months from now. I’ll do my best to keep revisiting this section.

Still, in this brief snapshot in time, I hope to share my (so far) successful experience setting up Apache 2.2.22, MySQL 5.5, and PHP 5.3.5 on Windows 8, as I believe the hiccups that prevented me from a smooth setup could still be encountered on other Windows platforms.

First of all, I recommend consulting apacheguide.org while installing, as it has proved to be a very usueful guide. I was able to install them with the MSI files, with the exception of PHP because success came only after using one of their zip files. I’m still learning about working with web servers and I wish to flatten the learning curve only a few degrees at this juncture and hold off on compiling these tools from source code.

So, I used Apache 2.2.22 because it’s the latest version with an MSI to install from. It can be found on httpd’s list of binaries. When I first tried to install the Apache web server on Windows 8, it installed properly but it wouldn’t start because another service was listening on port 80 on localhost. The service that was doing so turned out to be one of the Windows IIS services, namely World Wide Web Publishing service. There may be some other service on your Windows machine associated with IIS that needs to be stopped. IIS is Windows’s built in web server that uses .NET technologies like ASP for server-side scripting and MSSQL for database management. After stopping World Wide Web Publishing with services.msc, Apache finally started.

Next, I installed MySQL straight from Oracle. The installer set everything up just fine with all the default options. The last time I installed MySQL was in 2010 or so. This time, I was pleasantly surprised by the MySQL Workbench. It’s a GUI that lets you work with databases and it’s a great way to avoid using the command line if you’re in a hurry. phpmyadmin 3.5.5’s interface is substantially improved as well. I’ll have more to say about that later.

I had a lot of trouble getting PHP to cooperate. First of all, I recommend simply using one of the zip files from the Windows download archive page. Since I’m using Apache installed from one of the binaries at apache.org, I’m using the last version of PHP that was compiled with VC6, which is PHP 5.3.5. I recommend just unzipping the contents of php-5.3.5-Win32-VC6-x86.zip into C:PHP, since a lot of installation instructions on the site assume that installation directory.

The php.ini-development file will start PHP up just fine if you rename it php.ini. From there, I’d follow the PHP Apache Guide to make sure you’re on the right path. The most important parts will be assigning extension_dir and session.save_path to directories that actually exist. I’d follow the rest of the guide’s instructions too.

If you want to use phpmyadmin make sure you at least have the Bzip2, mcrypt, mbstring, and (of course) mysql extensions loaded in PHP. You’ll want Zip as well, but it looks like that extension is available in PHP 5.3.5 by default. See PHP’s guide on installing extensions on Windows.

To get Apache to recognize PHP, take a look at PHP’s guide on configuring Apache, especially the example that shows the directives you’ll want to add to http.conf. Be sure to load php5apache2_2.dll if you’ve got Apache 2.2. You can simply cut and paste this part to the very end of http.conf. I would even put PHPIniDir in an tag. Something like:

<IfModule php5_module>
PHPIniDir "C:/php"
</IfModule>

This may not be all that necessary because if Apache can’t load the module, the web server won’t start, so you’d never even get to the PHPIniDir line. But a slight advantage is that you can simply comment out that LoadModule line if there’s a problem and not have to do the same thing with the ini directive.

After adding lines for the extensions you need in php.ini, making sure extension_dir and session.save_path are set to the right directories and adding the final lines to http.conf, the web server triad should be properly configured to dynamically serve some pages. Last, you may want to setup phpmyadmin as it will help a lot in maintaining your site.

The newest phpmyadmin lets you edit database fields by merely clicking on them in the Browse tab. Quite convenient. There are a ton of features I still know little about, that I’m sure are essential. If anything, just the look and feel of the whole site is significantly improved from previous versions.

As I’m sure you’ve guessed, phpmyadmin will also require additional configuration. After grabbing the latest version from their site, extract the contents to a folder called phpmyadmin right underneath Apache’s document root (the htdocs folder, if you haven’t changed it). Take a look at the documentation’s section on using the Setup Script to install phpmyadmin. You’ll want to create a folder called “config” underneath the phpmyadmin folder. You can either move a config.inc.php file there from an older phpmyadmin installation, or leave it empty to create a new one. If you then go to //localhost/phpmyadmin/setup in your browser, you’ll be shown the basic steps to take care of in order to get the site running.

On the Edit Server page, under the Basic Settings tab, make sure you enter localhost for Server Name and mysqli for PHP Extension to use. Under Authentication, you should set Authentication Type to cookie or http if you are concerned about external access. If you are just using a private test server, you can set this option to config and enter your MySQL username and password to avoid having to enter it every time you use the site.

The last thing I recommend, which they could draw more attention to, is to go to the Configuration Storage tab and fill out all the text fields. There are links next to each field for a documentation section on the value, and they will help you better understand what each configuration table is for. They allow you to use advanced features like saving history, enabling the click-and-edit feature, PDF conversions, and so on. It’s worth enabling all of this as phpmyadmin will keep complaining if you do not.

You’ll first need to create these pma tables by running the SQL file at localhost/phpmyadmin/examples/create_tables.sql. You can use phpmyadmin to do this by using the Import link. Once the tables are there, you can return to the setup script and click the pencil icon next to each text field pertaining to a pma table name so that it will enter the default value. Alternatively, you could set the config table values for the setup script first and then subsequently create the tables.

With perseverance and luck, you will finally have a fully-featured config.inc.php file which you should put right under localhost/phpmyadmin. Everything should now be in order. I hope this little guide helps someone else get an open source test web server running on Windows 8 as well.

And now, for Linux…

Update: 3/21/13

Getting a classic LAMP setup on Ubuntu 12.04 was quite straightforward when following instructions from the OS’s documentation. I decided to install the components separately and went to the Ubuntu Software Center to get the php5 and MySQL Server (5.5) metapackages. I went ahead and upgraded my OS to 12.10 so that I could get PHP 5.4 through the software center. The apache2 package available is Apache 2.2.22. I setup phpmyadmin just from the source on their site, but you can also dowload it from the software center if searching in “universe” repositories is enabled, which it was for me by default . Hopefully, Fedora is just as easy. Haven’t setup Fedora 18 yet.

Update: 3/24/13

Well, to my pleasant surprise, installing a LAMP server on Fedora 18 turned out to be even easier. The instructions at this thread spelled instant success. The httpd package gives you Apache 2.4.3 and the php one gives you PHP 5.4.12 at the moment. The MySQL version is still 5.5

Final Update: 5/13/13

I just lastly wanted to add that I finally came to realize that getting Apache 2.4 and the most recent PHP going on Windows 7 and 8 turns out to be not all that complicated either. The site Apache Lounge offers the versions of Apache that the most recent PHP for Windows is compatible with. At this moment, this thread has the links for their Update 2 version. It’s their News & Hangout section that tends to advertise such updates. Follow their very simple instructions and you should have Apache 2.4 running on Windows 7 or 8 (the older ones do not appear to be supported). And remember that you can only run the 32 bit version of PHP with the 32 bit version of Apache, and the same with 64 bit versions. The main links on PHP’s Windows download page have the 32 bit versions. You can find 64 bit versions of PHP on the Apache Lounge site too.

What say you?