1 准备环境

1、配置ip地址

网络模式选用net模式
搭建LAMP环境 - 图1

  1. TYPE=Ethernet
  2. PROXY_METHOD=none
  3. BROWSER_ONLY=no
  4. BOOTPROTO=static
  5. DEFROUTE=yes
  6. IPV4_FAILURE_FATAL=no
  7. IPV6INIT=yes
  8. IPV6_AUTOCONF=yes
  9. IPV6_DEFROUTE=yes
  10. IPV6_FAILURE_FATAL=no
  11. IPV6_ADDR_GEN_MODE=stable-privacy
  12. NAME=ens33
  13. DEVICE=ens33
  14. ONBOOT=yes
  15. IPADDR=192.168.100.10
  16. NETMASK=255.255.255.0
  17. GATEWAY=192.168.100.2
  18. DNS1=8.8.8.8

2、关闭防护墙与selinux

搭建LAMP环境 - 图2

3、安装基本工具

vim bath-com net-tools
搭建LAMP环境 - 图3

4、上传lamp所需要的安装包到/usr/local/src/

搭建LAMP环境 - 图4

二、安装

1、安装mysql

1、解压缩
tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
搭建LAMP环境 - 图5
mv mysql-5.6.50-linux-glibc2.12-x86_64 /usr/local/mysql (mysql用于存放mysql的数据)
搭建LAMP环境 - 图6

2、 创建mysql用户

useradd -s /sbin/nologin mysql
搭建LAMP环境 - 图7
初始化数据库

3、 创建数据存放目录:

mkdir -p /data/mysql
搭建LAMP环境 - 图8

4、 修改权限:

chown -R mysql:mysql /data/mysql
搭建LAMP环境 - 图9

5、 安装perl环境:

yum install -y perl-Module-Install
搭建LAMP环境 - 图10

6、 执行脚本

./scripts/mysql_install_db —user=mysql —datadir=/data/mysql
—user 是指定MySQL用户 —-datadir 是指定数据存放目录
搭建LAMP环境 - 图11
配置文件

7、 拷贝:

cp support-files/my-default.cnf /etc/my.cnf
搭建LAMP环境 - 图12

8、 修改文件:

搭建LAMP环境 - 图13
basedir = /usr/local/mysql/ MySQL安装的目录
datadir = /data/mysql MySQL数据存放的目录
port = 3306 mysql的端口号
server_id = 155 集群id
socket = /tmp/mysql.sock
搭建LAMP环境 - 图14
配置启动脚本文件

9、 拷贝:

cp support-files/mysql.server /etc/init.d/mysqld
搭建LAMP环境 - 图15

10、 修改文件:

搭建LAMP环境 - 图16
basedir=/usr/local/mysql/
datadir=/data/mysql
搭建LAMP环境 - 图17
设置mysql 开启mysql
1、把启动脚本加入到系统服务中:
chkconfig —add mysqld
chkconfig mysqld on
搭建LAMP环境 - 图18
2、启动mysql
service mysqld start
搭建LAMP环境 - 图19

11、 查看进程

ps -ef |grep mysqld
搭建LAMP环境 - 图20

12、查看端口 显示3306成功

image.png

2、安装apache

1、解压安装包
tar -zxvf apr-1.6.5.tar.gz
搭建LAMP环境 - 图22
tar -zxvf apr-util-1.6.1.tar.gz
搭建LAMP环境 - 图23
tar -zxvf httpd-2.4.46.tar.gz
搭建LAMP环境 - 图24

2、切换目录

cd apr-1.6.5/
搭建LAMP环境 - 图25

3、 编译:

./configure —prefix=/usr/local/apr
搭建LAMP环境 - 图26

  1. 报错安装:

yum install libtool* -y
搭建LAMP环境 - 图27

4、 安装make:

make && make install
搭建LAMP环境 - 图28

5、切换目录

cd apr-util-1.6.1/
搭建LAMP环境 - 图29

