Get the most out of your Centmin Mod LEMP stack
Become a Member

Nginx Ownership issues with WordPress

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by jcat, Mar 9, 2016.

  1. jcat

    jcat Member

    51
    13
    8
    Jun 21, 2015
    Ratings:
    +20
    Local Time:
    1:38 AM
    We are seeing this issue more and more where people are complaining they are unable to update plugins. Easily fixed by recursively changing the domains user ownership to nginx but I am thinking its because wp-cli is ran as root so anytime something is updated via wp-cli the ownership of the files are changed to root. I just been creating a cronjob to chown the files every hour but was wondering if there was a better approach to this to avoid running a cronjob.

    Doing something like

    runuser -l nginx -c '/usr/bin/wp plugin update --all'

    instead of

    /usr/bin/wp plugin update --all --allow-root

    Obviously its not going to work since shell is set to /sbin/nologin for the user nginx but maybe you had some other ideas?
     
  2. eva2000

    eva2000 Administrator Staff Member

    28,968
    6,575
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,758
    Local Time:
    3:38 PM
    Nginx 1.13.x
    MariaDB 5.5
    Who's complaining ? doing the updating ? Centmin mod lemp stack is not made for shared hosting - FAQ item 2.

    So you should not have any issues with wordpress plugin updates if you do plugin updates via wp-admin update (if wp plugin was installed via wp-admin plugin -> add new) or if updated via wp-cli as root user. Pure-ftpd virtual ftp user also uploads as nginx user Pure-FTPD Virtual FTP Users - CentminMod.com LEMP Nginx web stack for CentOS so there shouldn't be any problems there either.

    I haven't had any issues updating WP plugins via wp-admin or via wp-cli on my Wordpress7 site. For example AMP WP plugin installed via wp-admin -> add new plugin installs wp plugin files as nginx user/group

    Code:
    ls -lahR wp-content/plugins/amp
    wp-content/plugins/amp:
    total 1.6M
    drwxr-xr-x  6 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-sr-x 38 nginx nginx 4.0K Mar  8 15:45 ..
    -rw-r--r--  1 nginx nginx 2.5K Mar  5 05:14 amp.php
    drwxr-xr-x  3 nginx nginx 4.0K Mar  5 05:14 assets
    drwxr-xr-x  6 nginx nginx 4.0K Mar  5 05:14 includes
    -rw-r--r--  1 nginx nginx 2.2K Mar  5 05:14 jetpack-helper.php
    drwxr-xr-x  2 nginx nginx 4.0K Mar  5 05:14 languages
    -rw-r--r--  1 nginx nginx  18K Mar  5 05:14 LICENSE
    -rw-r--r--  1 nginx nginx  21K Mar  5 05:14 readme.md
    -rw-r--r--  1 nginx nginx 4.4K Mar  5 05:14 readme.txt
    -rw-r--r--  1 nginx nginx 284K Mar  5 05:14 screenshot-1.png
    -rw-r--r--  1 nginx nginx 365K Mar  5 05:14 screenshot-2.png
    -rw-r--r--  1 nginx nginx 349K Mar  5 05:14 screenshot-3.png
    -rw-r--r--  1 nginx nginx 157K Mar  5 05:14 screenshot-4.png
    -rw-r--r--  1 nginx nginx 314K Mar  5 05:14 screenshot-5.png
    drwxr-xr-x  2 nginx nginx 4.0K Mar  5 05:14 templates
    
    wp-content/plugins/amp/assets:
    total 12K
    drwxr-xr-x 3 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 images
    
    wp-content/plugins/amp/assets/images:
    total 12K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 3 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx  866 Mar  5 05:14 placeholder-icon.png
    
    wp-content/plugins/amp/includes:
    total 52K
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx  379 Mar  5 05:14 amp-frontend-actions.php
    -rw-r--r-- 1 nginx nginx 1.1K Mar  5 05:14 amp-helper-functions.php
    -rw-r--r-- 1 nginx nginx 3.7K Mar  5 05:14 amp-post-template-actions.php
    -rw-r--r-- 1 nginx nginx 2.8K Mar  5 05:14 class-amp-content.php
    -rw-r--r-- 1 nginx nginx 8.6K Mar  5 05:14 class-amp-post-template.php
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 embeds
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 lib
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 sanitizers
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 utils
    
    wp-content/plugins/amp/includes/embeds:
    total 36K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx  591 Mar  5 05:14 class-amp-base-embed-handler.php
    -rw-r--r-- 1 nginx nginx 1.4K Mar  5 05:14 class-amp-facebook-embed.php
    -rw-r--r-- 1 nginx nginx 3.2K Mar  5 05:14 class-amp-gallery-embed.php
    -rw-r--r-- 1 nginx nginx 2.4K Mar  5 05:14 class-amp-instagram-embed.php
    -rw-r--r-- 1 nginx nginx 1.8K Mar  5 05:14 class-amp-twitter-embed.php
    -rw-r--r-- 1 nginx nginx 1.5K Mar  5 05:14 class-amp-vine-embed.php
    -rw-r--r-- 1 nginx nginx 2.8K Mar  5 05:14 class-amp-youtube-embed.php
    
    wp-content/plugins/amp/includes/lib:
    total 12K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx 4.0K Mar  5 05:14 class-fastimage.php
    
    wp-content/plugins/amp/includes/sanitizers:
    total 32K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx 1.9K Mar  5 05:14 class-amp-audio-sanitizer.php
    -rw-r--r-- 1 nginx nginx 1.6K Mar  5 05:14 class-amp-base-sanitizer.php
    -rw-r--r-- 1 nginx nginx 4.0K Mar  5 05:14 class-amp-blacklist-sanitizer.php
    -rw-r--r-- 1 nginx nginx 3.4K Mar  5 05:14 class-amp-iframe-sanitizer.php
    -rw-r--r-- 1 nginx nginx 2.9K Mar  5 05:14 class-amp-img-sanitizer.php
    -rw-r--r-- 1 nginx nginx 1.9K Mar  5 05:14 class-amp-video-sanitizer.php
    
    wp-content/plugins/amp/includes/utils:
    total 20K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx 1.8K Mar  5 05:14 class-amp-dom-utils.php
    -rw-r--r-- 1 nginx nginx  637 Mar  5 05:14 class-amp-html-utils.php
    -rw-r--r-- 1 nginx nginx 3.2K Mar  5 05:14 class-amp-image-dimension-extractor.php
    
    wp-content/plugins/amp/languages:
    total 8.0K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    
    wp-content/plugins/amp/templates:
    total 32K
    drwxr-xr-x 2 nginx nginx 4.0K Mar  5 05:14 .
    drwxr-xr-x 6 nginx nginx 4.0K Mar  5 05:14 ..
    -rw-r--r-- 1 nginx nginx  409 Mar  5 05:14 meta-author.php
    -rw-r--r-- 1 nginx nginx  569 Mar  5 05:14 meta-taxonomy.php
    -rw-r--r-- 1 nginx nginx  323 Mar  5 05:14 meta-time.php
    -rw-r--r-- 1 nginx nginx 1.3K Mar  5 05:14 single.php
    -rw-r--r-- 1 nginx nginx 5.6K Mar  5 05:14 style.php
    I can only imagine the problem would occur if you are uploading wp plugin files using a ftp account other than root or the pure-ftpd virtual ftp user generated by Centmin Mod's nginx vhost creation routine at Nginx Vhost & NSD DNS Setup - CentminMod.com LEMP Nginx web stack for CentOS ?
     
  3. eva2000

    eva2000 Administrator Staff Member

    28,968
    6,575
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,758
    Local Time:
    3:38 PM
    Nginx 1.13.x
    MariaDB 5.5
    Btw, do you have the wp-updater-domain.com.sh cron running ?

    if you do, you can add this line to the updater (i'll update centmin mod 123.09beta01 with this too) - of course changing path to your nginx vhost domain's web root
    Code (Text):
    chown -R nginx:nginx /home/nginx/domains/testdomain.com/public

    i.e. for testdomain.com wp updater /root/tools/wp_updater_testdomain.com.sh
    Code (Text):
    #!/bin/bash
    PATH=/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
    EMAIL=myemail@testdomain.com
    
    {
    cd /home/nginx/domains/testdomain.com/public
    echo "/home/nginx/domains/testdomain.com/public"
    #/usr/bin/wp cli update --allow-root
    echo "update wp-cli"
    rm -rf /usr/bin/wp
    wget -cnv --no-check-certificate https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -O /usr/bin/wp --tries=3
    chmod 0700 /usr/bin/wp
    /usr/bin/wp --info --allow-root
    /usr/bin/wp plugin status --allow-root
    /usr/bin/wp plugin update --all --allow-root
    #/usr/bin/wp core check-update --allow-root
    #/usr/bin/wp core update --allow-root
    #/usr/bin/wp core update-db --allow-root
    chown -R nginx:nginx /home/nginx/domains/testdomain.com/public
    /usr/bin/nprestart
    } 2>&1 | /usr/bin/tr -cd '\11\12\15\40-\176' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" | dos2unix | mail -r $EMAIL -s "Wordpress WP-CLI Auto Update $(date)" $EMAIL
     
    Last edited: Mar 9, 2016
    • Like Like x 1
  4. jcat

    jcat Member

    51
    13
    8
    Jun 21, 2015
    Ratings:
    +20
    Local Time:
    1:38 AM
    wp-updater-domain.com.sh
    is running yeah, that would be perfect in terms of adding chown to that file automatically. No need to take this post any further if that will be implemented, that ultimately satisfies what I was looking for :)

    Appreciate it!
     
    • Like Like x 1