コンパイルとインストールPHP + Apache環境

コンパイルとインストールPHP + Apache環境

注意事項:

1、主にApacheで、これだけのapacheユーザの作成を開始

スクリプト

#!/ binに/ bashRED = "\ 033 [0; 31メートル" GREEN = "\ 033 [0; 32メートル" NO_COLOR = "\ 033 [0メートル" PREFIX =は/ usr / local / PHPの#这个还是别改了、好多地方要改SYSCONFDIR = 
SRC =は/ usr / src 
FLAG = $ 1CPUS = `猫の/ proc / cpuinfoの| grepの"物理ID" | 並べ替え| UNIQ | WC -l` 
CORE = `猫の/ proc / cpuinfoの| grepの"CPUコア" | UNIQ | AWK '{$ 4印刷}' ` 
J = $(($ {CPUS} * $ {CORE}))
FILEURL = 'HTTP://ftp.ntu.edu.tw/pub/php/distributions/php-7.3.10 .tar.gzの'#判断是不是rootjudge_root(){ 
    [$(のid -u)= "0"!] && {エコー-e「$ {RED}エラー:$ {NO_COLOR}このスクリプトを実行するには、rootでなければなりません。 "; 1番出口; }    
}#ダウンロードdownload_source(){CD 
    yumをインストールwgetの-y 
    wgetの$ {} FILEURL 
    あれば[!"$?" -eq 0];
    / usr / sbinに/ groupaddの-g 48 -rアパッチ2>を/ dev / null || 
    は/ usr / sbinに/ useraddの-c "アパッチ" -u 48 -gのapache \ 
    -s / sbinに/ nologinに-r -dは、/ usr / share / httpdのapacheの2>を/ dev / null || :  
    #EPEL 
    のwget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 
    のyumのgccのopenssl-develのインストールPCRE-develのlibnghttp2-develのncursesの-develのlbzip2 bzip2のexpatの-develののlibxml2-develのののlibxml2のautoconfのlibtoolを-y 
    タールXFのphp-7.3.10.tar.gz -C $ {SRC} / CDの$ {SRC} /php-7.3.10/
    ./configure --prefix =は/ usr / local / PHP --enable-mysqlnd --with-mysqliの= mysqlnd --with-PDO-のMySQL = mysqlnd --with-OpenSSLの--with-FreeTypeの-DIR --with- JPEG-DIR --with-PNG-DIR --with-ZLIB --with-CONFIG-ファイルパス= / USR / LOCA / PHPの/ etc --with-CONFIG-ファイルスキャンDIR =は/ usr / local / PHPの/ etc / php.d --enable-mbstringの--enable-XML --enable-ソケット--enable-FPM --enable-保守-ZTS --disable-のFileInfoは、
    -J $ {J}を作る
    #設定ファイルをインストールします
    CDの$ {PREFIX}の/ etc / 
    CPのphp-fpm.conf.defaultのphp-fpm.conf CD $ {PREFIX} /etc/php-fpm.d 
    CP www.conf.default www.conf#ファイルinit 
    のcp $ {SRC } /php-7.3.10/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm  
    ます。chmod + xの/etc/init.d/php-fpm#設定ファイルを変更します
    SED -iの@ユーザ=誰も@ユーザー=アパッチ@ '$ {PREFIX} /等/php-fpm.d/www.conf 
    SED -iの@基=基=アパッチ@誰' $ {PREFIX} /etc/php-fpm.d/www.conf 
    のsed -iさん@ = 127.0.0.1:9000@listen = /var/run/php-fpm.sock@聞く'$ {PREFIX}の/ etc / PHP-FPMを.D / www.conf 
    SED -iの@; listen.mode = [email protected] = 0666 @ '$ {PREFIX} /etc/php-fpm.d/www.conf #reload 
    systemctlデーモンリロード    
} test_php (){ 
    のphp-FPM開始systemctl 
    睡眠3のps -ef場合| グレップのPHP-FPM | grepの-v grepをし、次に
        エコー-e "$ {} GREENたぶんPHPが正常にインストールされ... $ {NO_COLOR}" 
    他の
        エコー-e "$ {RED}たぶん、PHPのインストールに失敗しました... $ {NO_COLORを}"
    ps -efかの睡眠3 | グレップのPHP-FPM | grepの-vのgrep、次に
        エコー-e "$ {RED} PHPのアンインストールが失敗... PHPのプロセスを強制終了失敗... $ {NO_COLOR}" 
        出口2のfi 
    $ {PREFIX} $ {SRC} /php-7.3 -rf RMを0.10 /etc/init.d/php-fpm 
} judge_uninstall(){もし[ "$フラグ" = "アンインストール"];次に
    remove_php出口0fi}メイン(){ 
    judge_uninstall 
    judge_root 
    download_source 
    インストール
    test_php    
} 

主に

コンパイルし、HTTPDをインストール

