#!/bin/bash
if [ $UID -ne 0 ];then
echo "请以管理员用户进行执行"
exit
fi
script_path=$(pwd)
port=3306
apache_version=2.4.54
install_dir=/usr/local/apache
id apache &> /dev/null
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin apache
else
echo "用户已存在"
fi
yum -y install epel-release --allowerasing && \
dnf groups mark install 'Development Tools' -y
dnf -y install openssl-devel pcre-devel expat-devel libtool gcc gcc-c++ wget vim make --allowerasing
dnf -y install ncurses-devel openssl-devel openssl cmake mariadb-devel --allowerasing
dnf -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd ncurses-compat-libs libsqlite3x-devel libzip-devel perl --allowerasing
tar xf files/apr-1.7.0.tar.gz -C /tmp/
tar xf files/apr-util-1.6.1.tar.gz -C /tmp/
tar xf files/httpd-$apache_version.tar.gz -C /tmp/
cd /tmp/apr-1.7.0
if [ ! -d /usr/local/apr ];then
sed -i '/$RM "$cfgfile"/d' configure
./configure --prefix=/usr/local/apr && \
make && make install
else
ls /usr/local
echo "apr 编译安装完成"
fi
cd ../apr-util-1.6.1/
if [ ! -d /usr/local/apr-util ];then
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && \
make && make install
else
ls /usr/local/
echo "apr-util 编译安装完成"
fi
cd ../httpd-$apache_version/
if [ ! -d ${install_dir} ];then
./configure --prefix=${install_dir} \
--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
else
ls ${install_dir}
echo "httpd 编译安装完成"
fi
echo "export PATH=${install_dir}/bin:\$PATH" > /etc/profile.d/apache.sh
ln -s ${install_dir}/include /usr/include/apache &> /dev/null
grep 'apache' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
sed -i "22a MANDATORY_MANPATH ${install_dir}/man" /etc/man_db.conf
fi
cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=httpd server daemon
After=network.target
[Service]
Type=forking
ExecStart=${install_dir}/bin/apachectl start
ExecStop=${install_dir}/bin/apachectl stop
ExecReload=/bin/kill -HUP \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now httpd
ss -antl
yum install -y libxml2-devel --allowerasing
yum install -y sqlite-devel --allowerasing
yum install bzip2 bzip2-devel -y --allowerasing
yum install -y libcurl-devel.x86_64 --allowerasing
yum install -y gd-devel --allowerasing
yum config-manager --set-enabled PowerTools --allowerasing
yum -y install oniguruma oniguruma-devel --allowerasing
yum -y install readline-devel --allowerasing
passwd=123456
id mysql &> /dev/null
if [ $? -ne 0 ];then
useradd -r -M -s /sbin/nologin mysql
else
echo "用户已存在"
fi
if [ ! -d /usr/local/mysql ];then
echo "解压软件包"
tar xf ${script_path}/files/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local
cd /usr/local
mv mysql-5.7.38-linux-glibc2.12-x86_64 mysql
fi
chown -R mysql.mysql /usr/local/mysql
echo 'export PATH=/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
ln -s /usr/local/mysql/include /usr/include/mysql
echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
grep '/usr/local/mysql/man' /etc/man_db.conf &> /dev/null
if [ $? -ne 0 ];then
sed -i "22a MANDATORY_MANPATH /usr/local/mysql/man" /etc/man_db.conf
fi
if [ -d /opt/JL ];then
mkdir -p /opt/JL
fi
chown -R mysql.mysql /opt/JL
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/JL &> /tmp/passwd
password=$(grep 'password' /tmp/passwd |awk '{print $NF}')
cat > /etc/my.cnf << EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/JL
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/JL/mysql.pid
user = mysql
skip-name-resolve
EOF
if [ ! -d /etc/init.d ];then
mkdir -p /etc/init.d
fi
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /etc/init.d/mysqld
sed -ri 's#^(datadir=).*#\1/opt/JL#g' /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
service mysqld start
sleep 6
chkconfig --add mysqld
/usr/local/mysql/bin/mysql -uroot -p"$password" --connect-expired-password -e "set password = password('$passwd');"
echo "数据库的密码是: $passwd"
ss -antl
yum remove libzip -y
php_install_dir=/usr/local/php7
if [ ! -d /usr/src/php-7.4.29 ];then
echo "正在解压"
tar xf ${script_path}/files/php-7.4.29.tar.gz -C /usr/src
else
ls /usr/src/php-7.4.29
sleep
echo "php已解压"
fi
if [ ! -d /usr/src/libzip-1.3.2 ];then
tar xf ${script_path}/files/libzip-1.3.2.tar.gz -C /usr/src
else
ls /usr/src/libzip-1.3.2
sleep
echo "libzip已解压"
fi
if [ ! -d libzip-1.3.2 ];then
cd /usr/src/libzip-1.3.2
./configure && make && make install
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/"
else
echo "libzip已安装"
fi
if [ ! -d php-7.4.29 ];then
cd /usr/src/php-7.4.29
./configure --prefix=$php_install_dir \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix && \
make && make install
else
ls $php_install_dir
sleep 3
echo "PHP编译安装完成"
fi
echo "export PATH=${php_install_dir}/bin:${php_install_dir}/:sbin:\$PATH" > /etc/profile.d/php7.sh
echo "${php_install_dir}/lib" > /etc/ld.so.conf.d/php.conf
ldconfig
sleep 2
ln -s ${php_install_dir}/include /usr/include/php &> /dev/null
cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/rc.d/init.d/php-fpm
cd ${php_install_dir}/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
service php-fpm start
chkconfig --add php-fpm
echo "PHP安装完成."
sleep 3
ss -antl
cat > ${install_dir}/htdocs/index.php <<EOF
<?php
phpinfo();
?>
EOF
cat > ${install_dir}/conf/extra/vhosts.conf <<EOF
<VirtualHost *:80>
DocumentRoot "${install_dir}/htdocs"
ServerName JL.example.com
ErrorLog "logs/JL.example.com-error_log"
CustomLog "logs/JL.example.com-access_log" common
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000${install_dir}/htdocs/\$1
<Directory "${install_dir}/htdocs">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
EOF
grep 'AddType application/x-httpd-php .php' ${install_dir}/conf/httpd.conf &> /dev/null
if [ $? -ne 0 ];then
sed -i '/\bAddType.*.gz .tgz/a \ AddType application/x-httpd-php .php' ${install_dir}/conf/httpd.conf
fi
grep 'AddType application/x-httpd-php-source .phps' ${install_dir}/conf/httpd.conf &> /dev/null
if [ $? -ne 0 ];then
sed -i '/\bAddType.*.php/a \ AddType application/x-httpd-php-source .phps' ${install_dir}/conf/httpd.conf
fi
sed -i '/index.html/c \ DirectoryIndex index.php index.html' ${install_dir}/conf/httpd.conf
sed -i '/proxy_module/s/#//g' ${install_dir}/conf/httpd.conf
sed -i '/proxy_fcgi_module/s/#//g' ${install_dir}/conf/httpd.conf
grep 'Include conf/extra/vhosts.conf' ${install_dir}/conf/httpd.conf &> /dev/null
if [ $? -ne 0 ];then
echo 'Include conf/extra/vhosts.conf' >> ${install_dir}/conf/httpd.conf
fi
chown -R apache.apache ${install_dir}
systemctl restart httpd
service mysqld restart
service php-fpm restart
sleep 3
ss -antl
firewall-cmd --add-rich-rule 'rule family=ipv4 source address=0.0.0.0/0 port port=80 protocol=tcp accept' --permanent &> /dev/null
firewall-cmd --reload
安装脚本链接:https://www.aliyundrive.com/s/FfAx1Vqavm3
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通