当输入以下命令的时候没有问题的时候就可以部署PHP测试页面了。
[root@localhost ~]# php -v
PHP 7.3.27 (cli) (built: Apr 1 2021 22:04:00) ( ZTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies
[root@localhost ~]# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
yaf
zip
zlib
[Zend Modules]
安装Nginx
[root@localhost ~]# yum -y install nginx
启动Nginx
[root@localhost ~]# systemctl start nginx
编辑Nginx配置文件
[root@localhost conf.d]# pwd
/etc/nginx/conf.d
[root@localhost conf.d]# ls
php.conf
[root@localhost conf.d]# vim php.conf
server {
listen 80;
# 这里改动了,也可以写你的域名
server_name 10.0.10.250;
# 默认网站根目录(www目录)
root /var/www/;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
# 这里改动了 定义首页索引文件的名称
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# 这里新加的
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI协议默认配置.
# Fastcgi服务器和程序(PHP,Python)沟通的协议.
location ~ \.php$ {
# 设置监听端口
fastcgi_pass 127.0.0.1:9000;
# 设置nginx的默认首页文件(上面已经设置过了,可以删除)
fastcgi_index index.php;
# 设置脚本文件请求的路径
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# 引入fastcgi的配置文件
include fastcgi_params;
}
}
[root@localhost conf.d]# nginx -t ##检测配置文件是否有问题
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost conf.d]# nginx -s reload ##重新加载配置文件
编辑php测试文件
[root@localhost www]# pwd
/var/www ##目录没有就创建
[root@localhost www]# ls
index.php
[root@localhost www]# cat index.php
<?php
phpinfo()
?>
浏览器测试