XAMPP: The PHP Developer’s Dream

0

This is the final installment in a series of four articles by Brian Kelly on PHP.

Regardless of whether your production server is a System i or a System p, or if you run x-Series servers, z-series mainframes, Solaris, or HP, your dream development machine for building dynamic PHP applications needs to have XAMPP from Apache Friends. XAMPP is a phenomenal integration package for the development components that just about every modern day Web developer requires, regardless of platform they work on.

The “X” in XAMPP stands for “operating system.” The rest of the acronym is: Apache, MySQL, PHP, and PERL. XAMPP also integrates a number of other related open source packages that have value to many developers, including: OpenSSL, PEAR, PHPMyAdmin, ProFTPD, and Webalizer.

As you may have guessed, the “X” also means that there are distributions of XAMPP built for multiple operating systems. Right now, there are four operating systems supported by XAMPP: Linux, Mac OS X, Solaris, and Windows. The package can be can be downloaded from the Apache Friends Web site and it installs quite handily.

Just about anybody building Web applications with PHP has heard of or has used the LAMP stack, and many others have used WAMP. It probably comes as no surprise that the “L” in the LAMP stack means “Linux” and the “W” in the WAMP stack stands for “Windows.” In both acronyms, the “P” has triple duty: PHP, PERL, and Python. Although, while you can run Python in XAMPP, it is not integrated, but available as an add-on. Python lovers know it to be an interpreted, interactive, object-oriented programming language. Industry gurus often compare Python to the likes of Tcl, Perl, Scheme, or Java.

Many programmers know from experience that it’s not a totally uneventful task to install an Apache Web server on most platforms. It gets even harder if you want to add MySQL, PHP, and Perl. That is the beauty of XAMPP. I know that it is easy to install because I did it myself. You just download, extract, and start it up. Once you find out where the htdocs root is stored, you are minutes away from serving static pages and PHP scripts, with or without MySQL. You can use PERL scripts right out of the box, and the XAMPP stack even runs on Windows clients.

How does XAMPP stack up against LAMP and WAMP? The best answer is that it doesn’t. XAMPP is being recognized as the best way to deploy a LAMP or WAMP stack. Integration has always been problematic when you have a number of separate open source components like MySQL, PHP, PERL. XAMPP comes as close as anything to eliminating this problem. With XAMPP, there is no reason for developers to ignore open source solutions when collecting their tools. XAMPP assures that the versions of all the individual products are compatible and that the full stack is updated as frequently as possible. Who could ask for more?

Apache friends love to boast that the distribution of XAMPP is free of charge. They say that they don’t like overpriced commercial software and XAMPP is their attempt to do something that shows free software doesn’t have to be bad.

XAMPP installs easily under Linux or any other OS. Regardless of your distribution, the installation in Linux is as simple as a tape archive command that in all cases will look very similar to this:

tar xvzf XAMPP-linux-1.x.x.tar.gz -C /opt

So, I have made my point. Not everything in life is this easy. Well, the XAMPP installation actually is just one command, unlike with the integrated LAMP stack where the developer (you) still must edit some configuration files to customize the components. Linux experts suggest that regardless of your Linux experience level, this need not be a showstopper. The XAMPP configuration files are well-documented, so you can get the job done post haste with minimal pain.

My mission in this article is not to make you into a Linux XAMPP pro. In fact, the true mission is to help you get this great tool set up on your Windows desktop in a no-brainer fashion. Before you even begin to develop PHP for your host site–whether it be a System i, Windows, or some flavor of Unix or Linux–you can learn PHP and MySQL, and even HTML and CSS if you don’t already know these important tools, right on your own PC.

Then, after you “know it all,” set up your production environment on System i or whatever your platform happens to be. Move the test scripts that you developed in your Windows XAMPP learning experience to your big production system and you should be quite pleased. They should, for the most part work immediately upon uploading without changes.

XAMPP for Windows Clients

XAMPP runs on all reasonably robust Windows clients – 2000, XP and Vista. There has been some grumbling about Vista in terms of issues and performance as expected, but it is getting better and better as more is understood and workarounds are provided and the components of the distributions are adapted. The Apache Friends have a note on their site with some suggestions:

Note for Vista Users: Because missing or insufficient write permissions in the “c:program” files folder of the default Vista installation, I recommend using the alternate folders for XAMP: c:XAMPP or c:myfolderXAMPP.

Just as in Linux, to install XAMPP you only need to download and extract the file. One of the beautiful things about the method I chose for this article, and will explain to you as we go, is that there are no changes to the Windows registry. (Of course this is not true if you choose to use the Windows installer version of XAMPP, which I did not.) Besides not having to make changes to the registry, it’s not even necessary to edit any configuration files to set up for an on-desk full Web testing environment.

Along with XAMPP, you will find that some working sample programs are included with the package. For example, there is a small CD collection program (written in PHP using MySQL) and a small guest book application (written in Perl). There are also some other demonstration utilities.

