Using WampServer for Local Development

I began taking on-line development classes offered at my local college, and students had to upload their scripts and files via FTP to a school server for processing. The necessary security precautions required a boatload of username/password combinations that were strictly enforced and a pain to remember. Getting my project onto the school’s server was possible, but it was easier for me to develop my project locally before uploading them to where they eventually needed to be.

This article will explain how a development system solves such a problem and how to install the popular Windows-based web development platform WAMP. As a relative newcomer to the PHP language, I hope this article speaks directly to other new programmers who are interested in honing their development skills to eventually become PHP masters.

The Development Server

Every programmer needs a place to write and develop their programs.

A development system is a computer with a group of applications that are installed that perform the same tasks as on a web server. The benefits of this is being able to develop and test your scripts locally without having to upload them first, and the security of maintaining your files locally until they are ready for their intended purpose. Plus you don’t have to be connected to the Internet while you work. We are pretty much always on-line nowadays, but every so often you can find yourself without a connection to the web. Who knows, you may want to crunch code on a laptop while sitting on a beautiful secluded beach.

What is a WAMP Server?

A WAMP server is a computer running these applications:

  • Windows OS
  • Apache
  • MySQL Database
  • PHP

There are many variations, and you may have come across the term LAMP server before. This is essentially is the same as WAMP except it is based on the Linux operating system.

There are also various ways to construct your WAMP server. If you are bold and fearless, you can download and install Apache, MySQL, and PHP individually on your machine, and if all goes well you will end up with a sweet WAMP server. Or if you are like me, you will take the advice of many wise men and install a Windows-based server package of which there are several. I choose to install WampServer. WampServer is open source, free to use under the GPL license agreement, relatively simple package that automatically installs everything you need to start developing.

WampServer even includes a great graphical tool, phpMyAdmin, which helps handle the administration of MySQL. If you have ever dealt with MySQL and its initially intimidating command line interface, you will immediately appreciate how phpMyAdmin helps with creating databases and tables and modifying data within them. Plus, familiarizing yourself with phpMyAdmin may come in handy as many web hosts restrict access to the command line for security reasons.

How to Use WampServer

Go to the WampServer homepage and download the package that is applicable for your local machine. The current version available is 2.2E. The application is constantly updated, so plan on checking in periodically to ensure you have access to the latest version available.

Once you have installed the package, you should see the WampServer icon in the Windows system tray next to the clock display. You may need to click the “show hidden icons” up arrow to see it.

The WampServer menu has links to several related pages and folders.

The uppermost and most important page is Localhost. Clicking Localhost brings up your browser and displays the WampServer menu page which confirms the server is functioning correctly. You will see the versions of all applications and extensions that are installed under the Server Configuration heading.

Under tools are links to the phpinfo() function which, when clicked, will display all of the information related to your particular installation and configuration. Below that you will find a link to the above mentioned phpMyAdmin.

Under the Your Projects heading is a display of the project folders you are working on. Each of your projects should be within its own folder. Your project folders are copied into the www subfolder within the wamp directory.

Running a PHP Script

When clicked, all PHP files and scripts placed in the www folder will be processed by the Apache server where any PHP code will be parsed and processed by the PHP application. It’s almost magical how a PHP script can establish a database connection, execute a query against the database, and dynamically return the results to the client. Depending on the nature of your script, the results can be returned as HTML back to the client browser for display.

During development, when PHP encounters any code errors (and trust me, as a newbie you will encounter many errors), PHP has the ability to display error messages that are great clues to finding the source of the error. The process of error checking and solution finding is part of the learning curve of any programming, and reason enough to set-up a local development server. Without it, one would go nuts having to upload each file revision using FTP to the web server.

Summary

In closing, server-side programming without doubt has its challenges. But now you are aware that setting up a development server using WampServer can save a lot of time and frustration and provide you with the means to safely develop your next killer application on your local machine.

Image via Fotolia

Win an Annual Membership to Learnable,

