Installing Apache, PHP and CURL on Windows

Posted March 23, 2009 by Gabriel Hurley

I got tired of having to upload every little change to the code of my web designs to the server to see if they even work at all, so I decided I'd run a local web server with PHP on my computer. If they ran Linux, this would be extremely simple. Unfortunately, I run Windows XP on both my development machines.

Apache was a snap:

  1. Download whichever version of Apache you prefer from http://httpd.apache.org/download.cgi. I chose version 2.2, which is the most recent as of this writing.
  2. Run the installer and choose a directory, such as C:\Apache.
  3. Open up the httpd.conf file and set things like the DocumentRoot and any directory options you need.
  4. [optional] edit your hosts file (located at C:\Windows\system32\drivers\etc) to point specific domains to 127.0.0.1 and create different VirtualHosts in Apache for each of those domains. This is useful if you want your local sites to behave as if they're at the root of the site.

Getting PHP installed isn't too much worse, except it's got one big caveat as noted below:

  1. Download the latest version from http://www.php.net/downloads.php (it was 5.2.9 for me)
  2. Run the installer, and select any plugins you know you need to be installed. In my case, I selected CURL. (You will have to manually install and enable the plugin DLL file from the PHP binary zip file later if you don't).
  3. Here's the catch: selecting the plugins to be installed by PHP there DOES NOT install all their dependencies or automativally make them work! It only puts the plugin DLL in the PHP extensions directory and adds a line in php.ini to enable the plugin! You still have to do whatever else it takes to make the plugin work on a plugin by plugin basis.

In my case, I needed CURL, and that was somewhat tricky. I owe credit to Tony Spencer's article for getting me on the right track here.

  1. Download the Windows XP build of CURL from http://curl.haxx.se/download.html and you can also grab Win32 OpenSSL to go along with it. [Note: You may need to download the Visual C++ 2008 Redistributables in order to make the OpenSSL installer work]
  2. Copy the extracted CURL directory to your programs directory, and copy the libssl32.dll from the OpenSSL directory to your CURL directory.
  3. Check to see if you have c:\windows\system32\msvcr70.dll. If you don't, then search for it and download a copy because you'll get error messages without it.
  4. Copy php5ts.dll from your PHP folder to your Apache bin folder. There are other solutions to give Apache access to this DLL, but this is the simplest in my opinion.
  5. Lastly, make sure you've got these two items set in php.ini:
    1. register_globals = On
    2. sessions.save_path uncommented and set to a directory that exists
  6. You're basically all done now; just restart your Apache server to update all these changes, and you should be good to go.

All this worked on my system, and didn't even require a restart. Most of the troubles I ran into involved my lack of understanding how to configure Apache VirtualHosts. So if you run into issues, I suggest you start there. If you're seeing the local copy of your site in your browser but PHP or CURL aren't working, check Apache's error logs in Apache\logs\error.log to see what it has to say.

If that helps you, please let me know in the comments!

Categories: Technical
Tagged: apachecurlphptech tipsweb design

Post A Comment