Home > Article > Backend Development > What to do if php cannot connect to mysql under linux
Solution to the problem that php cannot connect to mysql under Linux: First open the terminal; then execute the [apt install php-mysql] command to install the php-mysql module; finally execute the [service apache2 restart] command to restart the server.
Cause analysis:
It may be that the php-mysql module is not installed.
(Recommended tutorial: php graphic tutorial)
Solution:
First execute the following command to install the module:
apt install php-mysql
(Learning video recommendation: php video tutorial)
Then execute the following command to restart the apache2 server.
service apache2 restart
The above is the detailed content of What to do if php cannot connect to mysql under linux. For more information, please follow other related articles on the PHP Chinese website!