PHP 是一种创建动态交互性站点的强有力的服务器端脚本语言。
PHP 是免费的,并且使用非常广泛。
1.更新yum源
[root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2.安装PHP、依赖包
[root@localhost ~]# yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64 php70w-pdo.x86_64 php70w-mysqlnd php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb
3.php相关命令
[root@localhost ~]# systemctl stop php-fpm #停止php
[root@localhost ~]# systemctl start php-fpm #开启php
[root@localhost ~]# systemctl restart php-fpm #重启php
[root@localhost ~]# systemctl status php-fpm #查看php状态
[root@localhost ~]# systemctl enable php-fpm #添加php开机自启动
[root@localhost ~]# php -v #v小写,查看php安装版本
[root@localhost ~]# php -m #查看php拓展
4.配置Nginx解析php
Nginx的配置文件默认位置为: /etc/nginx/nginx.conf
[root@localhost ~]# vim /etc/nginx/nginx.conf #进入nginx配置文件
-------在配置文件中http块中添加一个server----------
server {
listen 80 default_server;
listen [::]:80 default_server;
# 这里改动了,也可以写你的域名
server_name localhost;
root /usr/share/nginx/html;
# 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;
}
}
5.新建测试文件
在Nginx的网站根目录(/usr/share/nginx/html)下创建一个php文件,随便起名我的是phpinfo.php
[root@localhost ~]# cd /usr/share/nginx/html
[root@localhost ~]# vim phpinfo.php
----将以下内容添加进去----
<?php
phpinfo();
?>
----:wq保存退出---------
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# systemctl restart php-fpm
6.浏览器测试
进入浏览器输入你的ip/文件名 例如:192.168.0.104/phpinfo.php