#!/bin/bash#**************************************************************#Author:                     哈啰#QQ:                         xxxxxxxxx#Date:                       2019-08-08#FileName:                   install_httpd.sh#URL:                        https://blog.51cto.com/14012942#Description:                The test script#Copyright (C):              2019 Copyright ©  站点名称  版权所有#************************************************************#set -eRED="\033[0;31m"GREEN="\033[0;32m"NO_COLOR="\033[0m"PREFIX=/usr/local/httpd2.4.41
SYSCONFDIR=/etc/httpd
SRC=/usr/src
FLAG=$1CPUS=`cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l`
CORE=`cat /proc/cpuinfo| grep "cpu cores"| uniq | awk '{print $4}'`
J=$((${CPUS}*${CORE}))
FILEURL='https://ftp.bit.nl/apache/httpd-2.4.41.tar.gz https://archive.apache.org/dist/apr/apr-1.7.0.tar.gz https://archive.apache.org/dist/apr/apr-util-1.6.1.tar.gz'# 判断是不是rootjudge_root() {
    [ $(id -u) != "0" ] && { echo -e "${RED}Error:${NO_COLOR} You must be root to run this script."; exit 1; }   
}# download download_source() {    cd
    yum install wget -y    for i in ${FILEURL};do
    {
        wget ${i}
        if [ ! "$?" -eq 0 ];then
            echo "download failed!"
            exit 1        fi
    }    done}# installinstall() {    # Add the "apache" group and user
    /usr/sbin/groupadd -g 48 -r apache 2> /dev/null || :
    /usr/sbin/useradd -c "Apache" -u 48 -g apache \
    -s /sbin/nologin -r -d /usr/share/httpd apache 2> /dev/null || : 
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    yum install gcc openssl-devel pcre-devel libnghttp2-devel ncurses-devel  lbzip2  bzip2 expat-devel autoconf libtool -y
    tar xf httpd-2.4.41.tar.gz -C ${SRC}/    #apr这个解压到srclib目录即可,官方文档说的很明白了,如下
    #if you   need to use the APR and APR-Util from the apr.apache.org  project. If the latter, download the latest versions and unpack them to ./srclib/apr and ./srclib/apr-util (no  version numbers in the directory names) and use  ./configure's --with-included-apr option
    tar xf  apr-util-1.6.1.tar.gz -C /usr/src/httpd-2.4.41/srclib/
    tar xf apr-1.7.0.tar.gz -C /usr/src/httpd-2.4.41/srclib/
    mv /usr/src/httpd-2.4.41/srclib/apr-util-1.6.1 /usr/src/httpd-2.4.41/srclib/apr-util
    mv /usr/src/httpd-2.4.41/srclib/apr-1.7.0  /usr/src/httpd-2.4.41/srclib/apr    cd ${SRC}/httpd-2.4.41
    ./configure \
    --prefix=${PREFIX} \
    --sysconfdir=${SYSCONFDIR} \
    --enable-http2 \
    --enable-ssl \
    --enable-so \
    --enable-cgi \
    --enable-rewrite \
    --with-zlib \
    --with-pcre \
    --with-included-apr \
    --enable-modules=most \
    --enable-mpms-shared=all \
    --with-mpm=prefork 
    make -j ${J}
    make install    # 使用system启动就不要path变量了,不,还得要
    echo "PATH=${PREFIX}/bin:$PATH" >> /etc/profile.d/env.sh    # source /etc/profile.d/env.sh
    cat > /usr/lib/systemd/system/httpd.service <<EOF
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
EnvironmentFile=${SYSCONFDIR}/httpd.conf
ExecStart=${PREFIX}/bin/apachectl -k start  -DFOREGROUND
ExecReload=${PREFIX}/bin/apachectl  -k graceful
ExecStop=/usr/bin/kill -WINCH ${MAINPID}PrivateTmp=true[Install]
WantedBy=multi-user.target

EOF    #修改apache启动的用户
    sed  '/^Group/ s/daemon/apache/' /etc/httpd/httpd.conf  -i
    sed  '/^User/ s/daemon/apache/' /etc/httpd/httpd.conf  -i    #加载一下
    systemctl daemon-reload
}# test_webtest_web() {    #防止启动太慢,后续可以改
    sed  '/#ServerName www.example.com/a ServerName www.example.com:80' ${SYSCONFDIR}/httpd.conf -i    # apachectl start
    systemctl start httpd
    ss -ltn | grep -q :80
    [ "$?" -eq 0 ] && echo -e "${GREEN}May be web server is ok! \n If not ok,please check selinux and firewalld status.${NO_COLOR}" || \        echo -e "${RED}ERROR,Please check the web server.${NO_COLOR}"}remove_httpd() {    # source /etc/profile.d/env.sh
    # apachectl stop
    systemctl stop httpd
    rm -rf ${PREFIX} ${SYSCONFDIR} ${SRC}/httpd-2.4.41 /usr/lib/systemd/system/httpd.service 
    sed -i '/^PATH/d' /etc/profile.d/env.sh
}judge_uninstall(){if [ "$FLAG" = "uninstall" ];then
    remove_httpd    exit 0fi}main() {
    judge_uninstall
    judge_root
    download_source
    install
    test_web
}

main

测试

cat >> /etc/httpd/httpd.conf <<'EOF'LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_fdpass_module modules/mod_proxy_fdpass.so
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ unix:/var/run/php-fpm.sock|fcgi://localhost/var/www/html
EOF

sed  's/DirectoryIndex index.html/DirectoryIndex index.php index.html/' /etc/httpd/httpd.conf -i

sed -r 's@/usr/local/httpd2.4.41/htdocs@/var/www/html@' /etc/httpd/httpd.conf -i

mkdir /var/www/html -p
cat > /var/www/html/index.php <<EOF
<?
    phpinfo();
?>
EOF

httpd -t 
systemctl restart httpd

卸载

[root@node1 ~]# bash php-7.3.10.sh uninstall[root@node1 ~]# bash httpd.sh uninstall


おすすめ

転載: blog.51cto.com/14012942/2444579