Thursday, January 21, 2010


Configuring Linux Web 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.

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.
Figure: Displaying the packages in the Web Server group.

You can install the necessary PHP and MySQL packages using the Package Management tool  In Linux Server. 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 above; 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.

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:

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: Displaying phpinfo.php in Firefox.

Firefox should display details about your server, as shown in Figure above. 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 some friendly web server 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.


About bench3 -

Haja Peer Mohamed H, Software Engineer by profession, Author, Founder and CEO of "bench3" you can connect with me on Twitter , Facebook and also onGoogle+

Subscribe to this Blog via Email :