centos8 安装 LMAP(Linux+Apache+MySQL+PHP)环境

centos8 安装 LMAP 过程记录

系统环境:

cat  /etc/redhat-release
# CentOS Linux release 8.0.1905 (Core)
getconf LONG_BIT
# 64
uname -a
# Linux insome 4.18.0-80.11.2.el8_0.x86_64 #1 SMP Tue Sep 24 11:32:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

1. 更新 CentOS 8 软件包

dnf update
... ...

更新后查看系统环境

cat  /etc/redhat-release
# CentOS Linux release 8.1.1911 (Core)
uname -a
# Linux insome 4.18.0-147.5.1.el8_1.x86_64 #1 SMP Wed Feb 5 02:00:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Linux 内核的升级,reboot 重启之后 uname -a才会显示更新

2. 在 CentOS 8 上安装 Apache Web 服务器

  • 安装 Apache

    dnf install httpd httpd-tools
  • 设置 Apache 服务开机自启

    systemctl enable httpd
    # Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
  • 启动相关命令

    # 启动Apache服务
    systemctl start httpd
    
    # 关闭Apache服务
    systemctl stop httpd
    
    # 查看Apache服务状态
    systemctl status httpd
    
    # 重启Apache服务
    systemctl restart httpd
  • 查看 Apache 的版本以及与 Apache 相关的其他详细信息

    httpd -v
    # Server version: Apache/2.4.37 (centos)
    # Server built:   Dec 23 2019 20:45:34
    
    rpm -qi httpd
    # Name        : httpd
    # Version     : 2.4.37
    # Release     : 16.module_el8.1.0+256+ae790463
    # Architecture: x86_64
    # Install Date: Wed 04 Mar 2020 10:02:16 AM CST
    # Group       : System Environment/Daemons
    # Size        : 5611291
    # License     : ASL 2.0
    # Signature   : RSA/SHA256, Tue 24 Dec 2019 06:22:02 AM CST, Key ID     # 05b555b38483c65d
    # Source RPM  : httpd-2.4.37-16.module_el8.1.0+256+ae790463.src.rpm
    # Build Date  : Tue 24 Dec 2019 04:46:30 AM CST
    # Build Host  : x86-02.mbox.centos.org
    # Relocations : (not relocatable)
    # Packager    : CentOS Buildsys 
    # Vendor      : CentOS
    # URL         : https://httpd.apache.org/
    # Summary     : Apache HTTP Server
    # Description :
    # The Apache HTTP Server is a powerful, efficient, and extensible
    # web server.
  • Apache 配置文件路径:
    /etc/httpd/conf/httpd.conf
  • 现在可以访问服务器 IP 地址查看 Apache 测试页
    Apache测试页面
阿里云服务器默认没有开启 80 端口,访问 IP 地址测试 Apache 是否正常工作前,需要先开启服务器的 80 端口

3. 在 CentOS 8 上安装 MariaDB

MariaDB 是 MySQL 数据库的分支。 它是由一个 MySQL 的前团队开发的,该团队担心 Oracle 可能会将 MySQL 变成一个开源项目。 它具有比 MySQL 更好的创新功能,使其比 MySQL 更好。
  • 安装 MariaDB

    dnf install mariadb-server mariadb -y
  • 设置 MariaDB 服务开机自启

    systemctl enable mariadb
    # Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
    # Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/  # system/mariadb.service.
    # Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
  • 启动相关命令

    # 启动 MariaDB 服务
    systemctl start mariadb
    
    # 关闭 MariaDB 服务
    systemctl stop mariadb
    
    # 查看 MariaDB 服务状态
    systemctl status mariadb
    
    # 重启 MariaDB 服务
    systemctl restart mariadb
  • 设置密码

    mysql_secure_installation
    # Enter current password for root (enter for none):
    # 第一次设置的时候 root 密码为空,直接回车即可
    # 之后设置新密码
    # 之后根据提示输入 y 或者 n,建议一直 y 到最后。
  • MariaDB 配置文件路径:
    /etc/my.cnf

