1、安装centos(自行百度安装系统)
2、安装php7
[root@VM_2_240_centos /etc]# yum install php
3、安装php-fpm
[root@VM_2_240_centos /etc]# yum install php-fpm
4、安装nginx(目录:/etc)
[root@VM_2_240_centos /etc]# yum install nginx
- 启动nginx
[root@VM_2_240_centos /etc]# systemctl start nginx
- 浏览器访问查看是否安装成功(地址栏输入你安装的那台机器的ip,成功就会进到一个welcome to nginx界面)
几个需要注意的文件目录:
/etc/nginx:nginx的安装目录,配置文件nginx.conf等文件都在这里面---跟安装时的路径有关,我在/etc下安装的是这样,在usr/下安装就是usr/nginx,如此
/usr/share/nginx/html:网站根目录,这个目录下的文件就是页面执行的具体文件根目录,例如index.html index.php等---这个也是可以配置的,具体的后面讲
- 配置nginx让与php工作
1.打开/etc/nginx/nginx.conf文件,在http模块下server里面添加如下配置:
//location:控制每一层路径的访问
location / { //这里要注意在"{"之前加一个空格
root /usr/share/nginx/html;
index index.html index.htm index.php;
}
location ~\.php$ { //正则匹配
root /usr/share/nginx/html; //网页根目录
fastcgi_pass 127.0.0.1:9000;//导向的ip:port
fastcgi_index index.php; //index文件
//修改文件名为网页根目录,其中$document_root的值就是我们在上面root后面跟的路径(网页根目录)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
/*
**fastcgi_params文件中含有各个nginx常量的定义,
**默认SCRIPT_FILENAME=$fastcgi_script_name,
**不修改就会按照这个变量去找文件
*/
include fastcgi_params;
}
2.检查nginx配置文件语法是否可用,检查OK就重启nginx服务
[root@VM_2_240_centos /etc/nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@VM_2_240_centos /etc/nginx]# nginx -s reload
3.在网站根目录下面新增index.php文件
<?php
echo phpinfo();
?>
4.启动php-fpm
[root@VM_2_240_centos /etc]# systemctl start php-fpm
5.在浏览器地址栏输入127.0.0.1/index.php,网页就显示php的一些信息
相关知识记录:
1.nginx配置文件更详细的介绍,包括对各部分配置项的解释和ngx-http核心模块的配置,两个参考链接里面讲的也是很有用的
https://www.jianshu.com/p/59c6386e1696
2.在安装前如果需要移除之前安装的Apache和PHP来保证不会冲突
yum remve httpd* php*
3.关闭nginx
nginx -s stop
nginx重启关闭等命令https://www.cnblogs.com/apexchu/p/4119252.html
4.nginx+php-fpm运行原理详解
https://blog.csdn.net/u013474436/article/details/52972699
http://www.php.cn/php-weizijiaocheng-395077.html
5.~./php$: 以$为界讲参数划分为两部分,前面的那一部分进行匹配,后面的为第二部分
6.参考资料