简体   繁体   中英

How to check the nginx run the same version of php version on Ubuntu?

I just install PHP on the Ubuntu server in the Digitalocean and create a simple PHP file just for testing called phpinfo.php and the contains is:

<?php phpinfo();

When I visit the file I got this error:

I got this error: 502 Bad Gateway nginx/1.18.0 (Ubuntu)

I check the errors in nginx's error log and got this one:

2020/10/01 00:16:26 [crit] 23593#23593: *15 connect() to unix:/var/run/php/php7.2-fpm.sock failed (2: No such file or directory)
while connecting to upstream, client: 212.###.###.182, server: 46.#####.106, request: "GET /info.php HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/php/php7.2-fpm.sock:", host: "46..###.###106"

check php version is :

PHP 7.4.10 (cli) (built: Sep  9 2020 06:36:30) ( NTS )

What is the problem ?

how can I check if Nginx using the same version of PHP 7.4

You have to check php7.*-fpm.sock if it's 4 or 2

First, run this command

sudo vim /etc/nginx/sites-available/YOUR.DOMAIN.COM

you will get something like this:

server {
    listen 80;
    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;
    server_name XXXXXXXXXX;

    location / {
            try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }

    location ~ /\.ht {
            deny all;
    }
}

Change the version of PHP to 7.4

fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

Save file

Then restart Nginx:

sudo service nginx restart

Now visit your app with the name of the file and you will get the PHP page version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM