Linux WordPress can’t not write wp-config file

I installed the latest version of Apache2 / PHP / MYSQL on my pc

In the directory /srv/www/htdocs I created a directory wordpress with all wordpress file.

Read More

Then, when I tried to create the wp-config file through the web interface I get this error :

Sorry, but i can't write the wp-config file.

I tried this command to change the group of /src/www/htdocs/wordpress

chown -R root:root /srv/www/htdocs/wordpress

But it was not working. After some research, i seen lot of people saying to change the group to www-data but i do not see www-data using this commande :

cut -d: -f1 /etc/group

Anyone know what I am doing wrong ?

enter image description here
enter image description here

Sorry about my poor english.

Related posts

Leave a Reply

5 comments

  1. This is what worked for me. (I’m a beginner and I’m using Debian 8)

    First I checked the Apache config file to find the group that apache uses. In my case it was www-data.
    grep ^Group /etc/apache2/httpd.conf

    I checked my /etc/group file and the group www-data was there.

    Then I changed the group ownership of my wordpress directory from root to www-data.

    chown -R root:www-data /var/www/html/wordpress
    

    I changed the permissions of my wordpress folder to 755 for directories and 644 for files, following the recommendations of other sites.

    find /var/www/html/wordpress -type d -exec chmod 755 {} ;
    find /var/www/html/wordpress -type f -exec chmod 644 {} ;
    

    But since we want to give write permissions to the group www-admin for the wordpress folder and subfolders, I changed the permissions for directories to 775:

    find /var/www/html/wordpress -type d -exec chmod 775 {} ;
    

    Then it worked: All right, sparky! You’ve made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to…

    Notes: The username and password of my myssql database was root/root. The username I was using to login to my computer was root and the password was something different than root. Just in case I changed my password to root, so the credentials of mysql and my local account are the same. I don’t know if by having the same name (root) they are the same account.

  2. Sounds like www-data is not the group name used by apache on your system. To find what it actually uses, try the following:

    ps xO gid | head -n 1; ps xO gid | grep httpd
    

    (That’s a capital O, not a zero). The column GID (probably the second column) is the numeric group ID that apache is running under. Look up its name in /etc/group.

  3. unable to write to wp-config.php file.

    I had this problem in my ubuntu 20.04, WordPress 5.x. I solved this issue with these steps:

    • First, change the group ownership of the WordPress directory from root to www-data.
    sudo chown -R root:www-data /var/www/html/wordpress
    
    • Then change your WordPress folders permission by this command.
    sudo find /var/www/html/wordpress -type d -exec chmod 755 {} ;
    
    • Then change your WordPress files permission by this command.
    sudo find /var/www/html/wordpress -type f -exec chmod 644 {} ;
    
    • Run the installation again.
  4. Even though I implemented CHOWN & CHMOD steps, but the issue was still persisting, then I found another scenario where this/same error could occur because of SELINUX CONTEXT issue (lack of write permission context).

    To solve that – You can change Apache/HTTPD write context with in the web-content folder like this (Specific to the Debian environment, as mentioned in this question):

    chcon -R -t httpd_sys_rw_content_t  /src/www/htdocs
    

    OR (on CentOS/Fedora):

    chcon -R -t httpd_sys_rw_content_t  /var/www/html
    

    You can validate the output like this (on CentOS/Fedora):

    # pwd
    # /var/www
    

    Notice the output of below command having changed RW (Read/Write) context on html (web-content) folder:

    # ls -ltrZ
    # drwxrwxr-x. 2 apache apache system_u:object_r:httpd_sys_script_exec_t:s0 4096 Jul  9 20:45 cgi-bin
    # drwxrwxr-x. 5 apache apache system_u:object_r:httpd_sys_rw_content_t:s0  4096 Jul 14 19:28 html
    

    NOTE: Do validate the Path, Web Server User-Names, and SELINUX write-context as per your environment before executing above commands.