6、编译

./configure —prefix=/usr/local/apr-util —with-apr=/usr/local/apr
搭建LAMP环境 - 图30

7、安装make

make && make install
搭建LAMP环境 - 图31

8、报错安装

yum install -y expat-devel
搭建LAMP环境 - 图32

9、切换目录

cd httpd-2.4.46/
搭建LAMP环境 - 图33

10、编译

./configure \
—prefix=/usr/local/apache2.4 \ 安装目录
—with-apr=/usr/local/apr \ 依赖
—with-apr-util=/usr/local/apr-util \ 依赖
—enable-so \ 支持动态扩展模块 后缀:.so
—enable-mods-shared=most 支持多个动态扩展模块
搭建LAMP环境 - 图34

11、报错安装:

yum install -y prce-devel
搭建LAMP环境 - 图35

12、安装make

make&&make install
搭建LAMP环境 - 图36
报错有两种办法

13、先 make clean 然后把apr和apr-util复制到htpp下的srclib目录下 然后重新make

make&&make install
搭建LAMP环境 - 图37
搭建LAMP环境 - 图38

14、 如果上述不行 重新执行./configure

./configure —prefix=/usr/local/apache2.4 —enable-so —with-pcre —with-included-apr —enable-modules=most —enable-mpms-shared=all —with-mpm=prefork
搭建LAMP环境 - 图39

3、安装PHP

1、解压
tar -zxvf php-5.6.30
搭建LAMP环境 - 图40

2、切换目录

cd php-5.6.30
搭建LAMP环境 - 图41

3、配置

./configure —prefix=/usr/local/php —with-apxs2=/usr/local/apache2.4/bin/apxs —with-config-file-path=/usr/local/php/etc —with-mysql=/usr/local/mysql —with-pdo-mysql=/usr/local/mysql —with-mysqli=/usr/local/mysql/bin/mysql_config —with-libxml-dir —with-gd —with-gd —with-png-dir —with-freetype-dir —with-iconv-dir —with-zlib-dir —with-bz2 —with-openssl —with-mcrypt —enable-soap —enable-gd-native-ttf —enable-mbstring —enable-sockets —enable-exif
搭建LAMP环境 - 图42

4、报错安装

yum install libxml2-devel bzip2 bzip2-level libpng libpng-devel openssl openssl-devel freetype freetype-devel epel-release libmcrypt-devel -y
搭建LAMP环境 - 图43

5、安装make

make&&make install
搭建LAMP环境 - 图44

6、验证是否成功

image.png

4、httpd解析php

1、切换目录
cd /usr/local/apache2.4/conf/
搭建LAMP环境 - 图46

2、修改配置文件

vim /usr/local/apache2.4/conf/httpd.conf
搭建LAMP环境 - 图47
搜索ServerName,把ServerName www.example.com:80前#去掉
搭建LAMP环境 - 图48
搜索Require,把Require all denied改为Require all granted 允许所有请求访问
搭建LAMP环境 - 图49
搜索AddType application/x-gzip .gz .tgz 在下面添加一行
AddType application/x-httpd-php .php
搭建LAMP环境 - 图50
搜索Index,在DirectoryIndex index.html后面添加index.php
搭建LAMP环境 - 图51

3、 测试apache服务:

/usr/local/apache2.4/bin/apachectl -t
搭建LAMP环境 - 图52

4、 重新加载

/usr/local/apache2.4/bin/apachectl graceful
搭建LAMP环境 - 图53

5、 杀掉进程 重新启动

/usr/local/apache2.4/bin/apachectl start
搭建LAMP环境 - 图54

6、 测试PHP

vim /usr/local/apache2.4/htodcs/test.php //增加如下内容

<?php
echo 123;
?>
搭建LAMP环境 - 图55
搭建LAMP环境 - 图56
curl localhost/test.php
搭建LAMP环境 - 图57

至此 lamp环境搭建完成