Home » Fix system files not writeable in wordpress

Fix system files not writeable in wordpress

How to make system files (.htaccess, wp config) and/or folders writable?

I faced this problem recently. WP rocket was unable to write to system files and there were three notices flashing on my WordPress dashboard in red. I have been using WP rocket for past several years and this was the first time I faced this issue. So, I researched online for help and found some articles that suggested changing permissions using FTP. They need to be 755 for folders and 644 for files. When I checked the file and folder permissions inside the root folder, they were right. For example .htaccess permission was set to 644 and wp-content folder permission set to 755. WP rocket also needs to write to wp-content/cache and it was unable to. It meant the issue was not related to just permissions and there was something else to it.

I remembered I had newly installed some modules on my apache server (easy apache 2.4) and made some other changes. When changing permissions did not work, I tried to revert those changes but it did not resolve the problem either. So, I tried restarting services including http server (apache) and PHP FPM service. However, the problem did not go. I have two blogs hosted on the same server and both were showing similar warnings. The plugins in question included WP Rocket and cache enabler. I tried deleting cache enabler from one of the blogs but I was unable to since wordpress asked for FTP credentials. Upon providing the credentials, it deleted the plugin but the final problem was still unresolved and the same warning was there on the site health panel on wp admin dashboard. When I tried installing new plugins, they showed similar warnings and one even triggered a fatal error. The site health dashboard suggested contacting the hosting provider.

An important thing I wanted to mention before discussing the resolution is that no directory should be given 777 permission. While researching online for a solution, I found that some users had tried setting this permission level to resolve the issue. A wordpress article expressly prohibits it. I have given the link below:

Changing file permissions

I decided to read the full article about ownership and permissions before contacting my host. The site was running fine at the front end and so I was in no hurry to fix it.

The article lists some popular methods that sysadmins use to setup permissions and ownership. The modules and extensions used for this purpose included mpm-itk, mod fcgid and PHP FPM. I had tried restarting PHP FPM service for apache already but it did not work. However, I decided to check the php version before contacting my hosting provider as a last resort. I logged into cpanel for one of the blogs and checked the multiphp manager where I had set the php version to 8.1 a few days ago. I noticed a change there. The PHP FPM beside the php version was showing as disabled. I remembered that when I had updated my php version to the latest a few days ago, there were green tick marks meaning PHP FPM is enabled. Those green tick marks were replaced by a red sign now. It meant that I needed to enable PHP FPM again. This was something that appeared related to the problem.

To check if PHP FPM is enabled, you can log into WHM as root user and check out the MultiPHP manager under the software section. When I checked, the PHP FPM was enabled there. I had also tried restarting apache server (httpd), which had not worked.  I wondered why PHP FPM was not enabled in the domain cpanel’s multi php manager when it was enabled in WHM. I have three blogs on the same server, two of them new.

Finally, the resolution…

WHM => SOFTWARE => MultiPHP Manager

Inside the Multiphp manager (in the WHM), under the system settings, I clicked on ‘enable PHP FPM on all domains.’ (you can enable it for individual domains if you have more than one hosted on the same server.) Then, I returned to the cpanel account for one of my domains. Inside the cpanel’s multiphp manager, I saw that the signs beside PHP FPM had turned to green again. So, I checked the wordpress blog. The warnings were gone from both blogs. There was no warning from WP rocket or any other plugin. The critical warning in site health section was also gone. The site was functioning as normal and so were the plugins.

Once you are inside the WHM, go to Software and check under the system settings for PHP FPM. If it is showing as enabled but disabled inside your domain’s cpanel section, you know you will need to reset it. If it is disabled, you can just enable it. As already mentioned, the sysadmins use PHP FPM for setting ownerships and permissions. I read it in the wordpress article I have provided the link for in the article and that’s how I got the hint. I had researched online for several hours since I was hesitant to contact my hosting provider initially. While this solution must work, if you ever face the same issue which can arise due to different reasons, you must contact your hosting provider in case you do not like to touch the settings yourself. The changes I mentioned above can also be made from SSH. However, in the case of WordPress users who do not use SSH, the easier method is detailed above. Inside the WHM’s multiphp manager, you will also find the settings to change your PHP handler right below where you enable the PHP FPM. Apart from that, you can set PHP FPM Pool options for individual domains from there.

I also came across a 2017 article which mentions

“By running the FastCGI server (i.e. the PHP-FPM daemon) as your own user, or running it via the root user and configuring your www.conf file to run processes as your own user, most of your permissions problems will evaporate.”

You can read the article here. Note: PHP-FPM stands for PHP FastCGI Process Management. PHP-FPM is PHP’s FastCGI server.
Thanks All. Happy Blogging!