部署LAMP架构

1、简介

1-1、什么是LAMP架构

LAMP=Linux + Apache + MySQL/MariaDB + PHP

LAMP和LNMP是两种网站解决方案,而LAMP注重安全、更强大,对php的运行较为稳定。LNMP注重性能,处理高并发能力强、负载高。

Apache本身只处理静态页面,动态页面由libphp5.so模块处理。

Apache工作原理:Apache 本身只处理 html 静态语言页面,当客户端需要访问 php 页面的时候,Apache
会调用libphp5.so 这个模块去工作,这个模块会把 php 页面转换成 html 静态页面,让 Apache
处理,Apache处理后,会返回给客户端。
在这里插入图片描述

2、部署LAMP架构(apache)

2-1、解决make依赖包

yum安装相关依赖包

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

2-2、下载源码包

下载源码包到/usr/local/src/目录下

链接:https://pan.baidu.com/s/1Qgt2ZppyakxOgBR_npR17g
提取码:8smn

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# ls
apr-1.6.2.tar.gz       libmcrypt-2.5.8.tar.gz  nginx-1.14.1.tar.gz
apr-util-1.6.0.tar.gz  mcrypt-2.6.8.tar.gz     pcre-8.41
boost_1_59_0           mhash-0.9.9.9.tar.gz    pcre-8.41.tar.gz
boost_1_59_0.tar.gz    mysql-5.7.19            php-7.1.24
httpd-2.4.37.tar.gz    mysql-5.7.19.tar.gz     php-7.1.24.tar.gz
libiconv-1.14.tar.gz   nginx-1.14.1

2-3、部署步骤

2-3-1、编译、编译安装依赖包apr

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xzvf apr-1.6.2.tar.gz 
[root@localhost src]# cd apr-1.6.2/
[root@localhost apr-1.6.2]# ./configure --prefix=/usr/local/apr/
[root@localhost apr-1.6.2]# make && make install

