CentOS上yum方式安装配置LNMP
实验环境
- 一台最小化安装的CentOS 7.3虚拟机
安装软件包
yum install -y epel-*
yum install -y nginx mariadb-server php php-mysql \
php-fpm php-pdo php-pdo_dblib php-gd php-pear \
php-xml php-pecl-zip php-json php-devel wget vim
配置nginx支持PHP
1.建立nginx
的web主目录
mkdir /var/wwwroot
cd /var/wwwroot
echo -e hello_world >> index.html
echo -e "<?php phpinfo(); ?>" >> info.php
2.编辑nginx
的配置文件
vim /etc/nginx/nginx.conf
3.修改nginx
主目录和索引
- 将
http
下的server
下的root
的值修改为/var/wwwroot
- 在
http
下的server
下添加index index.php index.html index.htm
4.在http
下的server
区块加入以下内容
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
5.启动nginx
和php-fpm
systemctl start nginx php-fpm
systemctl enable nginx php-fpm
6.关闭防火墙
setenforce 0
systemctl stop firewalld
systemctl disable firewalld
7.在宿主机访问nginx
访问http://[centos_ip]/info.php
配置MySQL
1.启动MySQL
systemctl start mariadb
systemctl enable mariadb
2.输入以下命令,配置MySQL
mysql_secure_installation
3.提示Enter current password for root (enter for none):
敲击回车
4.提示Set root password? [Y/n]
按Y
,随后设置密码
5.提示Remove anonymous users?
意思为是否删除匿名用户
6.提示Disallow root login remotely?
意思为远程禁止root登录吗?
7.提示Remove test database and access to it?
意思为删除测试数据库吗?
8.提示Reload privilege tables now?
意思为现在重新加载特权表吗?
9.登录mysql数据库
mysql -uroot -p
下载WordPress测试LNMP环境
1.下载WordPress
cd /var/wwwroot
rm -rf index.html
rm -rf info.php
wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz
cp -rf /var/wwwroot/wordpress/* /var/wwwroot
cd /var/wwwroot
rm -rf wordpress
chmod -R 777 *
2.登录mysql创建数据库
mysql -uroot -p
CREATE DATABASE wordpress;
3.在宿主机访问nginx服务器
访问http://[centos_ip]/
按提示安装即可
本文链接:https://www.cnblogs.com/connect/p/linux-yum-install-lnmp.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?