lamp架构

lamp的搭建

在同一台服务器上搭建

安装apache

[root@localhost ~]# dnf -y install wget
上次元数据过期检查:1:43:00 前,执行于 2021年05月12日 星期三 18时46分56秒。
依赖关系解决。
=================================================================================================
 软件包            架构                版本                         仓库                    大小
=================================================================================================
安装:
 wget              x86_64              1.19.5-10.el8                appstream              734 k

事务概要
=================================================================================================
安装  1 软件包
[root@localhost ~]# wget https://archive.apache.org/dist/apr/apr-1.7.0.tar.bz2
--2021-05-12 20:30:05--  https://archive.apache.org/dist/apr/apr-1.7.0.tar.bz2
正在解析主机 archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
正在连接 archive.apache.org (archive.apache.org)|138.201.131.134|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:872238 (852K) [application/x-bzip2]
正在保存至: “apr-1.7.0.tar.bz2”

apr-1.7.0.tar.bz2        100%[===============================>] 851.79K   115KB/s  用时 7.7s    

2021-05-12 20:30:14 (111 KB/s) - 已保存 “apr-1.7.0.tar.bz2” [872238/872238])

[root@localhost ~]#  wget https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.bz2
--2021-05-12 20:30:19--  https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.bz2
正在解析主机 archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
正在连接 archive.apache.org (archive.apache.org)|138.201.131.134|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:428595 (419K) [application/x-bzip2]
正在保存至: “apr-util-1.6.1.tar.bz2”

apr-util-1.6.1.tar.bz2   100%[===============================>] 418.55K   110KB/s  用时 3.8s  
2021-05-12 20:30:24 (110 KB/s) - 已保存 “apr-util-1.6.1.tar.bz2” [428595/428595])

[root@localhost ~]# wget https://archive.apache.org/dist/httpd/httpd-2.4.43.tar.bz2
--2021-05-12 20:30:36--  https://archive.apache.org/dist/httpd/httpd-2.4.43.tar.bz2
正在解析主机 archive.apache.org (archive.apache.org)... 138.201.131.134, 2a01:4f8:172:2ec5::2
正在连接 archive.apache.org (archive.apache.org)|138.201.131.134|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:7155865 (6.8M) [application/x-bzip2]
正在保存至: “httpd-2.4.43.tar.bz2”

httpd-2.4.43.tar.bz2     100%[===============================>]   6.82M   237KB/s  用时 40s     

2021-05-12 20:31:18 (173 KB/s) - 已保存 “httpd-2.4.43.tar.bz2” [7155865/7155865])

