搭建LNMP首先需要的就是安装必要的服务,我们说的LNMP其实是Linux系统、nginx服务、MySQL数据库、php。首先的就是在Linux上安装这些。我在这里就不说了,关于安装的教程网上有很多博客。
在安装完这些之后,首先需要配置nginx,使其能够支持php。
进入nginx的配置文件
vim /etc/nginx/conf.d/default.conf
进入之后里面有关于php的配置,但是被注释了,把注释去掉并做一些修改
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
这里的root是路径,保存php文件的路径。
接下来进入这个路径。
vim /usr/share/nginx/html/index.hph
<?php echo phpinfo(); ?>
记得要管理防火墙的规则,如果不会使用就直接把防火墙关闭。
接下来在浏览器测试
因为我的IP地址是192.168.137.22, 所以输入http://192.168.137.20/index.php
出现这个就说明环境已经搭建完成了。