Centos7- yum方式安装LNMP环境

LNMP 环境是指在 Linux 系统下,由 Nginx + MySQL/MariaDB + PHP 组成的网站服务器架构。

步骤1:安装 Nginx

1. 执行以下命令,在 /etc/yum.repos.d/ 下创建 nginx.repo 文件。

vi /etc/yum.repos.d/nginx.repo

2. 按 i 切换至编辑模式,写入以下内容。

[nginx]

name = nginx repo

baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/

gpgcheck = 0

enabled = 1

3. 按 Esc,输入 :wq,保存文件并返回。

4. 执行以下命令,安装 nginx。

yum install -y nginx

5. 执行以下命令,打开 default.conf 文件。

vim /etc/nginx/conf.d/default.conf

i 切换至编辑模式,编辑 default.conf 文件。

7. 找到 server{...},并将 server 大括号中相应的配置信息替换为如下内容。用于取消对 IPv6 地址的监听,同时配置 Nginx,实现与 PHP 的联动。
 

server {
 listen       80;
 root   /usr/share/nginx/html;
 server_name  localhost;
 #charset koi8-r;
 #access_log  /var/log/nginx/log/host.access.log  main;
 #
 location / {
       index index.php index.html index.htm;
 }
 #error_page  404              /404.html;
 #redirect server error pages to the static page /50x.html
 #
 error_page   500 502 503 504  /50x.html;
 location = /50x.html {
   root   /usr/share/nginx/html;
 }
 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 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;
 }
}

8. 按 Esc,输入 :wq,保存文件并返回。

9. 执行以下命令启动 Nginx。

systemctl start nginx

在本地浏览器中访问虚拟机的ip。

步骤2:安装数据库

执行以下命令,在 /etc/yum.repos.d/ 下创建 MariaDB.repo 文件。

vi /etc/yum.repos.d/MariaDB.repo

i 切换至编辑模式,写入以下内容,添加 MariaDB 软件库。

# MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = https://mirrors.cloud.tencent.com/mariadb/yum/10.4/centos7-amd64
gpgkey=https://mirrors.cloud.tencent.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

4. 按 Esc,输入 :wq,保存文件并返回。

5. 执行以下命令,安装 MariaDB。此步骤耗时较长,请关注安装进度,等待安装完毕。

yum -y install MariaDB-client MariaDB-server

6. 执行以下命令,启动 MariaDB 服务。

systemctl start mariadb
mysql

7. 输入\q退出

步骤3:安装配置 PHP

1. 依次执行以下命令,更新 yum 中 PHP 的软件源。

yum install -y epel-release
rpm -Uvh https://mirrors.tencent.com/remi/enterprise/remi-release-7.rpm

2. 运行以下命令,启用 PHP 8.0仓库

yum-config-manager --enable remi-php80

3. 执行以下命令,安装 PHP 8.0 所需要的包。

yum install -y php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json

4. 执行以下命令,启动 PHP-FPM 服务。

systemctl start php-fpm

5. 当您完成环境配置后,可以通过以下验证 LNMP 环境是否搭建成功。

echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php

重启nginx

systemctl restart nginx

刷新浏览器访问ip


如果生产环境中使用,可以将服务设置成开机启动

systemctl enable nginx 
systemctl enable mariadb
systemctl enable php-fpm

至此,教程结束!

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以按照以下步骤在CentOS 7上安装LNMPLinux + Nginx + MySQL + PHP): 1. 首先,需要更新YUM源。您可以使用以下命令添加EPEL源和IUS源: ``` yum install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm ``` 2. 接下来,安装必要的依赖库。您可以使用以下命令安装所需的依赖库: ``` yum install libevent* libtool* autoconf* libstd* ncurse* bison* openssl* ``` 3. 然后,需要安装cmake,因为自MySQL 5.5版本之后,需要使用cmake来支持编译安装。您可以使用以下命令安装cmake: ``` yum install cmake ``` 4. 最后,您需要将Nginx的软件源添加到CentOS 7系统中。您可以使用以下命令添加Nginx软件源: ``` yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm ``` 完成以上步骤后,您就可以继续安装LNMP环境了。这些步骤将帮助您在CentOS 7上安装LNMP123 #### 引用[.reference_title] - *1* *3* [Centos7部署LNMP](https://blog.csdn.net/qq_54735393/article/details/127199833)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* [CentOS7搭建LNMP环境](https://blog.csdn.net/weixin_46078817/article/details/103687975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值