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 ?
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]
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:- Edit the file /etc/php.ini
- Change the variable
display_errors = Off to
display_errors = On - 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!!!