Section 5.4. Configuring the Server with MySQL and PHP


5.4. Configuring the Server with MySQL and PHP

Today , dynamic Websites are more the rule than the exception. Most sites require some type of database back-end and use one scripting language or another. A bare-bones Apache configuration is perfectly suited to serving up static Web pages without any further configuration, but if you're looking to build a more dynamic site, a little more work is in order.

5.4.1. Installing MySQL and PHP

First , you'll need to make sure all of the appropriate packages for MySQL and PHP are installed. Here we're going for a pretty basic installation of MySQL and PHP; for a knock-'em-dead discussion of the finer details, see Kevin Yank's outstanding Build Your Own Database Driven Website Using PHP & MySQL (SitePoint, ISBN 0957921810).

Figure 5-1. Displaying the packages in the Web Server group.


You can install the necessary PHP and MySQL packages using the Package Management tool we saw in Chapter 4 (Desktop > System Settings > Add/Remove Packages). Launch the tool, scroll down to Web Server, and click the Details button to display the packages in the Web Server group, as shown in Figure 5-1; most of these will probably already be installed.

Ensure that the php and php-mysql packages are ticked (tick them if they're not) and click the Close button.

Next, ensure that the MySQL Database package group is checked. As we're building a server to use MySQL exclusively, we can uncheck the PostgreSQL Database package group, too. Click the Details button for MySQL Database and make sure that php-mysql and mysql-server are checked.

Once you're done, click Update in the main window to install or remove any packages.


Tip: If you'd rather make use of PostgreSQL than MySQL, there's no problem with that. In the Web Server package group, check php-pgsql to give PHP the ability to communicate with PostgreSQL databases. You can uncheck php-mysql to keep your server lean and mean, or leave it in, for added flexibility.

To complete your installation, restart the Apache service using your preferred method.

5.4.2. Testing your Installation of PHP

To test the installation of PHP, let's create a file named phpinfo.php in the /var/www/html directory; you'll need to switch to root to do this. The file should contain only the following three lines of code:

phpinfo.php

 <?php phpinfo(); ?> 

This page will call the built-in PHP function phpinfo() to display all the available information about your PHP installation. Run this page by opening http://localhost/phpinfo.php in your Web browser (Applications > Internet > Firefox Web Browser).

Figure 5-2. Displaying phpinfo.php in Firefox.


Firefox should display details about your server, as shown in Figure 5-2. If it does, congratulations: PHP is working! If not, check that the Apache service is up and running, then check Apache's error log (/etc/httpd/logs/error_log). Searching the Web for any error messages displayed in the error log will usually lead to a solution; alternatively, try your luck at SitePoint's friendly forums.


Tip: Once you've checked the installation, it's a good idea to delete phpinfo.php , lest someone should stumble across the critical details of your PHP installation.



Run Your Own Web Server Using Linux & Apache
Run Your Own Web Server Using Linux & Apache
ISBN: 0975240226
EAN: 2147483647
Year: 2006
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net