1,关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
2,导入yum网络源
#部署lamp-apache
#安装需要的工具包
echo "正在安装需要的工具包,请稍等..."
yum -y install bzip2 vim make wget openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ libxml2-devel
cd /opt
导入apr apr-utils httpd mysql php四个压缩包
3,解压并安装apr包
cd /opt
tar -xzf apr-1.7.0.tar.gz
cd /opt/apr-1.7.0
sed -i '/$RM "$cfgfile"/d' configure
3.1 vim /configure
删除:/$RM "$cfgfile
./configure --prefix=/usr/local/apr
make
make install
4,安装apr-util
cd /opt
tar -xzf apr-util-1.6.1.tar.gz
cd /opt/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install
5,安装httpd
cd /opt
tar -xzf httpd-2.4.54.tar.gz
cd /opt/httpd-2.4.54
./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
make
make install
cd
/usr/local/apache/bin/apachectl start
6,部署lamp-mysql
6.1 创建mysql用户
useradd -r -M -s /sbin/nologin mysql
6.2 安装依赖包
yum -y install libncurses*
6.3 配置mysql
tar -xzf /opt/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
ln -sv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
mkdir -p /opt/data
chown -R mysql.mysql /opt/data/
yum -y install libaio
6.4 数据库初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data/
ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
6.5 编辑mysql配置文件
vim /etc/my.cnf
[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
sed -ri "s#^(basedir=).*#\1/usr/local/mysql#g" /usr/local/mysql/support-files/mysql.server
sed -ri "s#^(datadir=).*#\1/opt/data#g" /usr/local/mysql/support-files/mysql.server
6.5.1 vim /usr/local/mysql/support-files/mysql.server
写入
basedir=/usr/local/mysql
datadir=/opt/data
6.6 定义mysql服务可以使用systemd来进行管理
vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=mysql 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
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable --now mysqld
6.7 设置数据库密码
/usr/local/mysql/bin/mysql -uroot -e "set password=password('redhat')"
6.8 做一个链接,添加mysql命令的变量到环境变量
echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
source /etc/profile
7,部署lamp-php
7.1 安装依赖包,安装GD库和GD库关联程序,用来处理和生成图片
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel
7.2 解压php包文件
cd /opt
tar -xjvf php-7.1.10.tar.bz2
7.3 配置编译安装php
cd php-7.1.10
./configure \
--prefix=/usr/local/php \ #指定将 PHP 程序的安装路径
--with-apxs2=/usr/local/apache/bin/apxs \ #指定Apache httpd服务提供的apxs 模块支持程序的文件位置
--with-mysql-sock=/tmp/mysql.sock \ #指定mysql 数据库连接文件的存储路径
--with-mysqli \ #添加 MySQL 扩展支持 #mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定
--with-zlib \ #支持zlib功能,提供数据压缩
--with-curl \ #开启curl扩展功能,实现http的get下载和post请求方法
--with-gd \ #激活gd库的支持
--with-jpeg-dir \ #激活jpeg的支持
--with-png-dir \ #激活png的支持
--with-freetype-dir \
--with-openssl \
--enable-mbstring \ #启动多字节字符串功能,以便支持中文等代码
--enable-xml \ #开启扩展性标记语言模块
--enable-session \ #会话
--enable-ftp \ #文本传输协议
--enable-pdo \ #函数库
--enable-tokenizer \ #令牌解释器
--enable-zip #zip压缩格式
make
make install
#配置php
7.4 测试环境时使用php.ini-development文件,生产环境使用php.ini-production文件
cp php.ini-development /usr/local/php/lib/php.ini
7.5 修改php配置文件,设置时区
sed -i 's/;date.timezone =/date\.timezone = \Asia\/Shanghai/' /usr/local/php/lib/php.ini
或vim /usr/local/php/lib/php.ini
date.timezone =\Asia\/Shanghai
7.6 修改httpd服务配置文件,让apache支持php
最后两行写入:
echo "AddType application/x-httpd-php .php" >> /etc/httpd24/httpd.conf
echo "AddType application/x-httpd-php-source .phps" >> /etc/httpd24/httpd.conf
sed -i 's/index.html/index\.php index\.html/' /etc/httpd24/httpd.conf
7.7 验证php测试页
rm -rf /usr/local/apache/htdocs/index.html
7.8 写入测试网页
vim /usr/local/apache/htdocs/index.php
<?php
phpinfo();
?>
7.9 启动apache服务
/usr/local/apache/bin/apachectl stop
/usr/local/apache/bin/apachectl start
