• I’ve been at this for days. I can’t figure out why when i go to my ip for wordpress it downloads the .php, but it works fine when i put in my_ip/phpMyAdmin. I’m not sure what I’m doing wrong or if I configured something wrong. I know i’ve setup /etc/php.ini and /etc/php-fpm.d/www.conf correctly like most sites recommend and ive tried every solution. most solutions have you modifying the .htaccess file but nginx does not use .htaccess. all permissions and ownership are correct unless im missing something…if anyone can help me out, I can finally leave this room.

    nginx.conf

    # Generic startup file.
    user nginx nginx;
    
    #usually equal to number of CPUs you have. run command "grep processor /proc/cpuinfo | wc -l" to find it
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log;
    pid        /var/run/nginx.pid;
    
    # Keeps the logs free of messages about not being able to bind().
    # daemon     off;
    
    events {
            worker_connections  1024;
    }
    
    http {
    #       rewrite_log on;
    
            include mime.types;
            default_type       application/octet-stream;
            access_log         /var/log/nginx/access.log;
            sendfile           on;
    #       tcp_nopush         on;
            keepalive_timeout  3;
    #       tcp_nodelay        on;
    #       gzip               on;
            #php max upload limit cannot be larger than this
            client_max_body_size 64m;
            index              index.php index.html index.htm;
    
            # Upstream to abstract backend connection(s) for PHP.
            upstream php {
                    #this should match value of "listen" directive in php-fpm pool
                    server unix:/var/run/php-fpm/php-fpm.sock;
    #               server 127.0.0.1:9000;
            }
    
    #       include sites-enabled/*;
            include /etc/nginx/conf.d/*.conf;
    }

    phpmyadmin.conf (works)

    server {
        listen       80;
        server_name  192.168.1.215;
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
    
            location /db-sector {
                    auth_basic "Admin Login";
                    auth_basic_user_file /etc/nginx/pma_pass;
    
                    location ~ \.php$ {
                            try_files $uri =404;
                            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                            fastcgi_index index.php;
                            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                            include /etc/nginx/fastcgi_params;
                    }
            }
    }

    wordpress.conf (doesn’t work, downloads index.php)

    server {
        listen       80;
        server_name  192.168.1.215;
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
    
            location / {
                    try_files $uri $uri/ /index.php?$args;
    
                    location ~ \.php$ {
                            try_files $uri =404;
                            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                            fastcgi_index index.php;
                            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                            include /etc/nginx/fastcgi_params;
                    }
            }
            location ~ /\. {
                    deny all;
                    access_log off;
                    log_not_found off;
            }
    }

    if you need any specifics let me know.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ASione

    (@asione)

    Well i figured out how to get both phpmyadmin and wordpress to work by putting them in one conf file. so wordpress no longer downloads, but executes the php files. but if I split the wordpress location block and move it to a new conf file with a similar server block the wordpress site starts to download index.php again. unless im messing up on configuration when it comes to two server blocks im not sure what im doing wrong.

    2in1.conf

    server {
        listen 80;
        server_name 192.168.1.215;
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
    
        location /db-sector {
            auth_basic "Admin Login";
            auth_basic_user_file /etc/nginx/pma_pass;
    
            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
            }
        }
        location / {
            try_files $uri $uri/ /index.php;
                location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include /etc/nginx/fastcgi_params;
                }
        }
    }

    but I still can’t figure out how to split both into two separate conf files.
    here is what the conf files look like when in separate conf files.

    phpmyadmin.conf

    server {
        listen 80;
        server_name 192.168.1.215;
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
    
        location /db-sector {
            auth_basic "Admin Login";
            auth_basic_user_file /etc/nginx/pma_pass;
    
            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
            }
        }
    }

    wordpress.conf

    server {
        listen 80;
        server_name 192.168.1.215;
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ /index.php;
                location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include /etc/nginx/fastcgi_params;
                }
        }
    }

    Unfortunately splitting the configuration into two conf files does not seem to work and wordpress just downloads the index.php again. I would prefer if both wordpress and phpmyadmin fuctions where in seperate conf files.

    if someone could lead me to a possible solution as to why its not working or what I may be missing to get it to work it would be most appreciated.

    HI there,
    First of all, why are you serving from IP ? you could use like mysite.com and add an entry in your hosts file. That file is checked before dns resolution (both on windows and linux).

    Now about your issue. Why are you trying to bind to the same port under same IP? It is like having two domain based vhost config both with same domain. Either use two ports like 81 for the 2nd and do https://ip:81/ or correct your configuration. ( I think you should do “nginx -t” to check config and it will return error.)

    Your problem is you are using “include …/*.conf;” format and therefore nginx successfully loads the first .conf alphabetically without trouble (and faces issue with binding for the second) and as you have php processing inside the /db-sector directory, php file outside it is not being sent to FPM and you are getting just the file. (my guess)

    Therefore either you change ports / use separate ip if you can / use domain based config / do what you did in your combined config.

    *** In the combined one, you could just take the php-fpm pass location block outside.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress & Nginx (CentOS 7) .PHP downloading instead of executing’ is closed to new replies.