It can be removed from your systems just as easily as it loads onto the system. If you decide that XAMPP isn’t needed any more on your client system, just delete the XAMPP directory and all components of the package will be completely removed.

In my original install, I was not taking any chances, so I used the Windows installer version of XAMPP. In this case, I had to use normal Windows uninstall feature. The uninstaller gets rid of the registry entries as well as the directories. If you have not shut down all of XAMPP prior to the uninstall, it will leave the XAMPP directory in place (but mostly empty). Unless you can shut all components down ahead of time, you will have to come back and delete the XAMPP directory after a reboot to complete the uninstall.

Please note that the default configuration is not so good from a security point of view as it is for getting the package up quickly. On your client PC, this may not matter, but it is not secure enough for a production environment. So it is not recommended that you not use the default XAMPP in such an environment.

Although XAMPP is free, it still has a license. It is actually a compilation/integration of other free software (comparable to a Linux distribution). But it is free of charge and free to copy under the terms of the GNU General Public License. Apache Friends caution that it is only the compilation of XAMPP that is published under GPL and they suggest that you check every individual license (MySQL, PHP, etc.) of the contained products to get an overview of what is and what isn’t allowed with the component. Since XAMPP operates on a tight budget, they also offer no warranty and also no implied warranty of merchantability or fitness for a particular purpose. This is all standard stuff and you should still wind up with a nice installation without a monkey on your back.

Installing XAMPP for Windows Client

1. Create a folder to catch the archive file:

MD C:downloadsXAMPP

Feel free to put this on E or F or your favorite client drive as long as it has a few hundred meg of extra space available.

2. Start the download process at the following link:

http://www.apachefriends.org/en/XAMPP-windows.html

3. Scroll down to “Download” and click on the XAMPP link.

4. You will see some information about various ways to install. Three different downloads are available:

Windows Installer–This uses the typical Windows installation approach. Its advantage is that it is familiar and safe for anybody who has ever installed a package to Windows that updates the registry.

ZIP archive–This is a normal ZIP archive that can be unzipped by PKZIP or WINZIP.

Self-extracting 7-ZIP archive–This is a special high compression ration version that requires you to load a special unzipper. This method is very economical in size but it does require an additional product to unzip.

5. Because I was not interested in downloading another archive product and because I just got my new high-speed cable connection, I selected the standard ZIP archive with no Windows installer required.

Scroll down to “XAMPP Windows 1.6.3a” (basic package) and click on “ZIP” (80 MB Zip Archive).

6. Choose “Save to Disk.”

7. Select “x:downloadsXAMPP” (X = drive letter) and click “Save” to save the “xampp-win32-1.6.3a.zip” file.

8. Go to the “x:downloadsxampp” folder and click on the archive to run the extraction.

9. Select the option to extract to a first level directory named “x:xampp” in which “x” is the drive letter where you want the package installed. In my case, I picked c:XAMPP.

10. Click to go inside the c:xampp folder to see the file structure:

11. Create a folder within htdocs called “MYPHP” for your stuff.

MD c:XAMPPhtdocsMYPHP

This is the htdocs for PHP and Apache and MySQL.

12. By extracting XAMPP in a top level folder like c:xampp or d:xampp as you will, you can start XAMPP directly. That means you do not need to execute the “setup_xampp.bat” at all. Apache, MySQL, and Mercury Mail server will start up correctly! The FileZilla FTP server will not start because it requires absolute paths. Please note: Do not use a double-XAMPP-folder like c:xamppxampp! You need a single- XAMPP folder like d:xampp(apache and so on). Otherwise you must run the “setup- XAMPP.bat” to set up the path configurations. Do not run the setup-xampp.bat procedure.

13. Click to open the c:xampp folder.

14. Click on xampp_start.exe and it should all start.

15. Check the DOS box that appears. It looks like this:

16. Do not end the DOS box unless you intend to shut down XAMPP. While you’re at it, take a little German lesson and you get an idea of where the roots of XAMPP originate.

17. To see if your installation has worked, type the following in the URL of a browser from your client workstation:

http://localhost

18. Check to make sure you see a panel such as the following:

19. Click on “English” or your preferred language to continue.

20. Check to make sure you see this panel:

Once you are in, check for status, security, documentation, etc., by clicking the menu items on the left frame. All of these functions are written in PHP scripts.

Here are some more server scripts, you might find useful:

  • Apache & MySQL start: .xamppxampp_start.exe
  • Apache & MySQL stop: .xamppxampp_stop.exe
  • Apache start: .xamppapache_start.bat
  • Apache stop: .xamppapache_stop.bat
  • MySQL start: .xamppMySQL_start.bat
  • MySQL stop: .xamppMySQL_stop.bat
  • Mercury Mailserver start: .xamppmercury_start.bat
  • FileZilla Server setup: .xamppfilezilla_setup.bat
  • FileZilla Server start: .xamppfilezilla_start.bat
  • FileZilla Server stop: .xamppfilezilla_stop.bat

In addition to the Apache and MySQL start script (xampp_start.exe) that we have already used, there are a number of other scripts available in the list above. The script that may be of most use to you is the universal control center script that is called “call .C:XAMPPXAMPP-control.exe.” As a point of note, the control center is not included in the lite version. Before you start the control center, right click on it and copy the icon to the desktop so that you can start and stop at will.

When you click on this or type it into the Windows command prompt, you get a GUI to help control the server operations.

Notice all of the servers monitored by this control center are running. You need just Apache and MySQL to handle simple scripts.

Go to the head of the class!

In an effort to wrap up, let me make the best suggestion I can for the beginner. Go back and re-learn HTML and XHTML and look hard at CSS. HTML is not what it was in the 1990s. Along with your site development tools such as DreamWeaver or FrontPage, and your intelligent development environment for PHP or Zend Studio and Eclipse via IBM‘s WDSC, you now have all of the server side material on your desktop for a full development or testing environment. Once you make your applications work in this environment, when you upload them to the host server, such as a System i with MySQL and PHP, and they are most assuredly going to work right away or work with minimal changes.

The point is you get to do all of that development work on your client, wherever that client may be. And, you do not have to worry about Apache, PHP, or MySQL restarts to be able to get a good test. Once have a complement of SQL tables, the development using MySQL is the same regardless of platform. You now have the developer’s dream machine for PHP.

Learning HTML, CSS, XML, PHP, and MySQL Scripting

It is amazing how much material is available for learning for free on the Internet. High quality no cost materials are available at www.w3schools.com.

Scroll down the left frame and you will find an amazing number of offerings. By dropping scripts into your MYPHP folder in c:XAMPPhtdocs, these learning scripts are servable from your PC with the local host URL. The lists of tutorials follow:

HTML Tutorials

XML Tutorials

Browser Scripting

Server Scripting

.NET (dotnet)

Multimedia

Web Building

PHP & MySQL Scripts

Under Server Scripting, click on Learn PHP. Then scroll down until you see these tutorial components under PHP Database:

  • MySQL Connect–Shows you how to open and close a connection.
  • MySQL Create–Shows you how to create a database and a table in the database.
  • MySQL Insert–Shows you how to add records to a table in a database.
  • MySQL Select–Shows you how to select/display records from a database.

If you are taking a full set of tutorials to learn HTML, CSS, XML, PHP, and MySQL scripting, then you should begin with the HTML tutorial and follow in sequence. If you were a student in my fall course, the tutorials would make up a big part of your learning assignment.

If in addition to these skills you also need to acquire Apache and directive skills, then you need another tutorial. You might try a GUI that you can use for a test period to help you learn directives, like the one you can find at this link, or you can go right to a full tutorial like the one found at this link. Typically only a Webmaster would want to know Apache directives, but on your own XAMPP box, you are the Webmaster.

For now, just this one time within each of the tutorials, I would like to see you connect, create, insert, and select database/data. There are examples in the tutorials that you can copy and paste into Notepad, ZendStudio, Eclipse, or some other editor that you have chosen. For this level work, Notepad is more than adequate and may be the best. Give each of these scripts an identifiable name describes what they do, such as MySQLConnect.PHP, MySQLCreateDatabase.PHP, MySQLCreateTable.PHP, MySQLInsert.PHP, or MySQLSelect.PHP. By the way, although all of these scripts use MySQL the uploaded script files are all PHP scripts and must end in “.PHP.” MySQL operates as a client server database to PHP. To get your stuff to XAMPP for testing, all you’ve got to do is to save the scripts to the MyPHP directory within htdocs directory within XAMPP on your installation drive. Save them one by one as you copy them into Notepad, and save them with those nice names in the MyPHP directory that you created in an earlier step.

So, now that you have your servers started and you loaded all the test scripts, it’s time to give it a run. From a browser, type in the following:

http://localhost/MYPHP/("name of PHP script dot PHP")

Run scripts in this sequence: Create the database, create the table, insert the records, and then for the last script MySQLSelect.php–the one that shows the database–type this URL:

http://localhost/MYPHP/MySqlSelect.PHP

When I typed that in on my PC’s browser, I got the following panel of success as you will too:

Well, there you have it. We moved from having nothing on our machine, to having the full XAMPP stack, to managing the stack with the control center, to taking a few tutorials, to running our own Apache/MySQL/PHP server with XAMPP. This has been a highly successful day and tomorrow when you get to load it on your big host machines, it will be an even bigger day.

Brian Kelly was an IBM Midrange SE for 30 years, and has spent nearly a decade as a System i5 consultant based in Scranton, Pennsylvania. He is also author of dozens of AS/400, iSeries, and System i5 books and he serves as an assistant professor at Marywood University, which uses the OS/400 and i5/OS platform and teaches courses in the box as well. Kelly is also one of the contributing technical editors to The Four Hundred newsletter. He can be contacted through the IT Jungle contact page.

RELATED STORIES

Getting MySQL Working With PHP

IBM Apache Servers Needed by PHP

Setting Up A PHP/Web Environment On System i: Where Do I Start?



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Source link

Share.

Leave A Reply