LAMP 环境搭建(LAMP, L=Linux, A=httpd(apache), M=MariaDB, P=PHP) 一、操作系统 1、openeuler: Linux openeuler 5.10.0-60.18.0.50.oe2203.x86_64 二、lamp环境安装 1、[root@openeuler ~]# dnf install httpd mariadb-server php php-fpm php-mysqlnd OS 24 kB/s | 3.8 kB 00:00 everything 26 kB/s | 3.8 kB 00:00 Dependencies resolved. =============================================================================================== Package Architecture Version Repository Size =============================================================================================== Installing: httpd x86_64 2.4.51-5.oe2203 OS 1.3 M mariadb-server x86_64 4:10.5.10-3.oe2203 OS 18 M php-fpm x86_64 8.0.0-9.oe2203 everything 1.7 M php-mysqlnd x86_64 8.0.0-9.oe2203 everything 134 k Installing dependencies: apr x86_64 1.7.0-4.oe2203 OS 110 k apr-util x86_64 1.6.1-12.oe2203 OS 110 k httpd-filesystem noarch 2.4.51-5.oe2203 OS 11 k httpd-tools x86_64 2.4.51-5.oe2203 OS 71 k mariadb x86_64 4:10.5.10-3.oe2203 OS 6.2 M mariadb-common x86_64 4:10.5.10-3.oe2203 OS 28 k mariadb-config x86_64 4:10.5.10-3.oe2203 OS 9.1 k mariadb-connector-c x86_64 3.1.13-1.oe2203 OS 179 k mariadb-errmsg x86_64 4:10.5.10-3.oe2203 OS 200 k mod_http2 x86_64 1.15.25-1.oe2203 OS 126 k mysql-selinux noarch 1.0.0-2.oe2203 everything 35 k nginx-filesystem noarch 1:1.21.5-1.oe2203 everything 9.2 k perl-DBD-MariaDB x86_64 1.21-3.oe2203 OS 122 k perl-DBI x86_64 1.643-2.oe2203 OS 462 k php-common x86_64 8.0.0-9.oe2203 everything 547 k php-pdo x86_64 8.0.0-9.oe2203 everything 73 k Installing weak dependencies: mariadb-backup x86_64 4:10.5.10-3.oe2203 OS 6.9 M mariadb-gssapi-server x86_64 4:10.5.10-3.oe2203 OS 15 k mariadb-server-utils x86_64 4:10.5.10-3.oe2203 OS 1.2 M Transaction Summary =============================================================================================== Install 23 Packages Total download size: 38 M Installed size: 193 M Is this ok [y/N]: y 2、httpd 开机启动配置: [root@openeuler ~]# systemctl status httpd //查看httpd的运行状态 ○ httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/httpd.service.d └─php-fpm.conf Active: inactive (dead) Docs: man:httpd.service(8) [root@openeuler ~]# systemctl start httpd //运行httpd服务 [root@openeuler ~]# systemctl status httpd //查看httpd的运行状态 ↻ httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/httpd.service.d └─php-fpm.conf Active: reloading (reload) since Mon 2022-07-11 16:03:29 CST; 4s ago Docs: man:httpd.service(8) Main PID: 7916 (httpd) Status: "Reading configuration..." Tasks: 1 (limit: 21417) Memory: 2.9M CGroup: /system.slice/httpd.service └─7916 /usr/sbin/httpd -DFOREGROUND Jul 11 16:03:24 openeuler systemd[1]: Starting The Apache HTTP Server... Jul 11 16:03:29 openeuler httpd[7916]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::d7ab> Jul 11 16:03:29 openeuler systemd[1]: Started The Apache HTTP Server. [root@openeuler ~]# [root@openeuler ~]# systemctl enable httpd //设置某服务开机启动,httpd服务开机启动 Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service. [root@openeuler ~]# [root@openeuler ~]# 3、mariadb-server 开机启动配置: [root@openeuler ~]# systemctl status mariadb.service //查看mariadb.service的运行状态 ○ mariadb.service - MariaDB 10.5 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: inactive (dead) Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ [root@openeuler ~]# systemctl start mariadb.service //查看某服务的状态,mariadb.service [root@openeuler ~]# systemctl status mariadb.service //开启某服务, mariadb.service ● mariadb.service - MariaDB 10.5 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2022-07-11 16:05:52 CST; 2s ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: 8154 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/SUCCESS) Process: 8178 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS) Process: 8279 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=0/SUCCESS) Main PID: 8264 (mariadbd) Status: "Taking your SQL requests now..." Tasks: 14 (limit: 21417) Memory: 75.9M CGroup: /system.slice/mariadb.service └─8264 /usr/libexec/mariadbd --basedir=/usr Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: See the MariaDB Knowledgebase at https://mariadb.com/kb or the Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: MySQL manual for more instructions. Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: Please report any problems at https://mariadb.org/jira Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: The latest information about MariaDB is available at https://mariadb.org/. Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: You can find additional information about the MySQL part at: Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: https://dev.mysql.com Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: Consider joining MariaDB's strong and vibrant community: Jul 11 16:05:51 openeuler mariadb-prepare-db-dir[8217]: https://mariadb.org/get-involved/ Jul 11 16:05:51 openeuler mariadbd[8264]: 2022-07-11 16:05:51 0 [Note] /usr/libexec/mariadbd (mysqld 10.5.10-MariaDB) starting as process 8264> Jul 11 16:05:52 openeuler systemd[1]: Started MariaDB 10.5 database server. [root@openeuler ~]# [root@openeuler ~]# systemctl enable mariadb.service //设置某服务开机启动,mariadb.service服务开机启动 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. [root@openeuler ~]# [root@openeuler ~]# [root@openeuler ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.5.10-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create user 'admin'@'IP_ADDRESS' identified by 'PASSWORD'; //创建mysql的新账户:admin@IP;隐藏了IP和PASSWORD Query OK, 0 rows affected (0.002 sec) MariaDB [(none)]> grant all privileges on *.* to 'admin'@'IP_ADDRESS'; //给新用户授权,admin@IP Query OK, 0 rows affected (0.002 sec) MariaDB [(none)]> MariaDB [(none)]> show grants for 'admin'@'IP_ADDRESS'; // IP_ADDRESS - 博主隐藏了真实IP设置,IP_ADDRESS限制admin账户所用的主机IP。 +------------------------------------------------------------------------------------------------------------------------+ | Grants for 'admin'@'IP_ADDRESS' | +------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO `admin'@'IP_ADDRESS` IDENTIFIED BY PASSWORD '*04535A6782D45FF8FC0BA9CA1ADFEAC83AB55004' | +------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.001 sec) MariaDB [(none)]> MariaDB [(none)]> MariaDB [(none)]> create database davidtest ; // 数据批量导入 Query OK, 1 row affected (0.001 sec) MariaDB [(none)]> use davidtest Database changed MariaDB [davidtest]> source /root/user/lidawei/db/davidtest.sql Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Database changed Query OK, 0 rows affected (0.003 sec) Query OK, 0 rows affected (0.012 sec) Query OK, 6 rows affected (0.005 sec) Records: 6 Duplicates: 0 Warnings: 0 Query OK, 0 rows affected (0.002 sec) Query OK, 0 rows affected (0.012 sec) Query OK, 1 row affected (0.002 sec) Query OK, 0 rows affected (0.000 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) Query OK, 0 rows affected (0.001 sec) MariaDB [davidtest]> 4、php-fpm 开机启动配置:
[root@openeuler ~]# systemctl status php-fpm.service // 查看服务的运行状态,php-fpm.service ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2022-07-11 16:03:24 CST; 5min ago Main PID: 7917 (php-fpm) Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 6 (limit: 21417) Memory: 6.5M CGroup: /system.slice/php-fpm.service ├─7917 "php-fpm: master process (/etc/php-fpm.conf)" ├─7918 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─7919 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─7920 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─7921 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" └─7922 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Jul 11 16:03:24 openeuler systemd[1]: Starting The PHP FastCGI Process Manager... Jul 11 16:03:24 openeuler systemd[1]: Started The PHP FastCGI Process Manager. [root@openeuler ~]# [root@openeuler ~]# systemctl enable php-fpm.service // 设置某服务开机启动,php-fpm.service开机启动 Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service. [root@openeuler ~]# [root@openeuler ~]# 三、服务器配置 1、selinux 配置: [root@openeuler ~]# vim /etc/selinux/config SELINUX=disabled 2、firewall 配置: [root@openeuler ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent // 开放某端口 success [root@openeuler ~]# firewall-cmd --reload // 重新载入配置信息 success [root@openeuler ~]# firewall-cmd --zone=public --query-port=80/tcp // 查询某端口是否开放 yes [root@openeuler ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent // 关闭某端口 success [root@openeuler ~]# firewall-cmd --zone=public --query-port=80/tcp // 查询某端口状态 yes [root@openeuler ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent // 开放某端口 success [root@openeuler ~]# firewall-cmd --reload // 重新载入配置信息 success [root@openeuler ~]# firewall-cmd --zone=public --query-port=80/tcp // 查询某端口是否开放 yes [root@openeuler ~]#
3、fedora39防火墙配置(firewalld):
3.1、fedora39默认zone:FedoraWorkstation
1 [laohu@fedora:conf]$ sudo firewall-cmd --get-default-zone
2 FedoraWorkstation
3.2、fedora39防火墙设置(firewalld):firewalld在配置过程中没有指定参数“--zone=public”
1 [laohu@fedora:conf]$ sudo firewall-cmd --add-port=80/tcp --permanent
2 success
3 [laohu@fedora:conf]$ sudo firewall-cmd --add-port=3306/tcp --permanent
4 Warning: ALREADY_ENABLED: 3306:tcp
5 success
6 [laohu@fedora:conf]$ sudo firewall-cmd --list-all
7 FedoraWorkstation (default, active)
8 target: default
9 ingress-priority: 0
10 egress-priority: 0
11 icmp-block-inversion: no
12 interfaces: ens160
13 sources:
14 services: dhcpv6-client mdns samba-client ssh
15 ports: 1025-65535/udp 1025-65535/tcp
16 protocols:
17 forward: yes
18 masquerade: no
19 forward-ports:
20 source-ports:
21 icmp-blocks:
22 rich rules:
四、参考资料:
1、centos firewalld开放端口: https://www.cnblogs.com/wuliwawa/p/11944112.html
2、LAMP经典入门教程 - 运维派: http://www.yunweipai.com/36039.html
3、LAMP安装 - 运维派: http://www.yunweipai.com/36050.html
本文由 lnlidawei 原创、整理、转载,本文来自于【博客园】; 整理和转载的文章的版权归属于【原创作者】; 转载或引用时请【保留文章的来源信息】:https://www.cnblogs.com/lnlidawei/p/16467019.html