I am getting a "FastCGI sent in stderr: "Unable to open primary script: /var/www/mediawiki/index.php (No such file or directory)"" error when I enter my wiki address in a browser bar. Here is my PHP-FPM www.conf file:

user = nginx
group = nginx
listen = /var/run/php/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
;chroot = 
;chdir = 
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/lib/php/wsdlcache
php_value[opcache.file_cache]  = /var/lib/php/opcache

Here is my nginx conf.d file:

# HTTP requests will be redirected to HTTPS

server {
    listen 80;
    listen [::]:80;
    server_name wiki.example.com;
    return 301 https://$host$request_uri;

# HTTPS Configuration

server {
    listen 443 ssl;
    listen [::]:443;

    server_name wiki.example.com;
    root /var/www/mediawiki;

    index index.php;
    autoindex off;

    # SSL Certification Configuration


    client_max_body_size 5m;
    client_body_timeout 60;

    location / {
    try_files $uri $uri/ @rewrite;

    location @rewrite {
    rewrite ^/(.*)$ /index.php?title=$1&$args;

    location ^~ /maintenance/ {
    return 403;

    #PHP-FPM Configuration NGINX

    location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    try_files $uri /index.php;
    expires max;
    log_not_found off;

location = /_.gif {
    expires max;

location ^~ 
^/(cache|includes|maintenance|languages|serialized|tests|images/deleted)/ {
    deny all;

location ^~ ^/(bin|docs|extensions|includes|maintenance|mw- 
config|resources|serialized|tests)/ {

# Security for 'image' directory
location ~* images/.*.(html|htm|shtml|php)$ {
    allow all;
    types {}
    default_type text/plain;

# Security for 'image' directory
location ^~ /images/ {
    allow all;
    try_files $uri /index.php;


I feel like it is a permissions issue or the php-fpm daemon is looking in a redundant file path or something. I tried passing an absolute path to FPM via the nginx conf.d file by doing:

fastcgi_param SCRIPT_FILENAME /var/www/mediawiki/index.php;

to no avail. So I know I'm pointing it in the right direction but it still gives me the same error which makes me believe I have a permissions issue. I've also tried:

setenforce 0

but this also doesn't work. I've chmod 777 the entire directory up to and including the index.php file.

Some background:

I wanted to install a wikimedia extension which required a new version of php (7.0+) and I was running 5.4 since it came with the base install of CentOS 7. I wasn't familiar with how to update PHP so I accidentally yum remove php*, installed php73 from remi, removed that, re-installed php 5.4, and finally figured out I could yum update with remi-php71.repo enabled to update my base packages. However, I lost my .conf and php.ini files in this process.


/var/log/nginx/error.log when I go to my website in a browser:

2019/01/22 16:58:19 [error] 10876#0: *1 FastCGI sent in stderr: "Unable to 
open primary script: /var/www/mediawiki/index.php (No such file or 
directory)" while reading response header from upstream, client:, server: wiki.example.com, request: "GET / HTTP/1.1", 
upstream: "fastcgi://unix:/var/run/php/php-fpm/php-fpm.sock:", host: 


- 22/Jan/2019:16:58:19 -0700 "GET /index.php" 404 
/var/www/mediawiki/index.php /var/www/mediawiki /index.php /index.php
  • Added nginx error log and php-fpm access log. Thank you! – Jordan Jan 23 '19 at 0:01
  • Just tried it; same exact error in both php-fpm access log and nginx error log. – Jordan Jan 23 '19 at 15:13

I fixed it, thanks to Christopher for pointing me in the right direction with his query about cgi.fix_pathinfo=0 in php.ini.

His specific question did not fix the issue, but I continued to play around with settings near cgi.fix_pathinfo=0 in php.ini and was able to get a different error message with NO error from PHP-FPM complaining about not being able to open /var/www/mediawiki/index.php.

This problem took me a solid 5 days to resolve. I REALLY appreciate the help Christopher!

I ended up commenting the following lines in php.ini:

;user_dir=/var/www/mediawiki    **This is the one that changed the error message

Once I changed that, I got a InvalidArgumentException which was due to me not installing php-mysqlnd when I upgraded from 5.4 > 7.1.

Once I installed that, bam, wiki is back up and running.

I feel like running around the building five times. Thanks again to Christopher for pointing me in the right direction!


| improve this answer | |
  • Yes I was bummed there wasn't more information in the error logs and/or fpm access logs. I already had the logs set to 'debug' -- the highest output verbosity available. Thanks again for your help Christopher. – Jordan Jan 25 '19 at 17:09

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