Sams Teach Yourself PHP, MySQL and Apache All in One (2012)

Part I. Getting Up and Running

Chapter 1. Installation QuickStart Guide with XAMPP

In case you want to get started quickly, this short chapter steps you through installation from the all-in-one cross-platform installation package, XAMPP. Then, the next three chapters explain how to obtain and install MySQL, Apache, and PHP, respectively, from the Internet so that you can make sure that your versions are up-to-date. In addition, those next three chapters contain extended explanatory information about each step and other important information relevant to understanding how these technologies work together.

You should familiarize yourself with the extended information for each technology in those next three chapters. However, if you just want to get started working on your local machine, that’s fine, too.

Using Third-Party Installation Packages

Third-party installation packages are those bundles of programs that are provided by a company or organization other than the original creator. In this chapter, you learn how to use the XAMPP installation package to install PHP, MySQL, and Apache simultaneously, on whichever operating system you are using (Linux/UNIX, Windows, or Mac).

Besides my own experience as an XAMPP user for several years, I selected it for use in this chapter because of the X in its name: The X indicates it is a cross-platform installation of AMPP (or Apache, MySQL, PHP, and Perl). (Perl is not a topic of this book, so just consider it a bonus.)

There are two other very good third-party installation packages for Apache, MySQL, and PHP that are specific to operating systems:

• WAMP—Installation of Apache, MySQL, and PHP on Windows. See http://www.wampserver.com/ for more information.

• MAMP—Installation of Apache, MySQL, and PHP on Mac. See http://www.mamp.info/ for more information.

One potential drawback to using third-party installation packages is that the version of the core technologies that are bundled together will always be a few revision versions behind. This happens because of the work that goes into creating and testing the bundle itself, to ensure that no conflicts exist between the latest versions of the technologies; it also has to go through a quality-assurance process. The upside of this process, however, is that when you install these technologies using a bundled installer, the upgrade process requires nothing more than running the new installer—it takes care of removing and updating all the files for you.

The next three sections describe the basic installation process of XAMPP. You only need to read the section that applies to your operating system. However, be sure to read the “Securing XAMPP” at the end of this chapter; it applies to all operating systems.

Installing XAMPP on Linux/UNIX

Although the following instructions were tested on an Ubuntu Linux system, the steps are the same for a default installation of all other Linux or commercial UNIX distributions. Should you encounter unexpected error messages during compilation, contact your systems administrator or refer to the documentation for your particular operating system.

If you are using the version of XAMPP included on this book’s CD-ROM, begin as the superuser (either log in as root or su from a regular system user) and mount the CD-ROM under /mnt on your filesystem:

# mount /dev/cdrom /mnt -t iso9660

Now that you have access to the XAMPP file on the CD-ROM, or if you have downloaded the latest version from http://www.apachefriends.org/en/xampp-linux.html, continue to the specific installation steps.

As the superuser, copy the file from the XAMPP directory on the CD-ROM (or from your download location) to the /opt directory. Within the /opt directory, extract the files you have downloaded:

# tar xvfz xampp-linux-VERSION-NUMBER.tar.gz -C /opt


Note

The XAMPP version number at the time of this writing is 1.8.0-beta2, so the filename is xampp-linux-1.8.0-beta2.tar.gz. Later versions will have a different filename, so adjust the command accordingly.


This creates a directory called /opt/lampp, in which XAMPP is installed. To start XAMPP, first change directories to the new directory:

# cd lampp

Issue the following command to start XAMPP (which starts Apache and MySQL):

# ./lampp start

You will see a message such as this:

Starting XAMPP for Linux 1.8.0...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.

To test whether the web server is running, open a web browser and enter http://localhost/xampp/index.php. The menu for the XAMPP service should display, as shown in Figure 1.1.

image

Figure 1.1 The XAMPP menu page.

That’s all there is to it; XAMPP has installed Apache, PHP, and MySQL on your machine, and you can see the status of services and read more information about it through the links in the left column when viewing http://localhost/xampp/index.php.

To stop XAMPP and its services, you can issue the following command at any time from the command line:

# /opt/lampp/lampp stop

Be sure to read “Securing XAMPP” at the end of this chapter for more information about locking down your XAMPP-powered machine (even if it is only for development).

Installing XAMPP on Windows

The XAMPP installation file included on the CD-ROM has been tested and is suitable for Windows operating systems from XP through Windows 7. Earlier versions of Windows are not supported.

To use the XAMPP installation file from the CD-ROM, first insert the CD-ROM into your PC; it should play automatically. If it does not, double-click the drive icon for your CD-ROM under My Computer, and navigate to the directory containing the XAMPP installer files.

Now that you have access to the XAMPP file on the CD-ROM, or if you have downloaded the latest version from http://www.apachefriends.org/en/xampp-windows.html, double-click the file to launch the wizard-based installer program.


Note

Because of the nuances in the Windows operating system releases, and because of different security practices and programs that may be installed on Windows machines, if any of the installation steps do not go smoothly, visit the XAMPP FAQ for Windows users athttp://www.apachefriends.org/en/faq-xampp-windows.html.


You are first asked to select your language; English is the default selection. After selecting your language and clicking the OK button, you will see the welcome screen of the installer program, as shown in Figure 1.2.

