阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS上yum方式安装配置LNMP

156次阅读
没有评论

共计 1512 个字符,预计需要花费 4 分钟才能阅读完成。

实验环境

  1. 一台最小化安装的 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

CentOS 上 yum 方式安装配置 LNMP

2. 编辑 nginx 的配置文件

vim /etc/nginx/nginx.conf

CentOS 上 yum 方式安装配置 LNMP

3. 修改 nginx 主目录和索引

  1. http 下的 server 下的 root 的值修改为/var/wwwroot
  2. http 下的 server 下添加index index.php index.html index.htm

CentOS 上 yum 方式安装配置 LNMP

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;
    }

CentOS 上 yum 方式安装配置 LNMP

5. 启动 nginxphp-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

CentOS 上 yum 方式安装配置 LNMP

配置 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,随后设置密码

CentOS 上 yum 方式安装配置 LNMP

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

CentOS 上 yum 方式安装配置 LNMP

下载 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]/
按提示安装即可

CentOS 上 yum 方式安装配置 LNMP
CentOS 上 yum 方式安装配置 LNMP
CentOS 上 yum 方式安装配置 LNMP

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计1512字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中