2-3-2、编译、编译安装依赖包apr-util

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xzvf apr-util-1.6.0.tar.gz
[root@localhost apr-util-1.6.0]# cd apr-util-1.6.0/
[root@localhost apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/bin/apr-1-config
[root@localhost apr-util-1.6.0]# make && make install

2-3-3、编译、编译安装依赖包pcre

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xzvf pcre-8.41.tar.gz
[root@localhost src]# cd pcre-8.41/
[root@localhost pcre-8.41]# ./configure --prefix=/usr/local/pcre/
[root@localhost pcre-8.41]# make && make install

2-3-4、编译、编译安装Apache

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xzvf httpd-2.4.37.tar.gz 
[root@localhost src]# cd httpd-2.4.37/
[root@localhost httpd-2.4.37]# ./configure --prefix=/usr/local/apache --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=event
[root@localhost httpd-2.4.37]# make && make install

对应指定目录配置

–prefix=/usr/local/apache ········ #安装路径
–enable-so ········ #支持动态加载模块
–enable-rewrite ········ #支持网站地址重写
–enable-ssl ········ #支持SSL加密
–with-pcre=/usr/local/pcre ········ pcre 路径
–with-apr=/usr/local/apr ········ apr路径
–with-apr-util=/usr/local/apr-util ········ apr-util路径

2-3-5、调整apache相关配置参数

生成启动脚本,即是把启动程序放到/etc/init.d/目录下

[root@localhost ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/
[root@localhost ~]# chmod +x /etc/init.d/apachectl

调整 Apache系统服务脚本

[root@localhost ~]# vim /usr/lib/systemd/system/apache.service
[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost ~]# chmod 754 /usr/lib/systemd/system/apache.service

2-3-6、启动apache服务

启动apache服务并加入开机启动项

[root@bogon init.d]# systemctl restart apache.service 
[root@bogon init.d]# systemctl enabled apache.service 
[root@bogon init.d]# systemctl status apache.service 
● apache.service - apache
   Loaded: loaded (/usr/lib/systemd/system/apache.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-07-16 20:34:48 CST; 7s ago
  Process: 109459 ExecStart=/etc/init.d/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 109462 (httpd)
    Tasks: 82
   CGroup: /system.slice/apache.service
           ├─109462 /usr/local/apache/bin/httpd -k start
           ├─109463 /usr/local/apache/bin/httpd -k start
           ├─109464 /usr/local/apache/bin/httpd -k start
           └─109465 /usr/local/apache/bin/httpd -k start

Jul 16 20:34:48 bogon systemd[1]: Starting apache...
Jul 16 20:34:48 bogon apachectl[109459]: AH00558: httpd: Could not reliably determine the server...sage
Jul 16 20:34:48 bogon systemd[1]: Started apache.
Hint: Some lines were ellipsized, use -l to show in full.

2-3-7、开放80端口

[root@bogon init.d]# firewall-cmd --permanent --add-port=80/tcp
success
[root@bogon init.d]# firewall-cmd --reload 
success

输入本机IP地址验证apache服务是否正常开启
在这里插入图片描述

3、部署LAMP架构(mysql)

3-1、解决安装环境依赖问题

删除系统自带的boost-、mysql和mariadb-

[root@localhost ~]# yum -y remove boost-* remove mysql mariadb-*

yum安装make依赖包

[root@localhost ~]# yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel

创建mysql用户

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

3-2、编译、编译安装依赖包mysql

解压mysql、boost

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# tar xzvf mysql-5.7.19.tar.gz
[root@localhost src]# tar xzvf boost_1_59_0.tar.gz
[root@localhost src]# ls
boost_1_59_0            mhash-0.9.9.9.tar.gz  pcre-8.41
boost_1_59_0.tar.gz     mysql-5.7.19          pcre-8.41.tar.gz
libiconv-1.14.tar.gz    mysql-5.7.19.tar.gz   php-7.1.24.tar.gz
libmcrypt-2.5.8.tar.gz  nginx-1.14.1
mcrypt-2.6.8.tar.gz     nginx-1.14.1.tar.gz

安装目录: /var/lib/mysql
数据目录: /var/lib/mysql/data

[root@localhost ~]# mkdir -p /var/lib/mysql/data
[root@localhost ~]# chown -R mysql:mysql /var/lib/mysql/
[root@localhost ~]# ll -d /var/lib/mysql/
drwxr-xr-x. 3 mysql mysql 18 6月  20 15:31 /var/lib/mysql/

编译前准备

[root@bogon src]# cd mysql-5.6.19/
[root@bogon mysql-5.6.19]# cmake -DCMAKE_INSTALL_PREFIX=/var/lib/mysql  -DMYSQL_DATADIR=/var/lib/mysql/data  -DSYSCONFDIR=/etc  -DWITH_MYISAM_STORAGE_ENGINE=1  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_MEMORY_STORAGE_ENGINE=1  -DWITH_READLINE=1  -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock  -DMYSQL_TCP_PORT=3306  -DENABLED_LOCAL_INFILE=1  -DWITH_PARTITION_STORAGE_ENGINE=1  -DEXTRA_CHARSETS=all  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DDOWNLOAD_BOOST=1  -DWITH_BOOST=/usr/local/src/boost_1_59_0

对应配置参数

#-DCMAKE_INSTALL_PREFIX=/var/lib/mysql 指定MySQL程序的安装目录,默认/usr/local/mysql
#-DMYSQL_DATADIR=/var/lib/mysql/data 数据文件目录
#-DSYSCONFDIR=/etc 初始化参数文件目录
#-DWITH_MYISAM_STORAGE_ENGINE=1 指定静态编译到 mysql 的存储引擎,MyISAM,MERGE
#-DWITH_INNOBASE_STORAGE_ENGINE=1
#-DWITH_MEMORY_STORAGE_ENGINE=1
#-DWITH_READLINE=1
#-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock socket文件路径,默认/tmp/mysql.sock
#-DMYSQL_TCP_PORT=3306 服务端口号,默认 3306
#-DENABLED_LOCAL_INFILE=1 指定是否允许本地执行
#-DWITH_PARTITION_STORAGE_ENGINE=1
#-DEXTRA_CHARSETS=all
#-DDEFAULT_CHARSET=utf8 指定服务器默认字符集,默认 latin1
#-DDEFAULT_COLLATION=utf8_general_ci 指定服务器默认的校对规则,默认 latin1_general_ci
#-DDOWNLOAD_BOOST=1
#-DWITH_BOOST=/usr/local/src/boost_1_59_0

生成二进制并安装

[root@bogon mysql-5.6.19]# make
[root@bogon mysql-5.6.19]# make install

3-3、修改mysql配置文件

[root@master ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
basedir=/var/lib/mysql
datadir=/var/lib/mysql/data
port=3306
socket=/var/lib/mysql/mysql.sock
character-set-server=utf8
log-error=/var/log/mysqld.log
pid-file=/tmp/mysqld.pid
[mysql]
socket=/var/lib/mysql/mysql.sock 
[client]
socket=/var/lib/mysql/mysql.sock

添加环境变量

[root@localhost ~]# vim /etc/profile.d/mysql.sh
export PATH=/var/lib/mysql/bin:$PATH

[root@master ~]# chmod +x /etc/profile.d/mysql.sh 
[root@master ~]# /etc/profile.d/mysql.sh 

生成服务启动脚本、初始化数据库

[root@localhost ~]# cp /var/lib/mysql/support-files/mysql.server /etc/init.d/mysqld

[root@localhost ~]# /var/lib/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data

启动mysql服务,加入开机启动项目

[root@localhost ~]# /etc/init.d/mysqld start
[root@localhost ~]# chkconfig --add mysqld 

若报错,删除数据目录下文件,重新初始化再启动服务

[root@localhost ~]# cd /var/lib/mysql/data/
[root@localhost data]# ls
auto.cnf  ib_buffer_pool  ibdata1  ib_logfile0  ib_logfile1
[root@localhost data]# rm -rf *
[root@localhost data]# /var/lib/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/var/lib/mysql --datadir=/var/lib/mysql/data
2020-07-18 12:14:47 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

[root@localhost data]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS! 

3-4、登录mysql并设置root用户密码

[root@localhost data]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.19 Source distribution

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

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> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> set password for root@localhost = password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

mysql> exit
Bye

4、部署LAMP架构(PHP)

4-1、解决环境依赖

添加epel服务的rpm包

[root@localhost ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Retrieving http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
warning: /var/tmp/rpm-tmp.xUH15R: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-7-12                ################################# [100%]

yum安装相关依赖包

[root@localhost ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel re2c php-pear

4-2、解压PHP安装包

[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar xzvf php-7.1.24.tar.gz 

4-3、PHP安装

4-3-1、编译前准备

指定php安装配置文件目录

[root@localhost src]# cd php-7.1.24/
[root@localhost php-7.1.24]# ./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring --with-curl --with-gd --enable-fpm --enable-mysqlnd --with-pdo-mysql=mysqlnd --with-config-file-path=/usr/local/php/etc/ --with-mysqli=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --enable-maintainer-zts

对应参数配置

--with-apxs2 #将 php 编译为 Apache 的一个模块进行使用
--enable-mbstring #多字节字符串的支持
--with-curl #支持 cURL
--with-gd #支持 gd 库
--enable-fpm #支持构建 fpm
--enable-mysqlnd #启用 mysqlnd
--with-pdo-mysql #支持 pdo:MySQL 支持
--with-config-file-path #设置配置文件路径
--with-mysqli #支持 MySQLi
--with-mysql-sock #关联 mysql 的 socket 文件
--enable-maintainer-zts #如果 Apache 是 event 模型,那需要指定 zts

4-3-2、生成二进制安装文件并安装

[root@localhost php-7.1.24]# make  && make install

4-4、修改PHP初始化配置

4-4-4、生成php自身配置文件

[root@localhost ~]# cp /usr/local/src/php-7.1.24/php.ini-production /usr/local/php/php.ini

4-4-5、编辑Apache的配置文件,以支持php

[root@localhostr ~]# vim /usr/local/apache/conf/httpd.conf 
393 AddType application/x-httpd-php .php
394 AddType application/x-httpd-php-source .phps

4-5、启动测试

重启apache服务

[root@localhost ~]# systemctl restart apache

创建测试php页面,开放80端口。

[root@localhost ~]# echo "<?php phpinfo(); ?>" > /usr/local/apache/htdocs/index.php
[root@localhost ~]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost ~]# firewall-cmd --reload 
success

打开浏览器输入http://172.20.10.7/index.php
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值