Monday, November 2, 2015

LAMP on CentOS 6.7

Using Apache with MySQL and PHP to Develop Web Applications

The Context

I had freshly installed CentOS 6.7. I had installed it as a developer workstation to be able to create applications using Linux, Apache, MySQL, and PHP (among other things).

What is LAMP ?

A high-level overview of LAMP's building blocks and overall system environment, displayed here in combination with optionally used web caches.
LAMP is an archetypal model of web service solution stacks, named as an acronym of the names of its original four open-source components: the Linux operating system, the Apache HTTP Server, the MySQL relational database management system (RDBMS), and the PHP programming language. The LAMP components are largely interchangeable and not limited to the original selection. As a solution stack, LAMP is suitable for building dynamic web sites and web applications.[1]

I was configuring the Apache web server. I wanted to test PHP with MySQL using an old PHP script I wrote back in 2006.

To my great disappointment, I've found out that the following command in my PHP script was not working:

// Connecting to the database server.
$connect = mysql_connect($db_addr, $db_user, $db_pass)
           or die("Could not connect : " . mysql_error());

All I was getting was a blank page displayed in my user agent (browser).

Note that mysql_connect() is a deprecated call. But my PHP script is one that I wrote in 2006.

The Solution

To obtain debug information when running the script, this is one thing you can do:

  1. Edit the file /etc/php.ini
  2. Change the variable
    display_errors = Off  to
    display_errors = On
  3. Restart the Apache server with:
    # service httpd restart
To fix my problem, I did the following commands:
# yum install php-mysql
# service httpd restart

And it worked... (although it took me a good amount of time to found this solution).
It seemed that the mysql module was not installed!!!