Database

Unable To Connect MySQL Database Server From PHP

connect-mysql-database-server-from-php
mm
Written by Santosh Prasad

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:

Debian/Ubuntu

Type below command to install:

# apt-get install php4-mysql

Or
If you are using PHP5, type:

# apt-get install php5-mysql

RHEL/CentOS/Fedora

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.

Thanks:)

Thank you! for visiting Look Linux.

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

About the author

mm

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