image

Figure 1.2 The XAMPP installation main screen.


Note

The XAMPP version number at the time of writing is 1.7.7, so the installation wizard displays that number. Later versions will have a different number, but the process will be similar.


Click the Next button to continue the installation process. As with most wizard-like installations, you are asked to select an installation location and some installation options before moving to the next step. The XAMPP installation is no different; you should leave the default installation location and the default installation options as marked and click the Next button to move on past each screen. At this point, the installation process itself happens, as shown in Figure 1.3.

image

Figure 1.3 The XAMPP installation continues as the files are extracted.

When the installation process finishes, the installer alerts you to this status; click the Finish button to complete the installation. Before the XAMPP installation process completely closes, it asks whether you want to start the Control Panel for managing the installed services, as shown in Figure 1.4.

image

Figure 1.4 The XAMPP installation is complete.

The XAMPP Control Panel, as shown in Figure 1.5, provides you with one-click access to starting and stopping the Apache and MySQL server processes running on your machine. If you are running these server processes on your local machine for development purposes only, you might want to turn them on only when you need them; the Control Panel allows quick access to do just that.

image

Figure 1.5 The XAMPP Control Panel.

To test whether the web server is running, open a web browser and enter http://localhost/xampp/xampp.php. The menu for the XAMPP service should display, as shown in Figure 1.6.

image

Figure 1.6 The XAMPP menu page.

That’s all there is to it; XAMPP has installed Apache, PHP, and MySQL on your machine, and you can see the status of services and read more information about it through the links in the left column when viewing http://localhost/xampp.

Be sure to read “Securing XAMPP” at the end of this chapter for more information about locking down your XAMPP-powered machine (even if it is only for development).

Installing XAMPP on Mac OS X

The XAMPP installation file included on the CD-ROM has been tested and is suitable for Mac OS X 1.4 and later. Earlier versions of Mac OS X are not supported.

To use the XAMPP installation file from the CD-ROM, first insert the CD-ROM into your Mac; it should play automatically. If it does not, double-click the drive icon for your CD-ROM and navigate to the directory containing the XAMPP installer files.

Now that you have access to the XAMPP file on the CD-ROM, or if you have downloaded the latest version from http://www.apachefriends.org/en/xampp-mac.html, double-click the DMG image. You will see a screen like that shown in Figure 1.7.

image

Figure 1.7 Instructions for installing XAMPP on a Mac.


Note

The XAMPP version number at the time of writing is 1.7.3 for Mac users, so the installation package displays that number. Later versions will have a different number, but the process will be similar.


Follow the onscreen instruction to drag the XAMPP folder to the Applications folder. After the folder and files are copied, you can find a link to the XAMPP Control Panel in the /Applications/XAMPP folder, as shown in Figure 1.8.

image

Figure 1.8 Find the link to the XAMPP Control Panel.

Double-click this link to start the XAMPP Control Panel, through which you can start and stop the Apache and MySQL server processes running on your machine. If you are running these server processes on your local machine for development purposes only, you might want to turn them on only when you need them; the Control Panel allows quick access to do just that.

To test whether the web server is running, open a web browser and enter http://localhost/xampp/index.php. The menu for the XAMPP service should display, as shown in Figure 1.9.

image

Figure 1.9 The XAMPP menu page.

That’s all there is to it; XAMPP has installed Apache, PHP, and MySQL on your machine, and you can see the status of services and read more information about it through the links in the left column when viewing http://localhost/xampp/index.php.

Be sure to read “Securing XAMPP,” next, for more information about locking down your XAMPP-powered machine (even if it is only for development).

Securing XAMPP

The primary purpose of XAMPP is to provide a quick-and-easy installation method for Apache, MySQL, and PHP within a development environment. One of the tradeoffs for this quick-and-easy installation is that some security settings are left incomplete—or, at least, up to the user to determine whether they are important enough to set.

Using the installation right out of the (virtual) box, the following are some potential security issues:

• The MySQL administrator user has no password. (You can use a blank password.)

• MySQL and Apache run as the same user (nobody; relevant for Linux/UNIX and Mac only).

• Some services are accessible to the network unless you specifically disallow access through your personal firewall.

However, XAMPP provides a utility for each operating system, which you can run and step through the process of securing your XAMPP system even in a development environment, as follows:

• On Linux/UNIX, run the utility by entering the following on the command line:

# /opt/lampp/lampp security

• On Windows, open the Security Console by navigating to http://localhost/xampp/index.php in your web browser and selecting Security from the navigation menu on the left side.

• On Mac, open a terminal window and enter the following on the command line:

# /Applications/XAMPP/xamppfiles/xampp security

Troubleshooting

The steps in this chapter have been tested with the versions of the software supplied on the CD-ROM that accompanies this book. If you experience installation problems, first check that you have followed the steps exactly as given in this chapter. Then, check the XAMPP website athttp://www.apachefriends.org/ for FAQs specific to this installation package.

If these processes still don’t work and you want to try another all-in-one third-party installation package, feel free to try WAMP and MAMP (mentioned at the beginning of this chapter).

You could also try the installations the “long” way, using the extended information found in the next three chapters. Those chapters provide troubleshooting tips and links to additional sites that can help you work through your installation issues.