CentOS7.2使用yum配置LNMP环境
一,安装系统查看
二,yum安装nginx
设置yum源
1 | rpm - Uvh http: / / nginx.org / packages / centos / 7 / noarch / RPMS / nginx - release - centos - 7 - 0.el7 .ngx.noarch.rpm |
安装nginx
1 | yum - y install nginx |
启动
1 | systemctl start nginx |
修改配置文件/etc/nginx/conf.d/default.conf设置支持php
1 2 3 4 5 6 7 8 | location ~ \.php$ { root / usr / share / nginx / html; fastcgi_pass 127.0 . 0.1 : 9000 ; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } |
三,yum安装MySQL5.7
设置yum源
1 | name: rpm - ivh http: / / repo.mysql.com / mysql57 - community - release - el7 - 8.noarch .rpm |
安装MySQL
1 | yum - y install mysql mysql - server |
启动MySQL
1 | systemctl start mysqld |
获取初始密码
1 | cat / var / log / mysqld.log |grep password |
使用初始密码登录并且修改密码
1 | mysql> SET PASSWORD = PASSWORD( 'Mysql123456!' ); |
四,yum安装php
默认CentOS7.2的php版本为5.4这里设置安装php7
设置yum源
1 | rpm - Uvh https: / / mirror.webtatic.com / yum / el7 / webtatic - release.rpm |
安装
1 | yum - y install php70w php70w - fpm php70w - pdo php70w - mysql |
查看版本
1 2 | php - v php - fpm - v |
启动php-fpm
1 | php - fpm |
验证
在目录/usr/share/nginx/html/下面新建两个文件
test.php
1 2 3 | <?php phpinfo() ?> |
mysql.php
1 2 3 4 5 6 7 8 9 | <?php $mysqli = new mysqli( "localhost" , "root" , "Mysql123456!" ); if (!$mysqli) { echo "database error" ; } else { echo "MySQL successful" ; } $mysqli - >close(); ?> |
注意:网站的根目录千万不要放在root目录下,随便放在其他普通目录都可以,如果放在/root目录下即使把该目录的权限设置为777都无法访问php文件,页面会报错
1 | File not found. |
nginx的错误日志error.log会报错
1 | FastCGI sent in stderr: "Primary script unknFastCGI |
分类:
Linux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!