SitePoint's Learning Platform

  • http://www.phpknowhow.com/ Gayanath Jayarathne

    Good intro. You may also want to mention how to run PHP scripts in command-line with WAMP for those who use command-line programs like PHPUnit.

  • http://www.clinov.com Sylvain Duport

    An alternative I found usevull : UsbWebServer (http://www.usbwebserver.net/en/).
    It can be run on any windows computer from a usb key without any install.

  • http://WebsiteURL Chris Emerson

    Rather than have the WAMP program load and stay in memory / put an icon in the tray, you can also go to Services, find wampapache and wampmysql services and set them to start up automatically. Now you don’t need to run the WAMPServer program after setting up (unless you want to use its menu for something), and the services will always be running in the background.

    • Matt Bragg

      Thanks for the reply Chris. I like the idea of starting those services automatically. I will have to try that and see how it helps my workflow.

  • http://WebsiteURL cap29a

    a other alternative
    easyPHP : http://www.easyphp.org
    Wamp MSS : http://www.uni-d.net/index.php?s=proj&id=3

    • Matt Bragg

      Thanks for the info cap29a, Kind of reminds me of CP30 :)
      I looked into easyPHP and that is really a beautiful thing. I would have never thought of a USB server set-up. It looks really easy to get going and great alternative to a full blown WAMP server.

  • http://www.hollyit.net Jamie

    Another tool to add to the arsenal is Acrylic DNS. What Acrylic does is functions as a DNS proxy. Instead of having to edit your hosts file for every site you work on, you can setup wildcard DNS entries. For example, on my development machine I have *.dev set up, so I can now use Apache VirtualHosts and have things like examplesite.dev pointing to my machine. The setup is really simple and saves tons of time:

    http://sourceforge.net/projects/acrylic/

  • http://WebsiteURL Antonio Martinez

    I recommend you http://www.easyphp.org/ it’s basically the same but using php 5.4 and other components.

  • Les

    I’ve been using WAMP since the very early days and it’s a great server, very stable and easy to install (much better than the alternatives) however it is a bugbear that there is no SSL support out of the box and there has been little support regards to this issue either over the years (that I’ve found).

    Otherwise I would recommend it over a lot of other PHP servers out there.

  • http://alexsablan.com Alex Sablan

    I currently develop my PHP web stuff on my local WAMP and it does save a lot of time from when I was trying to do it on my website server.

  • http://hilsz.com Philippe Hilsz

    I use http://www.apachefriends.org/en/xampp-windows.html enhanced with the latest MySQL, phpMyAdmin, Strawberry Perl, Python

  • Guy

    I used it when working locally on a uni project a few years ago and found it very useful. How easy is it to set up wordpress to run on WAMP locally? I want to delve into the world of WP and figure this would be a good way of doing it. Thanks.

    • Matt Bragg

      Thanks for the response Guy. It is very easy to set-up a WordPress installation using WAMP. Just create a database for WordPress and take note of the database name, user name and password. Then download and extract the WordPress files and copy the files into your project folder in WAMP. Change the WP-config-sample.php file to your actual username and password then return to WordPress to complete the set-up. You will soon have a local WordPress install to work on to your hearts content. Have fun.

  • http://www.sirpigal2012.in Laxman

    Good Introduction for beginner in WAMP server

    • Matt Bragg

      Thanks Laxman. It was my intention to provide basic information for those of us who are working their way towards becoming PHP Masters. There are many ways to get there but we all start from the beginning.

  • http://www.nomiguide.com zeshi

    which is best server xampp or wamp

    • Matt Bragg

      Thanks for the response Zeshi. I have looked at both XAMPP and WAMP and they each have a strong user base, however I am partial to WAMP. Whether one is better than the other can be subjective and ultimately decided by what works best for you.
      Life is good, both are free and easy to install. Try them both and let me know what you think.

  • Jessica

    Hi Matt, I am having trouble (but learning lots!) with sendmail.exe, pear, etc to send email from script – localhost on windows 7 using smtp.google.com, do you have any recommendations?

    • http://mattbragg.com Matt Bragg

      Jessica, I feel your pain as I too tried many ways to send mail from my local environment. I’m sure your research has indicated that it is doable, but just not as easy as one would think. Most solutions require using a separate application such as sendmail.exe as you mentioned. Also you need an appropriate SMTP mail server too, GMail seems to be the most prevalent.
      But once I figured out that PHP sends mail like it is supposed to from the web server ( as opposed to the local box) I was satisfied with that and moved onto the next problem.

  • http://engineeringbooks.net Lionel

    Thanks for this awesome introductory post for the beginners like me. I have started learning advance php and for me i think Wamp is better than Xammp.

    • Matt Bragg

      We are on the same page Lionel. WAMP Server is the way to go for easy local development on a Windows machine.

  • geoquarts

    Matt thanks so much for sharing your knowledge. I’m a newbie to web design, do you think php is a good way to begin a career in web design?

    • Matt Bragg

      Beginning a career in web development involves many technologies and choices to make. Once the basics are under your belt and you have a better understanding of how applications work, then you can decide on which languages or methods you want to use to develop your sites. I choose to learn PHP as a dynamic scripting language because of its large user base and lots of support. Learning PHP will bring you much satisfaction and magical interactivity to your websites.

  • -V-

    I installed wamp, but what good is it? It still requires an internet connection to work.. so what the point of using it

    • Matt Bragg

      You are correct in that WAMP Server requires an internet connection to receive data from the net but there is no way around that.
      The real beauty of a WAMP Server is the ability to run scripts and test functionality against a database or other resources that normally reside on a file server without having to upload and refresh those files on an actual web server, thus saving time.

      The idea is to have the ability to develop your application or site locally, then when it is ready, you upload it to your production server. It really is a good thing.

      Keep at it and if you have any other questions get back with me.

  • tipsys76@yahoo.co.uk

    Hi please i’m having small challenges i formatted my system sometime ago after which i reinstalled wampserver on it but i lost all that i had on the database is there a way i can retrieve them back? Your assistance will be highly appreciated.

    Tunde.

    • http://www.mattbragg.com Matt Bragg

      To tipsys76
      Formatting your computer is like strapping a bomb to your hard drive.
      If you had a backup strategy in place prior to performing your format, then I would suggest using your MySQL backup files to import your data back into your new databases.

      On the other hand…. If you did not implement a plan to backup your data, then I would be inclined to assume that your data is gone. Hopefully you will be able to recreate your data and move on, but I have my doubts given the nature of your inquiry. If worst comes to worst, then this may be a lesson learned that will assure you always have a data preservation plan in place for any future circumstance.