[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.43.tar.bz2
[root@localhost ~]# dnf -y install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel make expat-devel libtool
上次元数据过期检查:1:45:01 前,执行于 2021年05月12日 星期三 18时46分56秒。
软件包 openssl-1:1.1.1g-11.el8.x86_64 已安装。
依赖关系解决。
=================================================================================================
 软件包                   架构     版本                                        仓库         大小 

 解压rpm包

[root@localhost ~]# tar xf apr-1.7.0.tar.bz2 
[root@localhost ~]# tar xf apr-util-1.6.1.tar.bz2 
[root@localhost ~]# tar xf httpd-2.4.43.tar.bz2 
[root@localhost ~]# ls
anaconda-ks.cfg  apr-1.7.0.tar.bz2  apr-util-1.6.1.tar.bz2  httpd-2.4.43.tar.bz2
apr-1.7.0        apr-util-1.6.1     httpd-2.4.43
[root@localhost ~]# cd apr-1.7.0
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu

 

检测apr-1.7.0的编译环境

[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr

编译并安装apr-1.7.0

[root@localhost apr-1.7.0]# make
[root@localhost apr-1.7.0]# make install

检测apr-util-1.6.1.tar.bz2的编译环境

[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

编译并安装apr-util-1.6.1

[root@localhost apr-util-1.6.1]# make
[root@localhost apr-util-1.6.1]# make install

检测apache的编译环境并且配置所需要的功能

[root@localhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork

编译并安装apache 

[root@localhost httpd-2.4.43]# make
[root@localhost httpd-2.4.43]# make install

创建用户和组并设置属组和属主

[root@localhost httpd-2.4.43]# useradd -r -M -s /sbin/nologin -g apache apache
[root@localhost httpd-2.4.43]# chown -R apache.apache /usr/local/apache/

配置环境变量帮助文档和头文件

[root@localhost ~]# echo 'export PATH=/usr/local/apache/bin:$PATH' > /etc/profile.d/httpd.sh
[root@localhost ~]# source /etc/profile.d/httpd.sh
[root@localhost ~]# ln -s /usr/local/apache/include/ /usr/include/httpd
[root@localhost ~]# echo 'MANPATH /usr/local/apache/man' >> /etc/man.config

取消ServerName的注释

[root@localhost ~]# sed -i '/#ServerName/s/#//g' /etc/httpd24/httpd.conf 

将以下代码写在httpd.service文件中并存放在etc/systemd/system/目录下

[root@localhost ~]# cat << EOF >> /etc/systemd/system/httpd.service
> Description=Start httpd
> [Service]
> Type=simple
> EnvironmentFile=/etc/httpd24/httpd.conf
> ExecStart=/usr/local/apache/bin/httpd -k start -DFOREGROUND
> ExecReload=/usr/local/apache/bin/httpd -k graceful
> ExecStop=/bin/kill -WINCH ${MAINPID}
> [Install]
> WantedBy=multi-user.target
> EOF

启动apache

 

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl status httpd
● httpd.service
   Loaded: loaded (/etc/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-05-12 21:00:38 CST; 3min 4s ago
 Main PID: 110877 (httpd)
    Tasks: 6 (limit: 4743)
   Memory: 5.0M
   CGroup: /system.slice/httpd.service
           ├─110877 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─110878 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─110879 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─110880 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           ├─110881 /usr/local/apache/bin/httpd -k start -DFOREGROUND
           └─110882 /usr/local/apache/bin/httpd -k start -DFOREGROUND

5月 12 21:00:38 localhost.localdomain systemd[1]: Started httpd.service.

关闭防火墙和selinux

[root@localhost ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0

 

 查看80端口是否开启

[root@localhost ~]# ss -anlt
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          128                        *:80                      *:*                   
LISTEN     0          128                     [::]:22                   [::]:*                   

 

 安装mysql

安装依赖包

[root@localhost ~]#  dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
上次元数据过期检查:2:19:12 前,执行于 2021年05月12日 星期三 18时46分56秒。
软件包 openssl-devel-1:1.1.1g-15.el8_3.x86_64 已安装。
软件包 openssl-1:1.1.1g-15.el8_3.x86_64 已安装。
依赖关系解决。
=================================================================================================
 软件包                      架构    版本                                       仓库        大小
=================================================================================================
安装:
 cmake                       x86_64  3.18.2-9.el8                               appstream  9.8 M
 mariadb-devel               x86_64  3:10.3.27-3.module_el8.3.0+599+c587b2e7    appstream  1.0 M
 ncurses-devel               x86_64  6.1-7.20180224.el8                         baseos     527 k
安装依赖关系:
 cmake-data                  noarch  3.18.2-9.el8                               appstream  1.6 M
 cmake-filesystem            x86_64  3.18.2-9.el8                               appstream   44 k
 cmake-rpm-macros            noarch  3.18.2-9.el8                               appstream   44 k
 libuv                       x86_64  1:1.40.0-1.el8                             appstream  155 k
 mariadb-connector-c         x86_64  3.1.11-2.el8_3                             appstream  200 k
 mariadb-connector-c-config  noarch  3.1.11-2.el8_3                             appstream   15 k
 mariadb-connector-c-devel   x86_64  3.1.11-2.el8_3                             appstream   68 k
 ncurses-c++-libs            x86_64  6.1-7.20180224.el8                         baseos      58 k
 vim-filesystem              noarch  2:8.0.1763-15.el8                          appstream   48 k
启用模块流:
 mariadb                             10.3                                                       

事务概要
=================================================================================================
安装  12 软件包

创建用户

[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql

解压至指定目录 

[root@localhost ~]# tar xf mysql-5.7.33-linux-glibc2.12-x86_64\ .tar.gz -C /usr/local/

 创建软链接或者修改目录名

[root@localhost local]# mv mysql-5.7.33-linux-glibc2.12-x86_64/ mysql
[root@localhost local]# ls
apache  apr  apr-util  bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src

修改属组和属主

[root@localhost local]# chown -R mysql.mysql /usr/local/mysql/
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 13 apache apache 152 5月  12 20:50 apache
drwxr-xr-x.  6 root   root    58 5月  12 20:42 apr
drwxr-xr-x.  5 root   root    43 5月  12 20:44 apr-util
drwxr-xr-x.  2 root   root     6 5月  19 2020 bin
drwxr-xr-x.  2 root   root     6 5月  19 2020 etc
drwxr-xr-x.  2 root   root     6 5月  19 2020 games
drwxr-xr-x.  2 root   root     6 5月  19 2020 include
drwxr-xr-x.  2 root   root     6 5月  19 2020 lib
drwxr-xr-x.  3 root   root    17 5月  12 17:46 lib64
drwxr-xr-x.  2 root   root     6 5月  19 2020 libexec
drwxr-xr-x.  9 mysql  mysql  129 5月  12 21:21 mysql
drwxr-xr-x.  2 root   root     6 5月  19 2020 sbin
drwxr-xr-x.  5 root   root    49 5月  12 17:46 share
drwxr-xr-x.  2 root   root     6 5月  19 2020 src

设置环境变量

[root@localhost mysql]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@localhost mysql]# . /etc/profile.d/mysql.sh
[root@localhost mysql]# which mysql
/usr/local/mysql/bin/mysql

创建存放数据的目录并修改属主属组
需要一个空间大的目录,或者将目录创建后将硬盘设备挂载在此目录上

[root@localhost mysql]#  mkdir /opt/mysql_data
[root@localhost mysql]# chown -R mysql.mysql /opt/mysql_data/
[root@localhost mysql]# ll /opt
总用量 0
drwxr-xr-x. 2 mysql mysql 6 5月  12 21:36 mysql_data

 初始化并保存密码

 

[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/mysql_data/
2021-05-12T13:40:50.962310Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-05-12T13:40:51.673804Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-05-12T13:40:51.766447Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-05-12T13:40:51.826973Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: aaf5e254-b327-11eb-a45f-000c29778d47.
2021-05-12T13:40:51.828017Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-05-12T13:40:52.640637Z 0 [Warning] CA certificate ca.pem is self signed.
2021-05-12T13:40:53.295388Z 1 [Note] A temporary password is generated for root@localhost: KQ&4byGcx&pj
[root@localhost mysql]# vim password

写配置文件

[root@localhost mysql]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql			
datadir = /opt/mysql_data			
socket = /tmp/mysql.sock			
port = 3306									
pid-file = /opt/mysql_data/mysql.pid		
user = mysql								
skip-name-resolve						

启动脚本和开机自启

[root@localhost ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/mysql_data#g' /etc/init.d/mysqld
[root@localhost ~]# head -47 /etc/init.d/mysqld |tail -2
basedir=/usr/local/mysql
datadir=/opt/mysql_data
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/opt/mysql_data/localhost.localdomain.err'.
 SUCCESS! 
[root@localhost ~]# cd mysql
-bash: cd: mysql: 没有那个文件或目录
[root@localhost ~]#  chkconfig  mysqld on
[root@localhost ~]#  chkconfig --list

注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 

      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。

mysqld          0:关    1:关    2:开    3:开    4:开    5:开    6:关
[root@localhost ~]# ss -anlt
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          80                         *:3306                    *:*                   
LISTEN     0          128                        *:80                      *:*                   
LISTEN     0          128                     [::]:22                   [::]:*                   

头文件和库文件配置

[root@localhost ~]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost ~]# vim /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]#  ldconfig

启动并安装密码

[root@localhost ~]# mysql -uroot -p
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# dnf provides libncurses.so.5
上次元数据过期检查:3:10:16 前,执行于 2021年05月12日 星期三 18时46分56秒。
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries
仓库        :baseos
匹配来源:
提供    : libncurses.so.5

[root@localhost ~]# dnf -y install ncurses-compat-libs
上次元数据过期检查:3:10:29 前,执行于 2021年05月12日 星期三 18时46分56秒。
依赖关系解决。
=================================================================================================
 软件包                       架构            版本                         仓库             大小
=================================================================================================
安装:
 ncurses-compat-libs          x86_64          6.1-7.20180224.el8           baseos          331 k

事务概要
=================================================================================================
安装  1 软件包

总下载:331 k
安装大小:1.2 M
下载软件包:
ncurses-compat-libs-6.1-7.20180224.el8.x86_64.rpm                177 kB/s | 331 kB     00:01    
-------------------------------------------------------------------------------------------------
总计                                                             130 kB/s | 331 kB     00:02     
运行事务检查
事务检查成功。
运行事务测试
事务测试成功。
运行事务
  准备中  :                                                                                  1/1 
  安装    : ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                    1/1 
  运行脚本: ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                    1/1 
  验证    : ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                    1/1 
Installed products updated.

已安装:
  ncurses-compat-libs-6.1-7.20180224.el8.x86_64                                                  
[root@localhost /]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit

安装php 

 

[root@localhost ~]# dnf -y install php*

启动php-fpm监听端口并重启服务

[root@localhost /]# service php-fpm start
Redirecting to /bin/systemctl start php-fpm.service
[root@localhost /]# vim /etc/php
php.d/        php-fpm.conf  php-fpm.d/    php.ini       
[root@localhost /]# vim /etc/php-fpm.d/www.conf 
[root@localhost /]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@localhost /]# ss -anlt
State      Recv-Q     Send-Q         Local Address:Port         Peer Address:Port    Process     
LISTEN     0          128                  0.0.0.0:22                0.0.0.0:*                   
LISTEN     0          128                  0.0.0.0:9000              0.0.0.0:*                   
LISTEN     0          80                         *:3306                    *:*                   
LISTEN     0          128                        *:80                      *:*                   
LISTEN     0          128                     [::]:22                   [::]:*                   

配置apache 

 

[root@localhost /]# vim /etc/httpd24/httpd.conf 
[root@localhost /]# mkdir /usr/local/apache/htdocs/tengjia
[root@localhost /]# cd /usr/local/apache/htdocs/tengjia
[root@localhost tengjia]# cat << EOF > index.php
> <?php
>      phpinfo();
> ?>
> EOF
[root@localhost tengjia]# vim /etc/httpd24/extra/httpd-vhosts.conf 
[root@localhost tengjia]# service mysqld restart
Shutting down MySQL... SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@localhost tengjia]# systemctl restart php-fpm
[root@localhost tengjia]# systemctl restart httpd

效果图 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值