要安装php7
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm sudo yum install php70w php70w-common
现在用php -v来检查它。
PHP 7.0.19 (cli) (built: May 12 2017 21:01:27) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.19, Copyright (c) 1999-2017, by Zend Technologies
安装nginx
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm sudo yum install nginx sudo systemctl start nginx sudo systemctl enable nginx.service
在/ usr / share / nginx / html中使用vim info.php。
<?php phpinfo(); ?>
要inputvps_ip/info.php ,我得到如下。
为什么函数phpinfo()不能执行?
这是我的nginxconfiguration文件。
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; 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 { } }
在这里input图像说明
你想要的是安装php-fpm并让nginx使用它来处理php。 坏的问题,不好的答案:阅读文档。 或者至less找一个好的LEMP堆栈如何这样: https : //www.howtoforge.com/tutorial/install-nginx-with-php-and-mysql-lemp-stack-on-centos/
Nginx是一个Web服务器,而不是一个应用服务器。 你需要一些你需要一些应用服务器来解释你的php / ruby / python代码。
安装php-fpm ,在你的情况下:
yum install php70w-fpm
并添加到您的服务器configuration如下:
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 fastcgi_params; }
这确保所有以*.php结尾的*.php都将由php-fpm (FastCGI Process Manager for PHP)处理。 在这种情况下,在UNIX套接字上侦听。
确保将/etc/php-fpm.d/www.confconfiguration为在套接字上侦听:
;listen = 127.0.0.1:9000 listen = /var/run/php-fpm/php-fpm.sock
或者只是在nginx服务器configuration中使用TCP端口:
fastcgi_pass 127.0.0.1:9000;
最后重启nginx和php-fpm :
systemctl restart php-fpm.service systemctl restart nginx.service