LAMP服务器是Linux Web托管的基础。如果您想建立一个LAMP堆栈来托管您的网站,本指南将为您提供有关如何在RHEL 8 / CentOS 8 Linux服务器上开始使用LAMP的必要信息。

在本教程中,您将学习:

  • 如何在RHEL 8 / CentOS 8上安装所有LAMP必备软件包。
  • 如何保护MariaDB数据库。
  • 如何启动httpd和MariaDB服务。
  • 如何打开HTTP和HTTPS防火墙端口。
    20191107122551-2019-11-7.png
  1. 首先安装依赖
    以下命令将安装执行LAMP安装所需的依赖:
    1
    dnf install php-mysqlnd php-fpm mariadb-server httpd
  2. 在防火墙上打开HTTP及HTTPS端口80,443 :
    1
    2
    3
    firewall-cmd --permanent --zone=public --add-service=http 
    firewall-cmd --permanent --zone=public --add-service=https
    firewall-cmd --reload
  3. 启动Apache Web服务器和MariaDB服务:
    1
    2
    systemctl start mariadb
    systemctl start httpd
    允许服务自启动
    1
    2
    systemctl enable mariadb
    systemctl enable httpd
  4. 保护您的MariaDB安装并设置root密码:
    1
    mysql_secure_installation
  5. 确认LAMP服务器安装。在/var/www/html/目录中创建一个info.php,包含以下内容:
    1
    <?php phpinfo(); ?>
  6. 更改权限:
    1
    2
    chown -R apache:apache /var/www/html/*
    chcon -t httpd_sys_rw_content_t /var/www/html/ -R
  7. 浏览器打开http://localhost/info.phpURL,然后配置LAMP安装
  1. 安装其他PHP模块。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    dnf search php-

    php-gd.x86_64 : A module for PHP applications for using the gd graphics library
    php-fpm.x86_64 : PHP FastCGI Process Manager
    php-pdo.x86_64 : A database access abstraction module for PHP applications
    php-gmp.x86_64 : A module for PHP applications for using the GNU MP library
    php-dbg.x86_64 : The interactive PHP debugger
    php-pdo.x86_64 : A database access abstraction module for PHP applications
    php-xml.x86_64 : A module for PHP applications which use XML
    php-fpm.x86_64 : PHP FastCGI Process Manager
    php-cli.x86_64 : Command-line interface for PHP
    php-dba.x86_64 : A database abstraction layer module for PHP applications
    php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
    php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
    php-ldap.x86_64 : A module for PHP applications that use LDAP
    php-pear.noarch : PHP Extension and Application Repository framework
    php-intl.x86_64 : Internationalization extension for PHP applications
    php-json.x86_64 : JavaScript Object Notation extension for PHP
    php-odbc.x86_64 : A module for PHP applications that use ODBC databases
    php-devel.x86_64 : Files needed for building PHP extensions
    php-pgsql.x86_64 : A PostgreSQL database module for PHP
    php-common.x86_64 : Common files for PHP
    php-common.x86_64 : Common files for PHP
    php-recode.x86_64 : A module for PHP applications for using the recode library
    php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
    php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
    php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
    php-enchant.x86_64 : Enchant spelling extension for PHP applications
    php-process.x86_64 : Modules for PHP script using system process interfaces
    php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
    php-opcache.x86_64 : The Zend OPcache
    php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
    php-pecl-zip.x86_64 : A ZIP archive management extension
    php-embedded.x86_64 : PHP library for embedding in applications
    php-pecl-apcu.x86_64 : APC User Cache
    php-pecl-apcu-devel.x86_64 : APCu developer files (header)
  2. 安装软件包后,请重新加载httpd服务:
    1
    systemctl reload httpd
  3. 安装完成