zoukankan      html  css  js  c++  java
  • CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    LAMP是Linux,Apache,MySQL和PHP的首字母缩写,是网站管理员和开发人员用来测试和托管动态网站的一种流行的免费开源堆栈。

    LAMP服务器带有4个核心组件:Apache Web服务器,MySQL或MariaDB数据库以及PHP(一种流行的脚本语言,用于创建动态Web页面)。

     常见的LAMP架构平台!LAMP是世界上最流行的组合,当然同时也有Nginx,也就是LNMP: LAMP 相对于 NGINX 来说较为安全,但是Nginx处理高并发比Apache要强,在本文中,您将学习如何在CentOS 8 Linux发行版上安装LAMP服务器。

    步骤1:更新CentOS 8软件包

    建议,通常在开始安装之前先更新软件包是一个好的习惯。 因此,登录到您的服务器并运行以下命令。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf update

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    步骤2:在CentOS 8上安装Apache Web 服务器

    随着系统软件包的更新,下一步是安装Apache Web 服务器,一些关键的工具和实用程序将运行下面这条命令。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install httpd httpd-tools

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    安装完成后,使用以下命令启用Apache在系统启动时自动启动。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl enable httpd
    Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

    接下来,通过运行命令启动Apache服务。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl start httpd

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    要确认Apache Web服务是否正在运行,请运行命令。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl status httpd

    输出如下:

    ● httpd.service - The Apache HTTP Server
      Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
      Active: active (running) since Wed 2020-02-26 07:07:23 EST; 2min 15s ago
        Docs: man:httpd.service(8)
     Main PID: 85860 (httpd)
      Status: "Running, listening on: port 80"
        Tasks: 213 (limit: 23820)
      Memory: 25.2M
      CGroup: /system.slice/httpd.service
              ├─85860 /usr/sbin/httpd -DFOREGROUND
              ├─85862 /usr/sbin/httpd -DFOREGROUND
              ├─85863 /usr/sbin/httpd -DFOREGROUND
    lines 1-12

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    如果您有点好奇,可以通过运行rpm命令来获取Apache的版本以及与Apache相关的其他详细信息。

    [linuxidc@localhost ~/www.linuxidc.com]$httpd -v
    Server version: Apache/2.4.37 (centos)
    Server built:  Dec 23 2019 20:45:34
    [linuxidc@localhost ~/www.linuxidc.com]$rpm -qi httpd

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    此外,您可以打开网络浏览器并访问显示的服务器IP。

    https://www.linuxidc.com/

    如下图

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    测试页

    本页面是在 Apache HTTP 服务器 完成安装后用来测试它的正常运作。如果你能阅读此页面,此网站已能正常运作。此服务器是由 CentOS 所驱动。

    步骤3:在CentOS 8上安装MariaDB

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

    要安装MariaDB,请运行命令。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install mariadb-server mariadb -y

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    接下来,启动并在启动时启用MariaDB,运行命令。

    [linuxidc@localhost ~/www.linuxidc.com]$systemctl start mariadb
    [linuxidc@localhost ~/www.linuxidc.com]$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.

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    您可以通过运行命令来验证MariaDB的状态。

     mariadb.service - MariaDB 10.3 database server
      Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
      Active: active (running) since Wed 2020-02-26 07:23:30 EST; 47s ago
        Docs: man:mysqld(8)
              https://mariadb.com/kb/en/library/systemd/
     Main PID: 90101 (mysqld)
      Status: "Taking your SQL requests now..."
        Tasks: 30 (limit: 23820)
      Memory: 81.7M
      CGroup: /system.slice/mariadb.service
              └─90101 /usr/libexec/mysqld --basedir=/usr
    ~

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    最后,我们需要通过secure来保护MariaDB数据库引擎。

    [linuxidc@localhost ~/www.linuxidc.com]$mysql_secure_installation

    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
          SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

    In order to log into MariaDB to secure it, we'll need the current
    password for the root user.  If you've just installed MariaDB, and
    you haven't set the root password yet, the password will be blank,
    so you should just press enter here.

    Enter current password for root (enter for none):

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    系统将提示您输入root密码(如果您已经有root密码)或进行设置。在随后的每个提示中回答Y。

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    步骤4:在CentOS 8上安装PHP 7

    我们需要安装的LAMP堆栈中的最后一个组件是PHP,并且如前所述,PHP是用于开发动态网页的脚本Web编程语言。

    我们将使用Remi信息库安装最新版本的PHP(在撰写本指南时为PHP 7.4)。

    首先,安装EPEL存储库。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install https://dl.Fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    接下来,安装yum utils并使用以下命令启用remi-repository。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    成功安装yum-utils和Remi-packages之后,通过运行命令搜索可下载的PHP模块。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf module list php

    输出将包括可用的PHP模块,流和安装配置文件,如下所示。

    Extra Packages for Enterprise Linux 8 - x86_64  3.3 MB/s | 5.9 MB    00:01   
    Remi's Modular repository for Enterprise Linux  7.1 kB/s | 535 kB    01:15   
    Safe Remi's RPM repository for Enterprise Linux 3.7 kB/s | 1.4 MB    06:27   
    上次元数据过期检查:0:00:03 前,执行于 2020年02月26日 星期三 07时39分24秒。
    CentOS-8 - AppStream
    Name    Stream        Profiles                      Summary                 
    php      7.2 [d][e]    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 

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境 

    提示:[d]默认,[e]已启用,[x]已禁用,[i]已安装

    输出表明当前安装的PHP版本是PHP 7.2。要安装较新的版本PHP 7.4,请重置PHP模块。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf module reset php

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    重置PHP模块后,通过运行启用PHP 7.4模块。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo dnf module enable php:remi-7.4

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    最后,使用命令安装PHP,PHP-FPM(FastCGI进程管理器)和关联的PHP模块。

    [linuxidc@localhost ~/www.linuxidc.com]$ sudo dnf install php php-opcache php-gd php-curl php-mysqlnd

    已安装:
      php-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-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                                           
      oniguruma-6.8.2-1.el8.x86_64                                                 
      libsodium-1.0.18-2.el8.x86_64                                               
      php-pdo-7.4.3-1.el8.remi.x86_64                                             

    完毕!

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    验证安装的版本可以运行。

    [linuxidc@localhost ~/www.linuxidc.com]$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

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    完善!现在,我们已经安装了PHP 7.4。同样重要的是,我们需要在启动时启动并启用PHP-FPM。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl start php-fpm
    [sudo] linuxidc 的密码:
    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl enable php-fpm
    Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    要检查其状态,请执行命令。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl status php-fpm

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    指示SELinux允许Apache通过PHP-FPM运行来执行PHP代码。

    [linuxidc@localhost ~/www.linuxidc.com]$ setsebool -P httpd_execmem 1

    最后,重新启动Apache Web服务器以使PHP与Apache Web服务器一起使用。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo systemctl restart httpd

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    步骤5:测试PHP信息

    要在网络服务器上测试PHP,您必须在文档根目录中创建一个info.php文件。

    [linuxidc@localhost ~/www.linuxidc.com]$sudo nano /var/www/html/linuxidc.php

    在下面插入PHP代码并保存文件。

    <?php
     phpinfo ();
    ?>

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    然后转到您的浏览器,并在下面输入URL。 请记住用服务器的实际IP地址替换服务器本文测试的地址。

    https://www.linuxidc.com/linuxidc.php

    CentOS 8.1下搭建LAMP(Linux+Apache+MySQL+PHP)环境

    现在,您应该能够在Web浏览器上查看有关PHP的信息。

    OK! 现在,您已在CentOS 8系统上安装了Apache,PHP和MariaDB。 作为一种好习惯,请确保删除info.php文件,因为这能够识别您正在运行的PHP版本,有可能造成安全风险。

  • 相关阅读:
    Jmeter使用实践-接口diff测试
    Jmeter发送HTTPS请求
    Jmeter使用实践- 基础介绍
    Jmeter性能测试工具的使用(Web性能测试)
    使用JMeter创建FTP测试计划
    Jmeter引用cookies进行登录实战
    Jmeter: PATCH方法无法发送参数的暂时解决方法
    Springboot整合Freemarker
    Springboot整合Jsp
    Springboot文件上传
  • 原文地址:https://www.cnblogs.com/xlpc/p/14026689.html
Copyright © 2011-2022 走看看