Unable To Connect MySQL Database Server From PHP

Question: I have configured LAMP ( Linux Apache MySQL PHP ). I am able to connect MySQL server from MySQL client but I am not able to connect MySQL server from PHP scripts. So how do I configure or connect PHP scripts?

Answer: If you are able to connect MySQL server from MySQL client and unable to connect from PHP. Means you will need to install MySQL module for PHP4 or PHP5 and PHPx version. Without PHP-MySQL shared object or module, php scripts won’t able to connect to MySQL database server.

Installing PHP MySQL Modules

Follow the below steps to install PHP MySQL modules:


Type below command to install:

# apt-get install php4-mysql

If you are using PHP5, type:

# apt-get install php5-mysql


If you are using Redhat/CentOS/Fedora:

# yum install php-mysql

Note: If you are using RHEL <= 4 you will need to run the below command.

# up2date php-mysql

Restart Web Server to take effect.

# service httpd restart
# service nginx restart

Now you will be able to connect MySQL via PHP scripts.


Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment