CentOS 7 下搭建LNMP运行环境(nginx,php,mariadb)

php yum nginx 运维 · warm · 于 9个月前 发布 · 413 次阅读

环境搭建步骤

初步步骤

1.检查centos版本

执行命令

cat /etc/centos-release

执行结果

# CentOS Linux release 7.6.1810 (Core)

2. 设置时区

timedatectl list-timezones
sudo timedatectl set-timezone 'Asia/Shanghai'

date 命令查看时区

date

3. 更新操作系统软件包

sudo yum update -y

若执行失败 可参考网站(https://mirrors.tuna.tsinghua.edu.cn/help/centos/)

4. 安装CentOS操作系统基本管理所需的一些基本软件包

sudo yum install -y curl wget vim git unzip socat bash-completion epel-release

第1步 - 安装PHP和必要的PHP扩展

1. 设置Webtatic YUM源:

sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. 安装PHP,以及必要的PHP扩展:

sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-mbstring php72w-zip php72w-mysql php72w-sqlite3 php72w-curl php72w-xml php72-gd  php72w-intl

要显示在模块中编译的PHP,您可以运行:

php -m

运行结果

[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom

检查PHP版本:

php --version

运行结果

# PHP 7.2.14 (cli) (built: Jan 12 2019 12:47:33) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
#     with Zend OPcache v7.2.14, Copyright (c) 1999-2018, by Zend Technologies

3. 启动并启用PHP-FPM服务:

sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service

继续下一步,即数据库安装和设置

第2步 - 安装数据库和设置

1.安装数据库服务器

sudo yum install -y mariadb-server

检查数据库版本

mysql --version

运行结果

# mysql  Ver 15.1 Distrib 5.5.60-MariaDB, for Linux (x86_64) using readline 5.1

如果是远程环境,不需要设置服务启动和密码(进行2,3步骤)

2.启动服务

sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service

3. 数据库密码设置

sudo mysql_secure_installation

回答每个问题:

Would you like to setup VALIDATE PASSWORD plugin? N
New password: your_secure_password
Re-enter new password: your_secure_password
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

以root用户身份连接到 mysql shell:

sudo mysql -u root -p
# Enter password

为Bolt CMS 创建一个空的 MariaDB 数据库和用户并记住凭据:

MariaDB> CREATE DATABASE dbname;
MariaDB> GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
MariaDB> FLUSH PRIVILEGES;

退出 MariaDB:

MariaDB> exit

替换,并用您自己的名字。 dbname username password

第三步 - 安装nginx

nginx 安装参考文档 http://nginx.org/en/linux_packages.html#RHEL-CentOS

1. 安装 yum-utils

sudo yum install yum-utils

创建一个文件, /etc/yum.repos.d/nginx.repo 使用如下内容

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

安装nginx

sudo yum install nginx

检查nginx的版本

nginx -v

运行结果

# nginx version: nginx/1.12.2

2.启动并启用Nginx服务:

sudo systemctl start nginx.service
sudo systemctl enable nginx.service

3.通过运行以下命令 为Pagekit 配置 NGINX:

sudo vim /etc/nginx/conf.d/pagekit.conf

并使用以下配置填充文件:

server {
    listen [::]:443 ssl http2;
    listen 443 ssl http2;
    listen [::]:80;
    listen 80;
    # 配置自己的域名
    server_name example.com;

    index index.php index.html;
    #配置项目目录
    root /var/www/pagekit;

    ssl_certificate /etc/letsencrypt/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/example.com/private.key;
    ssl_certificate /etc/letsencrypt/example.com_ecc/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/example.com_ecc/private.key;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $fastcgi_script_name =404;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_index index.php; include fastcgi.conf;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass 127.0.0.1:9000;
    }

}

如果是yii框架,参考网站 https://www.yiichina.com/doc/guide/2.0/start-installation

检查 NGINX 配置是否存在语法错误:

sudo nginx -t

4.重新启动NGINX 服务:

sudo systemctl reload nginx.service

参考网站 https://www.howtoforge.com/how-to-install-pagekit-cms-on-centos-7/

共收到 0 条回复
没有找到数据。
添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册