Table of Contents[Hide][Show]
If you are a WordPress user and getting an error that says “Your PHP installation appears to be missing the MYSQL extension which is required by WordPress”, then this might be very frustrating to deal with.
Being a webmaster, I faced the same issue with my website. I searched online for a solution, posted in the best of the forums on the internet but did not get any accurate solution to fix my problem.
Finally, I took the initiative to delve into the matter and conduct some in-depth research and experimentation to rectify the error.
Once the issue was resolved, I decided to share the solution to this issue with the people who are using Ubuntu or CentOS, php5-cli
, php5-cgi
, php5-fpm
, and using the NGINX server. The solution might vary as per the services you are using to run your website.
The error message you’re seeing, “Your PHP installation appears to be missing the MySQL extension which is required by WordPress,” indicates that the MySQL extension is not enabled in your PHP configuration, and WordPress requires it to function properly.
The MySQL extension is used by PHP to interact with MySQL databases, which are commonly used to store and retrieve data for applications like WordPress.
Steps to Fix “Your PHP installation appears to be missing the MySQL extension which is required by WordPress”
Before proceeding with the detailed steps, consider implementing the following tweaks:
Check PHP Version: Make sure you are using a version of PHP that is compatible with the MySQL extension. WordPress generally supports PHP versions 5.6 and above. However, it’s recommended to use a more recent version for security and performance reasons.
Enable MySQL Extension: Depending on your server environment and how PHP is configured, you might need to enable the MySQL extension. You can do this by modifying the PHP configuration file (php.ini). Look for the following line and remove the semicolon (;) to uncomment it:
;extension=mysqli
Change it to:
extension=mysqli
This will enable the MySQL extension. Save the php.ini file and restart your web server (e.g., Apache or Nginx) for the changes to take effect.
To deploy PHP applications, “PHP-FastCGI” is implemented which allows NGINX to serve web pages properly.
Check for Alternative Extensions: In more recent versions of PHP, the mysql
extension has been deprecated in favor of the mysqli
(MySQL Improved) extension and the PDO extension. It’s recommended to use mysqli
or PDO for better security and functionality.
If your WordPress installation or themes/plugins you’re using are relying on the deprecated mysql
extension, you might need to update them to use mysqli
or PDO instead.
Update WordPress and Plugins: If you’re using an outdated version of WordPress or plugins, they might be using deprecated features. Make sure to update WordPress core and all plugins to their latest versions to ensure compatibility with modern PHP versions.
If you don’t have access to your admin dashboard, use FTP to delete the outdated themes and plugins and upload the latest version.
To manage WordPress Plugins, check How to Install WordPress Plugins: 2 Easy Steps.
Server Compatibility: Prioritize confirming that your server environment aligns with the essential prerequisites for running WordPress smoothly, alongside the selected PHP version. Refer to the official WordPress documentation to obtain precise insights into the specific requirements that need to be met.
Step 1: Remove and Reinstall PHP-FastCGI
First of all, you need to remove some of the PHP services by running the following code:
sudo apt-get remove php5-cli php5-cgi php5-fpm
Once you remove these services, reinstall them by running the following install command:
sudo apt-get install php5-cli php5-cgi php5-fpm
Step 2: Remove and Reinstall NGINX Web Server
In this step, remove and reinstall the NGINX Server by running:
sudo apt-get remove nginx # Removes all but config files.
sudo apt-get purge nginx # Removes everything.
Once using both of the above commands, run:
sudo apt-get autoremove
This will remove all the dependencies used by NGINX that are no longer required.
Now, reinstall the NGINX server:
sudo apt-get install nginx
Step 3: Configure Nginx
Now, configure NGINX for your websites. If you are hosting more than one website on a single server, create a separate config file for each of your websites.
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example1.com
Similarly, create another configuration file for another website and repeat this step for all the other websites.
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example2.com
Now, open each configuration file one by one, search for the following configuration and update them:
Configuration for example1.com
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/example1.com/public_html; index index.php; Make site accessible from http://localhost/ server_name example1.com www.example1.com *.example1.com; location / { First attempt to serve request as file, then as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.php; Uncomment to enable naxsi on this location include /etc/nginx/naxsi.rules } location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
Configuration for example2.com
server { listen 80; listen [::]:80; root /var/www/example2.com/public_html; index index.php; Make site accessible from http://localhost/ server_name example2.com www.example2.com *.example2.com; location / { First attempt to serve request as file, then as directory, then fall back to displaying a 404. try_files $uri $uri/ /index.php; Uncomment to enable naxsi on this location include /etc/nginx/naxsi.rules } location ~ .php$ { fastcgi_split_path_info ^(.+.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
Once you complete the configuration of each of your websites, you need to move these files from the sites-available to the sites-enabled directory. Do this for each of the config files you have just created by running the following command:
For website1.com
sudo ln -s /etc/nginx/sites-available/website1.com /etc/nginx/sites-enabled/
For website2.com
sudo ln -s /etc/nginx/sites-available/website2.com /etc/nginx/sites-enabled/
Then, remove the default NGINX configuration file from the sites-enabled directory by running the following command:
sudo rm /etc/nginx/sites-enabled/default
Now, restart NGINX and PHP5-fpm:
service php5-fpm restart
/etc/init.d/nginx restart
Step 4: Install MySQL Server & Packages
Run the following command to install the MySQL server and the packages required for the database to support PHP (You do not need to purge the MySQL Server):
sudo apt-get install mysql-server php5-mysql
Finally, restart php5-fpm:
service php5-fpm restart
That’s it! It should solve the issue.
If you’re using a web hosting service, they might have specific configurations or limitations in place. Contact your hosting provider’s support if you’re unsure about enabling the MySQL extension.
Other Error Fixes
- Error Establishing a Database Connection in WordPress Fix
- 4 Simple Ways to Fix 502 Bad Gateway Nginx Error in Ubuntu
- 5 Simple Steps to Fix 504 Gateway Timeout Nginx Error
- PHP5-FPM 502 Bad Gateway Error (connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory)
I would also advise you to set up and keep an eye on error reporting for PHP and NGINX. This will help you understand the issue more accurately.
Wrap Up
Incorporating these steps and insights should pave the way for resolving the issue at hand—tackling the “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”
By adhering to best practices, verifying server compatibility, seeking hosting provider guidance, and staying current with updates, you’re well-equipped to reinstate full functionality in your WordPress environment.
Remember that addressing such challenges systematically not only resolves the immediate concern but also contributes to an optimized and secure WordPress experience.
Should you encounter any further questions or obstacles, feel free to seek additional support.