April 6, 2011, 3:28 p.m.
posted by pypa
Getting PHP to Run on Your Computer
Before you can start writing your own PHP scripts, you'll need to set up a PHP environment. The easiest approach is probably to sign up for a web hosting account that provides PHP support. Even if you do so, though, there are some advantages to getting PHP to work on your own computer. You can edit files with your favorite editor and then test them right on your own computer rather than uploading them in order to see how they work. You'll also be able to work on them even if you're not online. Finally, you can keep from putting files on a server that your users will be able to see without your having tested them first.
To process PHP pages, you need the PHP interpreter and a web server that works with the PHP interpreter. The good news is that PHP and the most popular web server, Apache, are both free, open-source software. The bad news is that getting PHP up and running can be painful, mainly because it's usually installed as an add-on to the Apache web server. So you have to get Apache to work, install PHP, and then get it to work with Apache.
Fortunately, if you're a Windows or Mac user, someone else has done this hard work for you. A tool called XAMPP, available for both Windows and Mac OS X, bundles up versions of Apache, PHP, and MySQL (a database useful for storing data associated with web applications) that are already set up to work together. You can download it at http://www.apachefriends.org/en/xampp.html.
If you're a Mac user, you also have the option of using MAMP, another free package that combines Apache, PHP, and MySQL. It can be downloaded from http://www.mamp.info.
Once you've installed XAMPP (or MAMP), you just have to start the application in order to get a web server up and running that you can use to develop your pages. To test your PHP pages, you can put them in the htdocs directory inside the XAMPP install directory. For example, if you wanted to test the hello.php page I talked about earlier, you could put it in the htdocs directory. To view it, just go to http://localhost/hello.php.
If that doesn't work, make sure that XAMPP has started the Apache server. If you're using MAMP, the steps are basically the same. Just put your pages in the htdocs folder, as with XAMPP.