3

I have a CentOS 7 machine with Nginx running and the user is "nginx" (tghe default one in CentOS). I've installed Wordpress, which is working perfectly, and I've give wrtite permissions for nginx user in the wordpress folder and subfolders (775), but a still get a permission error:

Unable to create directory wp-content/uploads/2015/05

I double checked which user is running nginx worker processes and it is nginx.

It must be something trivial that I missed. Can someone help me?

EDIT:

I noticed this in /var/log/nginx/error.log:

2015/05/03 20:42:41 [error] 23652#0: *1 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/html/index.php (No such file or directory)" while reading response header from upstream, client: XXX.XXX.XXX.A, server: XXX.XXX.XXX.B, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "XXX.XXX.XXX.B"

2015/05/03 20:44:18 [error] 23652#0: *3 FastCGI sent in stderr: "Unable to open primary script: /usr/share/nginx/html/wp-admin/admin-ajax.php (No such file or directory)" while reading response header from upstream, client: XXX.XXX.XXX.A, server: XXX.XXX.XXX.B, request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "XXX.XXX.XXX.B", referrer: "http://XXX.XXX.XXX.B/wp-admin/"

2015/05/03 21:02:54 [emerg] 23803#0: getpwnam("http") failed in /etc/nginx/nginx.conf:6

EDIT 2

$ ps -elf|grep nginx
1 S root      2045     1  0  80   0 - 27393 sigsus 15:46 ?        00:00:00 nginx: master process /usr/sbin/nginx
5 S nginx     2049  2045  0  80   0 - 27503 ep_pol 15:46 ?        00:00:00 nginx: worker process
5 S nginx     2050  2045  0  80   0 - 27503 ep_pol 15:46 ?        00:00:00 nginx: worker process
5 S nginx     2051  2045  0  80   0 - 27503 ep_pol 15:46 ?        00:00:00 nginx: worker process
5 S nginx     2052  2045  0  80   0 - 27503 ep_pol 15:46 ?        00:00:00 nginx: worker process

The server configuration file is:

server {
    listen       80;
    server_name  XXX.XXX.XXX.B;

    location / {
        root   /var/www/wordpress;
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    error_page 404 /404.html;
    location = /404.html {
        root /usr/share/nginx/html;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        root /var/www/wordpress;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

As for the nginx configuration file:

user  nginx;
worker_processes  4;

error_log  /var/log/nginx/error.log;

pid        /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;

    keepalive_timeout  65;

    index   index.html index.htm;

    include /etc/nginx/conf.d/*.conf;

    server {
    listen       80 default_server;
    server_name  localhost;
    root         /usr/share/nginx/html;

    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page  404              /404.html;
    location = /40x.html {
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
    }
    }
}
4
  • 1
    Did you check SELinux?
    – masegaloeh
    May 4, 2015 at 14:03
  • Well, I checked the logs, nothing that I could tell. May 4, 2015 at 14:10
  • Please post the nginx configuration...
    – masegaloeh
    May 4, 2015 at 14:25
  • You say that you are using the 'nginx' user, but your logs suggest that it is the user named 'http' that it is trying to run as. May 4, 2015 at 14:30

1 Answer 1

4

It isn't the user nginx is running as that is important, but it is the user php-fpm is running as. After all, it is PHP-FPM that executes the PHP scripts, and WordPress is running under privileges that the PHP-FPM running user has.

So, check that your upload directory can be written by the user running PHP-FPM.

3
  • 1
    I checked the configuration file of PHP-FPM and it was set to apache. I corrected it setting the user and group to nginx and still got the same error message. May 5, 2015 at 15:00
  • 1
    The owner of the configuration file does not matter. You have to check which is the user that is used to run the PHP-FPM process, and make sure that the particular user can write to the directory. May 5, 2015 at 15:13
  • 1
    This was the solution, but because of previous changes I did, I do not noticed untill I undid them. Thank you. May 5, 2015 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.