• 如何在Rocky Linux 8上安装LAMP栈


    LAMP使一个在托管静态和动态web程序的开发环境中使用的流行栈。它是Linux, Apache, MySQL(或MariaDB)和PHP的缩写。它由Apache web服务程序,MYSQL或MariaDB数据程序和PHP组成。我们在这里经历在Rocky Linux 8上安装LAMP。

    前提条件

    在你开始前,确保你有一下去:

    • 一个Rocky Linux实例
    • 一个sudo配置的用户

    第一步:在Rocky Linux上安装Apache

    我们将要开始安装的第一个组件是Apache web服务程序。由httpd软件包提供了这个服务程序。在安装时,httpd守护进程在后台运行,等待来自客户端设备进入的HTTP请求。

    要按照Apache,启动你的终端并且运行这个命令。

    [root@rockygu ~]# dnf install httpd -y

    这一起安装了httpd包和其它依赖包。

    之后,使得这个web服务器在系统启动时启动。

    1. [root@rockygu ~]# systemctl enable httpd
    2. Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

    启动这个服务程序并且验证Apache在Rocky Linux 8上运行了:

    1. [root@rockygu ~]# systemctl start httpd
    2. [root@rockygu ~]# systemctl status httpd
    3. ● httpd.service - The Apache HTTP Server
    4. Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor prese>
    5. Active: active (running) since Tue 2022-07-26 22:46:49 CST; 1 day 23h ago
    6. Docs: man:httpd.service(8)
    7. Main PID: 589823 (httpd)
    8. Status: "Total requests: 197; Idle/Busy workers 100/0;Requests/sec: 0.00115;>
    9. Tasks: 278 (limit: 11402)
    10. Memory: 33.1M
    11. CGroup: /system.slice/httpd.service
    12. ├─589823 /usr/sbin/httpd -DFOREGROUND
    13. ├─589824 /usr/sbin/httpd -DFOREGROUND
    14. ├─589825 /usr/sbin/httpd -DFOREGROUND
    15. ├─589826 /usr/sbin/httpd -DFOREGROUND
    16. ├─589827 /usr/sbin/httpd -DFOREGROUND
    17. └─590053 /usr/sbin/httpd -DFOREGROUND

    验证Apache有效并且运行的另一种方法是通过浏览服务器的IP地址或者完全合格域名(FQDN)。

    1. http://server-IP
    2. OR
    3. http://domain.com

    这应该给出Apache HTTP测试页:

     如果当尝试访问这个页面时,在你浏览器上得到一个错误,则可能防火墙阻塞了HTTP流量。运行以下命令来运行HTTP流量并且重载这个防火墙。

    1. [root@rockygu ~]# firewall-cmd --add-service=http --permanent
    2. [root@rockygu ~]# firewall-cmd --add-service=http
    3. [root@rockygu ~]# firewall-cmd --reload

    第二步:在Rocky Linux行安装MySQL

    接着我们需要安装一个数据库服务软软件MySQL。

    要按照MySQL,运行以下命令:

    [root@rockygu blctrl]# dnf install mysql-server mysql -y

    当按照完成时,使MySQL能在系统重新启动时自启动。

    1. [root@rockygu blctrl]# systemctl enable --now mysqld
    2. Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

    最终,启动MySQL服务。

    [root@rockygu blctrl]# systemctl start mysqld

    用以下命令验证MySQL运行了。

    1. [root@rockygu blctrl]# systemctl status mysqld
    2. ● mysqld.service - MySQL 8.0 database server
    3. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pres>
    4. Active: active (running) since Sat 2022-07-30 16:46:13 CST; 1min 43s ago
    5. Process: 622362 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, >
    6. Process: 622238 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service>
    7. Process: 622214 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, st>
    8. Main PID: 622318 (mysqld)
    9. Status: "Server is operational"
    10. Tasks: 37 (limit: 11402)
    11. Memory: 436.7M
    12. CGroup: /system.slice/mysqld.service
    13. └─622318 /usr/libexec/mysqld --basedir=/usr

    MySQL的默认设置是脆弱并且造成一些可以被黑客利用入侵数据库服务器的漏洞。因为如此,我们需要采取补充步骤来加固这个数据库服务器。要实现这个目标,运行以下显示的脚本。

    为余下配置输入'Y'。这将有效地净化或移除任何义名用户,防止远程root登录以及移除在一个生产环境中不需要地Test数据库。

    1. [root@rockygu blctrl]# mysql_secure_installation
    2. Securing the MySQL server deployment.
    3. Connecting to MySQL using a blank password.
    4. VALIDATE PASSWORD COMPONENT can be used to test passwords
    5. and improve security. It checks the strength of password
    6. and allows the users to set only those passwords which are
    7. secure enough. Would you like to setup VALIDATE PASSWORD component?
    8. Press y|Y for Yes, any other key for No: Y
    9. There are three levels of password validation policy:
    10. LOW Length >= 8
    11. MEDIUM Length >= 8, numeric, mixed case, and special characters
    12. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
    13. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 8
    14. Invalid option provided.
    15. There are three levels of password validation policy:
    16. LOW Length >= 8
    17. MEDIUM Length >= 8, numeric, mixed case, and special characters
    18. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
    19. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
    20. Please set the password for root here.
    21. New password:
    22. Re-enter new password:
    23. Estimated strength of the password: 100
    24. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
    25. By default, a MySQL installation has an anonymous user,
    26. allowing anyone to log into MySQL without having to have
    27. a user account created for them. This is intended only for
    28. testing, and to make the installation go a bit smoother.
    29. You should remove them before moving into a production
    30. environment.
    31. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
    32. Success.
    33. Normally, root should only be allowed to connect from
    34. 'localhost'. This ensures that someone cannot guess at
    35. the root password from the network.
    36. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N
    37. ... skipping.
    38. By default, MySQL comes with a database named 'test' that
    39. anyone can access. This is also intended only for testing,
    40. and should be removed before moving into a production
    41. environment.
    42. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N
    43. ... skipping.
    44. Reloading the privilege tables will ensure that all changes
    45. made so far will take effect immediately.
    46. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
    47. Success.
    48. All done!

    数据库服务器现在完全配置并且安全了。

    第三步:在Rocky Linux上按照PHP

    最后,要安装地最后组件是PHP,PHP是一个在动态web页面开发中使用的脚本语言。Rocky Linux AppStream提供了多个PHP版本。要检查可用版本,运行命令:

    1. [root@rockygu blctrl]# dnf module list php
    2. Last metadata expiration check: 2:05:58 ago on Sat 30 Jul 2022 02:57:37 PM CST.
    3. Rocky Linux 8 - AppStream
    4. Name Stream Profiles Summary
    5. php 7.2 [d] common [d], devel, minimal PHP scripting language
    6. php 7.3 common [d], devel, minimal PHP scripting language
    7. php 7.4 common [d], devel, minimal PHP scripting language
    8. php 8.0 common [d], devel, minimal PHP scripting language
    9. Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

    这提供了一个PHP模块和Streams列表。默认PHP stream是PHP 7.2。要从仓库安装最新模块Stream,重置PHP stream。

    1. [root@rockygu blctrl]# dnf module reset php
    2. Last metadata expiration check: 2:09:38 ago on Sat 30 Jul 2022 02:57:37 PM CST.
    3. Dependencies resolved.
    4. Nothing to do.
    5. Complete!
    6. [root@rockygu blctrl]#

    接着使能首选的PHP stream。例如,要使能PHP 7.4,执行:

    [root@rockygu blctrl]# dnf module install php:7.4

    你可以安装补充的PHP扩展。我们现在安装php-curl和php-zip扩展。

    [root@rockygu blctrl]#  dnf install php-curl php-zip -y

    安装结束后,确认安装的PHP版本。

    1. [root@rockygu blctrl]# php -v
    2. PHP 7.4.19 (cli) (built: May 4 2021 11:06:37) ( NTS )
    3. Copyright (c) The PHP Group
    4. Zend Engine v3.4.0, Copyright (c) Zend Technologies

    测试安装的PHP版本的另一种方法是在/var/www/html/路径创建一个测试PHP文件。

    1. [root@rockygu blctrl]# cat /var/www/html/info.php
    2. phpinfo();
    3. ?>

    重启服web服务器。

    [root@rockygu blctrl]# systemctl restart httpd

    接着用你的浏览器并且输入以下URL:

    http://server-ip/info.php

     一个显示PHP版本以及诸如启动的PHP扩展细节的其它参数的页面将被显示。

    现在删除以上测试的PHP文件。

     

    [root@rockygu blctrl]# rm -rf /var/www/html/info.php
  • 相关阅读:
    联发科3纳米芯片预计2024年量产,此前称仍未获批给华为供货
    Win系统如何下载安装使用cpolar内网穿透工具?
    RocketMQ相关概念
    第2部分:物联网模式在行动
    Excel 数学
    MyBatis的自定义插件
    lua vm 二: 查看字节码、看懂字节码
    需求分析之道——需求分析要做什么(C系架构设计法,sishuok)
    频谱和功率谱的区别与联系
    Proof-of-Authentication,要啥PoX?
  • 原文地址:https://blog.csdn.net/yuyuyuliang00/article/details/126045037