生产环境手工源码编译安装部署LAMP小记
1.环境所需软件包:
httpd-2.4.43.tar.gz | Apache 主程序包 | https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.43.tar.gz |
apr-1.7.0.tar.gz | Apache 依赖包 | https://mirror.bit.edu.cn/apache/apr/apr-1.7.0.tar.gz |
apr-util-1.6.1.tar.gz | Apache 依赖包 | https://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.gz |
pcre-8.44.tar.gz | Apache 依赖包 | https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.gz |
php-7.2.31.tar.gz | php 主程序包 | https://www.php.net/distributions/php-7.2.31.tar.gz |
mysql-5.7.30.tar.gz | mysql 主程序包 | https://downloads.mysql.com/archives/community/ |
2.安装编译工具和开发包
yum install -y epel-release
yum -y install make gcc gcc-c++ openssl openssl-devel expa-tdevel
3.1.编译安装依赖包apr
tar xf apr-1.7.0.tar.gz -C /usr/local/src/
cd /usr/local/src/apr-1.7.0/
./configure --prefix=/usr/local/apr
echo $?
make -j 4 && make install && cd
3.2.编译安装依赖包 apr-util
tar xf apr-util-1.6.1.tar.gz -C /usr/local/src/
cd /usr/local/src/apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make -j 4 && make install && cd
4. 编译安装依赖包 pcre
tar xf pcre-8.44.tar.gz -C /usr/local/src/
cd /usr/local/src/pcre-8.44/
./configure --prefix=/usr/local/pcre
make -j 4 && make install && cd
5.编译安装 Apache
tar zxvf httpd-2.4.43.tar.gz -C /usr/local/src/
cd /usr/local/src/httpd-2.4.43/
./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
make -j 4 && make install && cd
/usr/local/apache/bin/apachectl -V
选项说明:
- –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 路径
网站根目录位置:/usr/local/apache/htdocs/ 下
5.1 生成启动脚本
cp /usr/local/apache/bin/apachectl /etc/init.d/
chmod +x /etc/init.d/apachectl
5.2 生成apache启动脚本
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
#保存退出
chmod 754 /usr/lib/systemd/system/apache.service
systemctl start apache.service
启动脚本参考文章:https://www.cnblogs.com/q149072205/p/11541693.html
6.修改Apache默认运行用户
useradd -M -s /sbin/nologin apache
vim /usr/local/apache/conf/httpd.conf
166行默认用户和默认组改为apache
6.1 修改目录权限
chown -R apache:apache /usr/local/apache/
systemctl restart apache
7.安装配置MySQL数据库
useradd -M -s /sbin/nologin mysql
tar xf mysql-5.7.30-el7-x86_64.tar.gz
mv mysql-5.7.30-el7-x86_64 /usr/local/mysql
mkdir -p /data/mysql #创建存放数据的文件夹
touch /var/log/mysqld.log
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/
chown -R mysql:mysql /var/log/mysqld.log
7.1创建 mysql 配置文件
vim /etc/my.cnf
[client]
port = 3306
socket = /data/mysql/mysql.sock
[mysqld]
port = 3306
user = mysql
socket = /data/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
log-error=/var/log/mysqld.log
7.2 添加环境变量
vim /etc/profile.d/mysql.sh
MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/bin
source /etc/profile #使环境变量生效
7.3 初始化数据库
cd /usr/local/mysql/
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成临时密码
cat /var/log/mysqld.log |grep password
7.3 开机启动MySQL
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
/etc/init.d/mysqld start
7.4 修改mysql root密码
mysql -uroot -p'上面grep出来的'
mysql> set password for root@localhost = password('123123');
mysql> flush privileges; #刷新权限表
mysql> exit
7.5 运行安全初始化脚本
mysql_secure_installation
8.编译安装 php7.2
8.1 安装依赖
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
tar xf php-7.2.31.tar.gz -C /usr/local/src/
cd /usr/local/src/php-7.2.31/
./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
make -j 4 && make install && cd
参数注释:
–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 |
8.2 生成配置文件
cp /usr/local/src/php-7.2.31/php.ini-production /usr/local/php/etc/php.ini
8.3 使apache支持php文件
vim /usr/local/apache/conf/httpd.conf
# 393 行下面添加:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#保存退出
systemctl restart apache.service
9. 测试php是否可用
cd /usr/local/apache/htdocs/
vim index.php
<?php
phpinfo();
?>
systemctl restart apache
评论前必须登录!
立即登录 注册