4. 在 CentOS 8 上安装 PHP 7

  • 获取 PHP 最新版本

    我们将使用 Remi 信息库安装最新版本的 PHP
    # 安装 EPEL 存储库
    dnf install https://dl.Fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
    
    # 安装yum utils并使用以下命令启用remi-repository
    dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
    
    # 搜索可下载的 PHP 模块
    dnf module list php
    # Remi's Modular repository for Enterprise Linux 8 - x86_64                                                        26 kB/s | 538 kB     00:20
    # Safe Remi's RPM repository for Enterprise Linux 8 -  x86_64                                                       22 kB/s | 1.4  MB     01:06
    # Last metadata expiration check: 0:00:06 ago on Wed 04 Mar 2020 11:06:50 AM  CST.
    # CentOS-8 - AppStream
    # Name                      Stream                        Profiles                                        Summary
    # php                       7.2 [d]                      common [d], devel,  minimal                     PHP scripting language
    # php                       7.3                          common, devel,  minimal                         PHP scripting language
    
    # Remi's Modular repository for Enterprise Linux 8 - x86_64
    # Name                      Stream                        Profiles                                        Summary
    # php                       remi-7.2                     common [d], devel,  minimal                     PHP scripting language
    # php                       remi-7.3                     common [d], devel,  minimal                     PHP scripting language
    # php                       remi-7.4                     common [d], devel,  minimal                     PHP scripting language
    
    # Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
  • 安装 PHP 最新版本

    # 输出表明当前默认安装的 PHP 版本是 PHP 7.2。要安装较新的版本 PHP 7.4,请重置 PHP 模块
    dnf module reset php
    
    # 重置PHP模块后,启用PHP 7.4模块
    dnf module enable php:remi-7.4
    # 再次 dnf module list php 搜索可下载 PHP 模块时,remi-7.4 会显示 [e]已启用
    
    # 最后,使用命令安装PHP,PHP-FPM(FastCGI进程管理器)和关联的PHP模块。
    dnf install php php-opcache php-gd php-curl php-mysqlnd
    # Installed:
    #     php-7.4.3-1.el8.remi.x86_64           php-common-7.4.3-1.el8.remi.x86_64    php-gd-7.4.3-1.el8.remi.x86_64
    #     php-mysqlnd-7.4.3-1.el8.remi.x86_64   php-opcache-7.4.3-1.el8.remi.x86_64   nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch
    #     php-cli-7.4.3-1.el8.remi.x86_64       php-fpm-7.4.3-1.el8.remi.x86_64       php-mbstring-7.4.3-1.el8.remi.x86_64
    #     php-sodium-7.4.3-1.el8.remi.x86_64    php-xml-7.4.3-1.el8.remi.x86_64       gd-2.2.5-6.el8.x86_64
    #     jbigkit-libs-2.1-14.el8.x86_64        libXpm-3.5.12-7.el8.x86_64            libjpeg-turbo-1.5.3-10.el8.x86_64
    #     libtiff-4.0.9-15.el8.x86_64           libwebp-1.0.0-1.el8.x86_64            oniguruma-6.8.2-1.el8.x86_64
    #     libxslt-1.1.32-3.el8.x86_64           libsodium-1.0.18-2.el8.x86_64         php-json-7.4.3-1.el8.remi.x86_64
    #     php-pdo-7.4.3-1.el8.remi.x86_64
  • 查看 PHP 版本

    php -v
    # PHP 7.4.3 (cli) (built: Feb 18 2020 11:53:05) ( NTS )
    # Copyright (c) The PHP Group
    # Zend Engine v3.4.0, Copyright (c) Zend Technologies
    #     with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
    
  • 设置 PHP-FPM 服务开机自启

    systemctl enable php-fpm
    # Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
  • 启动相关命令

    # 启动 PHP-FPM 服务
    systemctl start php-fpm
    
    # 关闭 PHP-FPM 服务
    systemctl stop php-fpm
    
    # 查看 PHP-FPM 服务状态
    systemctl status php-fpm
    
    # 重启 PHP-FPM 服务
    systemctl restart php-fpm
  • 指示 SELinux 允许 Apache 通过 PHP-FPM 运行来执行 PHP 代码

    setsebool -P httpd_execmem 1
    
    # 最后,重新启动Apache Web服务器以使PHP与Apache Web服务器一起使用。
    systemctl restart httpd
  • PHP 配置文件路径:
    /etc/php.ini
  • 测试 PHP 信息

    # 要在网络服务器上测试PHP,您必须在文档根目录中创建一个info.php文件。
    nano /var/www/html/linuxidc.php
    
    # 输入:
    # 

    浏览器访问查看 PHP 模块是否正常工作
    测试PHP模块是否正常工作

你可能感兴趣的:(centos8,lamp)