1. <th id="orwrz"></th>
        <tbody id="orwrz"><pre id="orwrz"></pre></tbody>
      2. <rp id="orwrz"><object id="orwrz"></object></rp>
        首頁 LAMP教程實戰案例:實現CentOS 7 編譯安裝基于 fastcgi 模式的多虛擬主機的wordpress和discuz的LAMP架構

        實戰案例:實現CentOS 7編譯安裝基于httpd 模塊方式的LAMP

        課后練習:

        運維派隸屬馬哥教育旗下專業運維社區,是國內成立最早的IT運維技術社區,歡迎關注公眾號:yunweipai
        領取學習更多免費Linux云計算、Python、Docker、K8s教程關注公眾號:馬哥linux運維

        實戰案例2

        目標

        實現CentOS 7 編譯安裝基于 fastcgi 模式的多虛擬主機的wordpress和discuz的LAMP架構

        環境準備

        兩臺主機:

        • 一臺主機:httpd+php(fastcgi模式)
        • 一臺主機:mariadb 服務器

        軟件版本:

        • mariadb-10.2.27-linux-x86_64.tar.gz 通用二進制格式
        • apr-1.7.0.tar.bz2
        • apr-util-1.6.1.tar.bz2
        • httpd-2.4.41.tar.gz
        • php-7.4.3.tar.xz 或 php-7.3.10.tar.bz2
        • wordpress-5.3.2-zh_CN.tar.gz
        • Discuz_X3.4_SC_UTF8【20191201】.zip
        實現步驟
        二進制安裝mariadb
        useradd -r -s /sbin/nologin mysql 
        tar xvf mariadb-10.2.27-linux-x86_64.tar.gz -C /usr/local
        cd /usr/local
        ls -sv mariadb-10.2.27-linux-x86_64 mysql 
        cd mysql
        chown -R root.root ./* 
        mkdir /data/mysql -p
        chown -R mysql.mysql /data/mysql
        mkdir /etc/mysql
        cp support-files/my-huge.cnf /etc/mysql/my.cnf 
        vim /etc/mysql/my.cnf 
        [mysqld]
        #加三行
        datadir =/data/mysql
        skip_name_resolve = ON 
        
        #準備PATH變量
        vim /etc/profile.d/lamp.sh
        PATH=/usr/local/mysql/bin/:$PATH
        .  /etc/profile.d/lamp.sh
        
        yum install libaio -y
        cd /usr/local/mysql;scripts/mysql_install_db  --user=mysql --datadir=/data/mysql
        cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
        chkconfig --add mysqld
        service mysqld start 
        
        #為wordprss和discuz應用準備數據庫和用戶帳號
        mysql -uroot 
        mysql> create database wordpress;
        mysql> create database discuz;
        mysql> grant all on wordpress.* to wpuser@'192.168.8.%' identified by "wppass";
        mysql> grant all on discuz.* to discuz@'192.168.8.%' identified by 'dispass';
        編譯安裝 httpd 2.4.41
        #安裝相關包
        yum install gcc pcre-devel openssl-devel expat-devel -y
        
        #編譯安裝httpd
        tar xvf apr-1.7.0.tar.bz2  
        tar xvf apr-util-1.6.1.tar.bz2 
        tar xf httpd-2.4.41.tar.gz 
        mv apr-1.7.0 httpd-2.4.41/srclib/apr
        mv apr-util-1.6.1 httpd-2.4.41/srclib/apr-util
        
        cd httpd-2.4.41/
        ./configure \
        --prefix=/apps/httpd24 \
        --enable-so \
        --enable-ssl \
        --enable-cgi \
        --enable-rewrite \
        --with-zlib \
        --with-pcre \
        --with-included-apr \
        --enable-modules=most \
        --enable-mpms-shared=all \
        --with-mpm=event
        
        make && make install 
        
        #準備PATH變量
        vim /etc/profile.d/lamp.sh
        PATH=/apps/httpd24/bin:PATH
         . /etc/profile.d/lamp.sh
        
        #創建和配置用戶和組
        useradd -s /sbin/nologin -r -u 88 apache
        vim /apps/httpd24/conf/httpd.conf
        user apache
        group apache
        
        #修改為event模式,編譯時已指定,此項不再需修改,可選項
        vim /apps/httpd24/conf/httpd.conf
        LoadModule mpm_event_module modules/mod_mpm_event.so                                  
        #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
        #LoadModule mpm_worker_module modules/mod_mpm_worker.so
        
        httpd -M |grep mpm
        mpm_event_module (shared)
        
        apachectl start
        
        [root@centos7 ~]#cat  /usr/lib/systemd/system/httpd.service
        [Unit]
        Description=The Apache HTTP Server
        After=network.target remote-fs.target nss-lookup.target
        Documentation=man:httpd(8)
        Documentation=man:apachectl(8)
        [Service]
        Type=forking
        #EnvironmentFile=/etc/sysconfig/httpd
        ExecStart=/apps/httpd24/bin/httpdOPTIONS -k start
        ExecReload=/apps/httpd24/bin/httpd $OPTIONS -k graceful
        ExecStop=/apps/httpd24/bin/apachectl stop
        KillSignal=SIGCONT
        PrivateTmp=true
        [Install]
        WantedBy=multi-user.target
        編譯安裝 fastcgi 方式的 php 7.4
        #安裝相關包,依賴EPEL源
        #php 7.4 相關包
        yum install gcc libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel
        #php 7.3 相關包
        yum install gcc libxml2-devel bzip2-devel libmcrypt-devel 
        
        #php7.4 編譯
        tar xvf php-7.4.3.tar.xz 
        cd php-7.4.3/
        
        ./configure \
        --prefix=/apps/php74 \
        --enable-mysqlnd \
        --with-mysqli=mysqlnd \
        --with-pdo-mysql=mysqlnd \
        --with-openssl    \
        --with-zlib  \
        --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
        
        #編譯安裝php 7.3
        tar xvf php-7.3.10.tar.bz2
        cd php-7.3.10
        
        ./configure --prefix=/apps/php73 \
        --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 4 && make install
        #準備PATH變量
        
        vim /etc/profile.d/lamp.sh
        PATH=/apps/php74/bin:/apps/httpd24/bin:PATH
         . /etc/profile.d/lamp.sh
        
        vim /etc/profile.d/lamp.sh
        PATH=/apps/php73/bin:/apps/httpd24/bin:PATH
         . /etc/profile.d/lamp.sh
        
        [root@centos7 ~]#php --version
        PHP 7.4.3 (cli) (built: Mar 11 2020 15:06:53) ( ZTS )
        Copyright (c) The PHP Group
        Zend Engine v3.4.0, Copyright (c) Zend Technologies
        
        [root@websrv ~]#/apps/php73/bin/php --version
        PHP 7.3.12 (cli) (built: Dec 14 2019 10:20:40) ( ZTS )
        Copyright (c) 1997-2018 The PHP Group
        Zend Engine v3.3.12, Copyright (c) 1998-2018 Zend Technologies
        
        #準備php配置文件和啟動文件
        cp php.ini-production  /etc/php.ini
        
        cp  sapi/fpm/php-fpm.service /usr/lib/systemd/system/
        cd /apps/php73/etc
        cp  php-fpm.conf.default  php-fpm.conf
        cd  php-fpm.d/
        cp www.conf.default www.conf
        
        #修改進程所有者
        vim /apps/php74/etc/php-fpm.d/www.conf
        user  apache
        group apache 
        #支持status和ping頁面
        pm.status_path = /fpm_status
        ping.path = /ping  
        
        #支持opcache加速
        mkdir /etc/php.d/
        vim /etc/php.d/opcache.ini
        [opcache]
        zend_extension=opcache.so               
        opcache.enable=1
        
        systemctl daemon-reload
        systemctl status php-fpm.service 
        systemctl enable --now  php-fpm.service 
        修改配置httpd 支持php-fpm
        vim /apps/httpd24/conf/httpd.conf
        #取消下面兩行的注釋
        LoadModule proxy_module modules/mod_proxy.so
        LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
        #修改下面行
        <IfModule dir_module>
        DirectoryIndex index.php index.html
        </IfModule>
        #加下面三行
        AddType application/x-httpd-php .php
        AddType application/x-httpd-php-source .phps
        ProxyRequests Off
        
        #實現兩個虛擬主機
        <virtualhost *:80>
        servername wordpress.magedu.org
        documentroot /data/wordpress
        <directory /data/wordpress>
        require all granted
        </directory>
        ProxyPassMatch ^/(.*\.php)fcgi://127.0.0.1:9000/data/wordpress/1
        #實現status和ping頁面
        ProxyPassMatch ^/(fpm_status|ping)fcgi://127.0.0.1:9000/1 
        CustomLog "logs/access_wordpress_log" common
        </virtualhost>
        
        <virtualhost *:80>
        servername discuz.magedu.org
        documentroot /data/discuz
        <directory /data/discuz/>
        require all granted
        </directory>
        ProxyPassMatch ^/(.*\.php)fcgi://127.0.0.1:9000/data/discuz/1
        CustomLog "logs/access_discuz_log" common
        </virtualhost> 
        
        apachectl restart
        準備wordpress和discuz! 相關文件
        #準備wordpress程序文件
        mkdir  /data/
        tar xvf  wordpress-5.3.2-zh_CN.tar.gz
        mv wordpress/ /data
        setfacl –R –m u:apache:rwx /data/wordpress/
        #或者chown –R apache.apache /data/wordpress
        
        #準備discuz!程序文件
        unzip Discuz_X3.4_SC_UTF8【20191201】.zip 
        mkdir /data/discuz
        mv upload/* /data/discuz
        setfacl -R -m u:apache:rwx /data/discuz/
        測試訪問
        vim /etc/hosts
        192.168.100.100 wordpress.magedu.org discuz.magedu.org

        打開瀏覽器訪問 http://wordpress.magedu.net 和http://discuz.magedu.net 分別進行初始化和安裝

        修改成UDS模式
        vim /apps/php/etc/php-fpm.d/www.conf
        ;listen = 127.0.0.1:9000
        listen = /run/php-fpm.sock
        listen.owner = apache
        listen.group = apache                                                                    
        listen.mode = 0660
        systemctl restart php-fpm
        
        ll /run/php-fpm.sock 
        srw-rw---- 1 apache apache 0 Dec 14 11:11 /run/php-fpm.sock
        
        vim /apps/httpd24/conf/httpd.conf
        <virtualhost *:80>
        servername wordpress.magedu.org
        documentroot /data/wordpress
        <directory /data/wordpress>
        require all granted
        </directory>
        #ProxyPassMatch ^/(.*\.php)fcgi://127.0.0.1:9000/data/wordpress/1
        ProxyPassMatch ^/(.*\.php)"unix:/run/php-fpm.sock|fcgi://localhost/data/wordpress/"
        #ProxyPassMatch ^/(status|ping) fcgi://127.0.0.1:9000/1
        ProxyPassMatch ^/(status|ping) "unix:/run/php-fpm.sock|fcgi://localhost/"    
        CustomLog "logs/access_wordpress_log" common
        </virtualhost>
        <virtualhost *:80>
        servername wordpress.magedu.org
        documentroot /data/wordpress
        <directory /data/wordpress>
        require all granted
        </directory>
        #ProxyPassMatch ^/(.*\.php)fcgi://127.0.0.1:9000/data/discuz/1
        ProxyPassMatch ^/(.*\.php)"unix:/run/php-fpm.sock|fcgi://localhost/data/discuz/"
        #ProxyPassMatch ^/(status|ping) fcgi://127.0.0.1:9000/1
        ProxyPassMatch ^/(status|ping) "unix:/run/php-fpm.sock|fcgi://localhost/"    
        CustomLog "logs/access_wordpress_log" common
        </virtualhost>
        
        apachectl restart

        本文鏈接:http://www.abandonstatusquo.com/36114.html

        實戰案例:實現CentOS 7編譯安裝基于httpd 模塊方式的LAMP

        課后練習:

        網友評論comments

        發表評論

        您的電子郵箱地址不會被公開。

        暫無評論

        Copyright ? 2012-2022 YUNWEIPAI.COM - 運維派 京ICP備16064699號-6
        掃二維碼
        掃二維碼
        返回頂部
        十分钟免费观看视频高清下载