2

I have recently updated my Ubuntu version from 16.04 to 18.0.4 with PHP version upgraded to 7.2. I haven't been able to log on to my Wordpress websites due to the following error:

Your php installation appears to be missing the mysql extension which is required by Wordpress

What I have tried:

  • sudo apt-get update & sudo apt-get -y install php-mysql
  • sudo update-alternatives --set php /usr/bin/php7.2
  • while checking if the last one worked with wp --info, I also got the following warning:

PHP Warning: PHP Startup: Unable to load dynamic library 'mysqli' (tried: /usr/lib/php/20170718/mysqli (/usr/lib/php/20170718/mysqli: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mysqli.so (/usr/lib/php/20170718/mysqli.so: undefined symbol: mysqlnd_global_stats)) in Unknown on line 0

These were in fact missing from php.ini. I added both

extension=/usr/lib/php/20170718/mysqli
and
extension=/usr/lib/php/20170718/mysqlnd.

The PHP warning disappeared, but the MySQL extension still seems to be missing.

The php.ini file is located at /etc/php/7.2/cli/php.ini. I restarted apache after each change I made.

Would you have any other solution that might work?

Dharman
  • 30,962
  • 25
  • 85
  • 135
MartaKa
  • 31
  • 1
  • 1
  • 2

7 Answers7

20

1.First check which version install in your pc by using this command :

php  -v

2.for example if you getting 7.2 run like this (based on php version )

sudo apt-get install php7.2-common php7.2-mysql

3.After install MySql restart apache server

sudo service apache2 restart
Jignesh Joisar
  • 13,720
  • 5
  • 57
  • 57
  • I've just tried that, with no success. I got an information in the console that both php7.2-common and php7.2-mysql are already the newest version. – MartaKa Sep 07 '18 at 12:17
  • 1
    @MartaKa can u install mysql-server ? – Jignesh Joisar Sep 07 '18 at 12:32
  • It seems I already have this, checked using dpkg --get-selections | grep mysql and mysql-server-5.7 is listed as installed, among also mysql-client, db-config-mysql and some more. – MartaKa Sep 07 '18 at 12:43
2

I am adding my answer here - though the circumstances are slightly different. I upgraded my Debian installation - and in the process php was upgraded from php 5 to php 7.0

It turns out that apache2 was still loading the php5 module and not the php7.0 module.

I needed to run the below:

  sudo a2dismod php5
  sudo a2enmod php7.0
  sudo systemctl restart apache2

Subsequently, my web pages loaded up.

dntrplytch
  • 109
  • 3
  • Thanks for leading me down the correct path! I used the following: sudo a2dismod php* sudo a2enmod php7.2 sudo systemctl restart apache2 – Piney Jul 08 '20 at 01:43
1

i solved this type of error in my .htaccess using the below code on a shared server that uses cpanel

# END WordPress
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
The Billionaire Guy
  • 3,382
  • 28
  • 31
1

A combination of the solutions above helped me.

After updating I couldn't reach my sites anymore, so I altered the code like this:

sudo a2dismod php*
sudo a2enmod php8.0
sudo systemctl restart apache2
Dharman
  • 30,962
  • 25
  • 85
  • 135
1

For AWS EC2 ubuntu Nginx Server

1.First check which version install in your pc by using this command :

php -version or which php

2.for example if you getting 7.4.33 run like this (based on php version )

apt install php7.4-mysql

3.After install MySql restart apache server

sudo systemctl restart apache2
0

I finally managed to find the solution to my problem.

This particular project runs on PHP 7.0., so I need to switch to the older version of PHP in order to work on it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
MartaKa
  • 31
  • 1
  • 1
  • 2
0

If you are using Apache Ubuntu, Update your PHP version to 8.1 solve your problem

sudo apt update && apt install -y software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update && sudo apt install -y php8.1
php -v

sudo apt-get install -y php8.1-cli php8.1-common php8.1-mysql php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath

sudo apt-get install -y php8.1-fpm

sudo apt install php libapache2-mod-php php-mysql
PyMatFlow
  • 459
  • 4
  • 8