yum搭建lnmp平台
时间: 2023-06-28 07:06:50 浏览: 135
在 CentOS 系统中,可以使用 yum 命令安装 LNMP 环境。
1. 安装 EPEL 源
EPEL(Extra Packages for Enterprise Linux)是由 Fedora 社区打造的 CentOS 与 RHEL 的社区软件源,包含了很多 CentOS 与 RHEL 没有的软件包。使用下面命令安装:
```
yum install epel-release
```
2. 安装 Nginx
使用下面命令安装 Nginx:
```
yum install nginx
```
启动 Nginx 服务:
```
systemctl start nginx
```
设置 Nginx 开机自启:
```
systemctl enable nginx
```
3. 安装 MySQL
使用下面命令安装 MySQL:
```
yum install mariadb mariadb-server
```
启动 MySQL 服务:
```
systemctl start mariadb
```
设置 MySQL 开机自启:
```
systemctl enable mariadb
```
执行安全设置:
```
mysql_secure_installation
```
根据提示输入密码并设置 MySQL 安全选项。
4. 安装 PHP
使用下面命令安装 PHP:
```
yum install php php-mysql php-fpm
```
启动 PHP-FPM 服务:
```
systemctl start php-fpm
```
设置 PHP-FPM 开机自启:
```
systemctl enable php-fpm
```
5. 配置 Nginx
编辑 Nginx 配置文件:
```
vim /etc/nginx/nginx.conf
```
找到 `server` 配置块,并修改为以下内容:
```
server {
listen 80;
server_name your_domain.com; # 修改为自己的域名
root /var/www/html; # 修改为自己的网站根目录
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /404.html;
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; # 修改为自己的 PHP-FPM Socket 路径
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
```
保存并退出。
重启 Nginx 服务:
```
systemctl restart nginx
```
现在,LNMP 环境已经配置完成。可以将网站文件放到 `/var/www/html` 目录下,并访问自己的域名即可。
阅读全文
相关推荐

















