Wordpress Access in Nginx and Permission denied

6,258

Your file permissions will be incorrect with respect to the user Nginx is running as. You haven't given us enough information to help, like who nginx runs as ( ps -u | grep nginx ) or where things are stored.

I have a tutorial that should help, here. Key parts are

useradd tim   (NB: you can name the user something else if you like!)
passwd tim    (NB: give them a secure password, but you'll never need to use it)
groupadd www-data
usermod -a -G www-data nginx   (add the nginx user to the www-data group)
chown -R tim /usr/share/nginx/
chgrp -R www-data /usr/share/nginx/
chmod -R 750 /usr/share/nginx/
chmod -R g+s /usr/share/nginx/

This is based on the Wordpress permissions documentation.

Share:
6,258

Related videos on Youtube

Muammad
Author by

Muammad

Updated on September 18, 2022

Comments

  • Muammad
    Muammad almost 2 years

    I have been trying to get wordpress work with nginx its new task for me but I am almost done.
    But I am still at the end can't get wordpress to work I have tried everything I was able to get and the same issue exactly and the solution approved, but didn't work for me.

    017/01/28 10:54:22 [crit] 3576#3576: *65 stat() "/home/wptask/public_html/wp-admin/install.php" failed (13: Permission denied), client: 127.0.0.1, server: firtswebsite.com, request: "GET /wp-admin/install.php HTTP/1.1", host: "127.0.0.1"
    2017/01/28 10:53:36 [crit] 3576#3576: *1 stat() "/home/wptask/public_html/wp-admin/install.php" failed (13: Permission denied), client: 192.168.10.1, server: firtswebsite.com, request: "GET /wp-admin/install.php HTTP/1.1", host: "192.168.10.10"
    

    I did this

    chmod +x /home
    chmod +x /home/wptask
    chmod +x /home/wptask/public_html 
    sudo chown -R wptask:wptask /home/wptask
    chmod go-rwx /home/wptask
    chmod go+x /home/wptask
    chgrp -R wptask /home/wptask
    chmod -R go-rwx /home/wptask
    chmod -R g+rx /home/wptask
    chmod -R g+rwx /home/wptask
    

    and even chmod 755 /home/wptask

    but non works for me

    Update :- ls -l for the webroot

    [root@web-srv ~]# ls -l /home/wptask/
    drwxr-sr-x. 2 root root   41 Jan 30 07:01 logs
    drwxr-sr-x. 5 root root 4096 Jan 28 08:41 public_html
    

    nginx.conf

        user  nginx;
        worker_processes  1;
    
        error_log  /var/log/nginx/error.log warn;
    
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
        access_log  /var/log/nginx/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    
        include /etc/nginx/sites-enabled/*;
        include /etc/nginx/conf.d/*.conf;
    }
    

    Fix Update :-

    ls -l webroot

    [root@web-srv ~]# ls -l /home/wptask/
    total 4
    drwxr-s---. 2 wptask wptask   41 Jan 30 07:01 logs
    drwxr-s---. 5 wptask wptask 4096 Jan 28 08:41 public_html
    

    and i changed the nginx user in nginx.conf

  • Muammad
    Muammad over 7 years
    Thank you Tim, the problem solved , only after do 777 for each path , i am sure something is wrong with me and i know where is it, thanks for your helpful link and advice :)
  • Tim
    Tim over 7 years
    777 "anyone can do anything" is not a solution, it's opening up the file permissions so wide any process or user can do anything. I encourage to keep looking at the problem.
  • Muammad
    Muammad over 7 years
    It works only with 755. i have tested it with less with no luck.
  • Tim
    Tim over 7 years
    Your file ownership is incorrect with respect to your web server user. You haven't given the requested information so I can't help further.
  • Muammad
    Muammad over 7 years
    here is the output: [root@web-srv ~]# ps -u | grep nginx root 4054 0.0 0.0 112648 960 pts/0 S+ 06:29 0:00 grep --color=auto nginx
  • Tim
    Tim over 7 years
    You really need to read a good tutorial and documentation on this. Change the Nginx user to something other than root, then you need to ensure that user has appropriate access to the webroot).
  • Tim
    Tim over 7 years
    The user your nginx runs as is in your nginx.conf, see the user directive. Perhaps you could edit your question to include the nginx.conf and and ls -l of your webroot