准备工具
httpd:apr-1.7.0.tar.gz,apr-util-1.6.1.tar.gz,httpd-2.4.39.tar.bz 所有源码包
mysql:mariadb-10.2.23.tar.gz源码包
php:php-7.3.5tar.bz2源码包
以上所有源码包存,以及一键安装脚本存放在root家目录下,运行一键安装脚本。
脚本运行完毕,使用浏览器访问测试页
一键安装脚本
#!/bin/bash
LINE=12 #编译时线程数
APR=apr-1.7.0 #APR源码包版本号
APRUTIL=apr-util-1.6.1 #APR-UTIL源码包版本号
HTTPD=httpd-2.4.39 #httpd源码包版本号
MYSQL=mariadb-10.2.23 #MySQL源码包版本号
PHP=php-7.3.5 #PHP源码包版本号
# 预安装环境
yum install -y gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel bzip2 vim lrzsz tree screen lsof tcpdump wget ntpdate net-tools iotop bc zip unzip nfs-utils expat-devel bison bison-devel zlib-devel libcurl-devel libarchive-devel boostdevel cmake ncurses-devel gnutls-devel libxml2-devel libevent-devel libaio-devel
# 安装httpd
## 解压apr,apr-util,httpd
tar xf ~/${APR}.tar.gz
tar xf ~/${APRUTIL}.tar.gz
tar xf ~/${HTTPD}.tar.bz2
## 将apr,apr-util移动至srclib
mv ~/$APR ~/$HTTPD/srclib/apr
mv ~/$APRUTIL ~/$HTTPD/srclib/apr-util
## 编译安装
cd $HTTPD
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr=/root/httpd-2.4.39/srclib/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make -j $LINE && make install
## 创建apache用户
useradd -r -s /sbin/nologin apache
## 修改配置文件
sed -i ‘/^User/s/.*/User apache/‘ /app/httpd24/conf/httpd.conf
sed -i ‘/^Group/s/.*/Group apache/‘ /app/httpd24/conf/httpd.conf
## 添加PATH变量
echo ‘PATH=/app/httpd24/bin:$PATH‘ > /etc/profile.d/httpd.sh
## 设置开机启动
echo "/app/httpd24/bin/apachectl start" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
## 清除源码包
rm -rf /root/$HTTPD
# 安装MySQL
## 创建MySQL用户
useradd -r -s /sbin/nologin mysql
## 创建MySQL数据库目录
mkdir -p /data/mysql
chown -R mysql.mysql /data/mysql
chmod 700 /data/mysql
## 解压MySQL源码包
tar xf ~/${MYSQL}.tar.gz -C /data
## 编译安装
cd /data/${MYSQL}
cmake . -DCMAKE_INSTALL_PREFIX=/app/mysql -DMYSQL_DATADIR=/data/mysql/ -DSYSCONFDIR=/etc/mysql -DMYSQL_USER=mysql -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITHOUT_MROONGA_STORAGE_ENGINE=1 -DWITH_DEBUG=0 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make -j $LINE && make install
## 配置文件相关
mkdir /etc/mysql
cp /app/mysql/support-files/my-huge.cnf /etc/mysql/my.cnf
sed -i ‘/\[mysqld\]/adatadir=/data/mysql‘ /etc/mysql/my.cnf
## 设置开机启动
cp /app/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
## 设置PATH变量
echo ‘PATH=/app/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
## 清除源码包
rm -rf /data/$MYSQL
## 初始化数据库
/app/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql
# 安装PHP
## 解压php源码包
cd
tar xf ~/${PHP}.tar.bz2
## 编译安装
cd ~/${PHP}
./configure --prefix=/app/php --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets --enable-fpm --enable-maintainer-zts --disable-fileinfo
make -j $LINE && make install
## 复制启动配置文件并修改
cp ~/$PHP/php.ini-production /etc/php.ini
sed -i ‘/;date.tim/[email protected]*@data.timezone = "Asia/Shanghai"@‘ /etc/php.ini
## 设置开机启动
cp ~/$PHP/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
## 复制配置文件模板
cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
cp /app/php/etc/php-fpm.d/www.conf.default /app/php/etc/php-fpm.d/www.conf
## 清除源码包
rm -rf /root/$PHP
# LAMP配置
## 配置httpd
sed -i ‘/mod_proxy.so/s/#\(.*\)/\1/‘ /app/httpd24/conf/httpd.conf
sed -i ‘/fcgi.so/s/#\(.*\)/\1/‘ /app/httpd24/conf/httpd.conf
sed -i ‘/ DirectoryIndex/s/.*/ DirectoryIndex index.php index.html/‘ /app/httpd24/conf/httpd.conf
cat << EOF >> /app/httpd24/conf/httpd.conf
addtype application/x-httpd-php .php
addtype application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/test/$1
EOF
## 配置php
# 生成测试页
mkdir -pv /data/test
cat << EOF >> /data/test/index.php
<?php
\$dsn=‘mysql:host=127.0.0.1;dbname=test‘;
\$username=‘root‘; \$passwd=‘‘;
\$dbh=new PDO(\$dsn,\$username,\$passwd);
var_dump(\$dbh);
phpinfo();
?>
EOF
# 启动服务
service mysqld start
/app/httpd24/bin/apachectl start
service php-fpm start
原文地址:https://blog.51cto.com/11886307/2395020
时间: 2024-10-07 01:37:34