lamp架构部署

  • amp平台软件安装次序:

    httpd --> mysql --> php
    安装httpd

配置源和工具

[root@localhost ~]# yum -y install epel-release vim wget

安装开发工具包

[root@localhost ~]# yum groups mark install 'Development Tools'

安装编译工具

[root@localhost ~]# yum -y install openssl-devel pcre-devel pcre  expat-devel libtool gcc gcc-c++ 

创建apache服务的用户和组

[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -s /sbin/nologin -g apache apache 
下载软件包并解压

#依赖包apr
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.7.0.tar.gz 
[root@localhost src]# tar -xf apr-1.7.0.tar.gz

#依赖包apr-util
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz 
[root@localhost src]# tar -xf apr-util-1.6.1.tar.gz

#软件包httpd
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.49.tar.gz
[root@localhost src]# tar -xf httpd-2.4.49.tar.gz

#查看
[root@localhost src]# ls
apr-1.7.0         apr-util-1.6.1         debug         httpd-2.4.49.tar.gz
apr-1.7.0.tar.gz  apr-util-1.6.1.tar.gz  httpd-2.4.49  kernels

安装依赖包apr

#删除configure中此行
[root@localhost src]# cd apr-1.7.0
[root@localhost apr-1.7.0]# sed -i '/$RM "$cfgfile"/d' configure
#安装
[root@localhost apr-1.7.0]# ./configure --prefix=/usr/local/apr
过程太长省略...
[root@localhost apr-1.7.0]# make && make install

安装依赖包apr-util

#安装
[root@localhost apr-1.7.0]# cd ../apr-util-1.6.1
[root@localhost apr-util-1.6.1]#  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
过程太长省略...
[root@localhost apr-util-1.6.1]# make && make install

安装软件包httpd

#安装
[root@localhost apr-util-1.6.1]# cd ../httpd-2.4.49
[root@localhost httpd-2.4.49]# ./configure --prefix=/usr/local/apache \
--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

[root@localhost httpd-2.4.49]# make && make install

配置
```go

#配置环境变量
[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 

```go
编写服务启动文件service文件

#编写service文件
[root@localhost ~]# vim /usr/lib/systemd/system/httpd.service
[Unit]
Description=Httpd server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/httpd/bin/apachectl start
ExecStop=/usr/local/httpd/bin/apachectl stop

[Install]
WantedBy=multi-user.target

#重新加载
[root@localhost ~]# systemctl  daemon-reload

[root@localhost ~]# systemctl  enable --now httpd
[root@localhost ~]# systemctl  status httpd
● httpd.service - httpd server daemon
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-09-23 16:23:24 CST; 6s ago
  Process: 378971 ExecStop=/usr/local/httpd/bin/apachectl stop (code=exited, status=0/SUCCESS)
  Process: 379133 ExecStart=/usr/local/httpd/bin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 379136 (httpd)
    Tasks: 82 (limit: 23790)
   Memory: 23.4M
   CGroup: /system.slice/httpd.service
           ├─379136 /usr/local/httpd/bin/httpd -k start
           ├─379137 /usr/local/httpd/bin/httpd -k start
           ├─379138 /usr/local/httpd/bin/httpd -k start
           └─379139 /usr/local/httpd/bin/httpd -k start

923 16:23:24 localhost.localdomain systemd[1]: Starting httpd server daemon...
923 16:23:24 localhost.localdomain systemd[1]: Started httpd server daemon.
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       

安装mysql

安装依赖包

[root@localhost ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs
    

创建用户和组

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


下载二进制格式的mysql软件包

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz

 
解压软件至/usr/local/

#解压
[root@localhost src]# ls
debug  kernels  mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz
[root@localhost src]# tar xf mysql-5.7.35-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ls /usr/local/
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.35-linux-glibc2.12-x86_64  share
#软连接
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.7.35-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.35-linux-glibc2.12-x86_64/'
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root  root    6 812 2018 bin
drwxr-xr-x. 2 root  root    6 812 2018 etc
drwxr-xr-x. 2 root  root    6 812 2018 games
drwxr-xr-x. 2 root  root    6 812 2018 include
drwxr-xr-x. 2 root  root    6 812 2018 lib
drwxr-xr-x. 2 root  root    6 812 2018 lib64
drwxr-xr-x. 2 root  root    6 812 2018 libexec
lrwxrwxrwx. 1 root  root   36 923 16:39 mysql -> mysql-5.7.35-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 923 16:38 mysql-5.7.35-linux-glibc2.12-x86_64
drwxr-xr-x. 2 root  root    6 812 2018 sbin
drwxr-xr-x. 5 root  root   49 718 10:33 share
drwxr-xr-x. 2 root  root    6 812 2018 src


修改目录/usr/local/mysql的属主属组


[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql
[root@localhost ~]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 923 16:39 /usr/local/mysql -> mysql-5.7.35-linux-glibc2.12-x86_64/


添加环境变量

[root@localhost ~]# ls /usr/local/mysql
bin  docs  include  lib  LICENSE  man  README  share  support-files
[root@localhost ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@localhost ~]# . /etc/profile.d/mysql.sh
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


创建数据存放目录

[root@localhost ~]# mkdir -p /opt/data
[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/
总用量 0
drwxr-xr-x. 2 mysql mysql 6 923 16:46 data

 
初始化数据库

#请注意这种方法初始化完成后是没有密码的
[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
2021-09-23T08:48:41.261781Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-09-23T08:48:41.438873Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-09-23T08:48:41.459162Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-09-23T08:48:41.527098Z 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: 0d70e7f6-1c4b-11ec-a20e-000c2984a301.
2021-09-23T08:48:41.528205Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-09-23T08:48:42.036191Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2021-09-23T08:48:42.036204Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2021-09-23T08:48:42.036605Z 0 [Warning] CA certificate ca.pem is self signed.
2021-09-23T08:48:42.238241Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

 

配置mysql

[root@localhost ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ ->/usr/local/mysql/include/[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@localhost ~]# ldconfig     


生成配置文件

[root@localhost ~]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF


配置service服务启动文件

[root@localhost ~]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /usr/local/mysql/support-files/mysql.server
[root@localhost ~]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /usr/local/mysql/support-files/mysql.server

[root@localhost ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=Mysqld server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop

[Install]
WantedBy=multi-user.target

#重新加载
[root@localhost ~]# systemctl  daemon-reload

#启动mysql
[root@localhost ~]# systemctl  start mysqld
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         80                         *:3306                    *:*       
LISTEN    0         128                     [::]:22                   [::]:*     


修改密码

#登录
[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.35 MySQL Community Server (GPL)

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> 

#设置新密码
mysql> set password = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit
Bye


安装php

安装依赖包

[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel  pcre-devel freetype freetype-devel gmp   gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt      libxslt-devel mhash mhash-devel php-mysqlnd libzip-devel libsqlite3x libsqlite3x-devel oniguruma   libzip-devel    https://repo.almalinux.org/almalinux/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
安装过程略....

下载php软件包

[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://www.php.net/distributions/php-8.0.10.tar.gz
下载过程略....

编译

[root@localhost ~]# cd /usr/src/php-8.0.10
[root@localhost php-8.0.10]# ./configure --prefix=/usr/local/php8  \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix


安装

[root@localhost php-8.0.10]# make install
配置环境变量

[root@localhost ~]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh 
[root@localhost ~]# source /etc/profile.d/php.sh

生成配置文件

[root@localhost ~]# cd /usr/src/php-8.0.10
[root@localhost php-8.0.10]# cp php.ini-production  /etc/php.ini
[root@localhost php-8.0.10]# cp sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm
[root@localhost ~]# chmod +x /etc/rc.d/init.d/php-fpm
[root@localhost ~]# cd /usr/local/php8/etc/
[root@localhost etc]# cp php-fpm.conf.default  php-fpm.conf
[root@localhost etc]# cd php-fpm.d/
[root@localhost php-fpm.d]# cp www.conf.default  www.conf

配置service文件

[root@localhost ~]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=Php-fpm server daemon
After=network.target

[Service]
Type=forking
ExecStart=service php-fpm start
ExecStop=service php-fpm stop

[Install]
WantedBy=multi-user.target

#重新加载
[root@localhost ~]# systemctl  daemon-reload


启动服务

[root@localhost ~]# systemctl start php-fpm.service
[root@localhost ~]# ss -antl
State     Recv-Q    Send-Q         Local Address:Port         Peer Address:Port    
LISTEN    0         128                127.0.0.1:9000              0.0.0.0:*       
LISTEN    0         128                  0.0.0.0:22                0.0.0.0:*       
LISTEN    0         80                         *:3306                    *:*       
LISTEN    0         128                        *:80                      *:*       
LISTEN    0         128                     [::]:22                   [::]:*       


配置httpd配置文件

启动代理模块

#取消注释
[root@localhost ~]# sed -i '/proxy_module/s/#//g' /usr/local/httpd/conf/httpd.conf
[root@localhost ~]# sed -i '/proxy_fcgi_module/s/#//g' /usr/local/httpd/conf/httpd.conf
配置虚拟主机

#创建站点目录
[root@localhost ~]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# mkdir  example
[root@localhost htdocs]# cd example/
[root@localhost example]# vim index.php
<?php
   phpinfo();
?>
[root@localhost example]# chown -R apache.apache /usr/local/httpd/htdocs/


#在配置文件的最后加入以下内容
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf

<VirtualHost *:80>
    DocumentRoot "/usr/local/httpd/htdocs/example"
    ServerName www.test.com
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/httpd/htdocs/example/$1
    <Directory "/usr/local/httpd/htdocs/example">
        Options none
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>  


#搜索AddType,添加以下内容
[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php        #添加此行
    AddType application/x-httpd-php-source .phps        #添加此行


#添加index.php
[root@localhost ~]# sed -i '/    DirectoryIndex/s/index.html/index.php index.html/g' /usr/local/httpd/conf/httpd.conf
//重启apache
[root@localhost ~]#  systemctl restart httpd

这里的图是做zabbix后补的,因为php8版本不兼容只能用php7的版本

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值