[centos] apache、php配置

  1. 安裝 apache
    yum -y install httpd apr apr-util httpd-manual mod_ssl mod_perl mod_auth_mysql httpd-devel
  2. 啓動 apache
    systemctl start httpd.service

    service httpd start
  3. apache 多端口監聽
    1. 編輯 apache 配置文件 vi /etc/httpd/conf/httpd.conf
    2. 找到 Listen 80,在其下方增加 Listen 8080
    3. 保存退出
    4. 重啓 apache systemctl restart httpd.serviceservice httpd restart
  4. 設置站點虛擬目錄和多站點配置

    1. /etc/httpd/conf/httpd.conf 文檔下可能會看到以下命令

      IncludeOptional conf.d/*.conf
      這段話的意思是 在 /etc/httpd/conf.d/ 目錄下所有後綴爲 .conf 的文件都會被包含進來。so 我們只需要在 /etc/httpd/conf.d/ 目錄下添加我們的多個 .conf 文件就可以了

    2. vi /etc/httpd/conf.d/test1.conf

      NameVirtualHost *:80 #綁定端口,一定要設置
      <VirtualHost *:80>
      ServerAdmin test@test.com #出現問題後發送的郵件地址
      ServerName test1.cn #域名
      DocumentRoot "/var/www/test1" #站點根目錄
      ServerAlias www.test1.cn blog.test1.cn #單站點多域名配置
      </VirtualHost>
    3. 也可以在 /etc/httpd/conf.d/test1.conf 文件中添加其他站點(單端口多域名設置)

      <VirtualHost ServerName *:80>
      ServerAdmin [email protected]
      DocumentRoot /var/www/test2
      ServerName blog.test.com
      </VirtualHost>
    4. 重啓 apache 服務器
      systemctl restart httpd.service

      service httpd restart

    5. 安裝 libmcrypt 擴展

      1. wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
      2. tar -zxvf libmcrypt-2.5.7.tar.gz
      3. cd libmcrypt-2.5.7
      4. ./configure
      5. make && make install
      6. echo "/usr/local/lib" >> /etc/ld.so.conf # 將擴展添加到 centos 環境變量 (ld) 中
      7. ldconfig
    6. 編譯安裝 php7 下載地址

      1. wget http://124.202.164.13/files/425300000A4693F4/cn2.php.net/distributions/php-7.1.6.tar.gz
      2. tar -zxvf php-7.1.6.tar.gz
      3. 編譯安裝

        ./configure --prefix=/etc/php7 --with-apxs2=/usr/bin/apxs #apxs 地址,請使用 whereis apxs 查找(使用時,請刪除這段) --exec-prefix=/etc/php7 --bindir=/etc/php7/bin --sbindir=/etc/php7/sbin --includedir=/etc/php7/include --libdir=/etc/php7/lib/php --mandir=/etc/php7/php/man --with-config-file-path=/etc/php7/etc --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mcrypt=/usr/local/libmcrypt --with-mhash --with-openssl --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --with-zlib --enable-zip --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp --enable-gd-native-ttf --enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear --with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir --with-opcache --with-redis --enable-fpm --enable-fastcgi --with-fpm-user=www --with-fpm-group=www --without-gdbm --disable-fileinfo

        1. cd /etc/php7/bin/
        2. cp phar.phar /usr/bin/phar.phar
          cp php /usr/bin/php
          cp php-cgi /usr/bin/php-cgi
          cp php-config /usr/bin/php-config
          cp phpize /usr/bin/phpize
          cp /etc/php7/sbin/php-fpm /usr/bin/php-fpm
          cd /etc/php7/etc/
          cp php-fpm.conf.default php-fpm.conf
          cp cp php-fpm.d/www.conf.default php-fpm.d/www.conf
        3. 進入 php7 源碼目錄 cp php.ini-development /etc/php7/etc/php.ini
        4. groupadd www && useradd www -g www
  5. 配置 apache 運行 php 文件

    1. vi /etc/httpd/conf/httpd.conf
    2. 找到 AddType 關鍵字 增加 AddType application/x-httpd-php .php .phtml
    3. 找到 LoadModule 關鍵字 增加 LoadModule php7_module /usr/lib64/httpd/modules/libphp7.so
    4. 保存退出並重啓 httpd service httpd restart
發佈了53 篇原創文章 · 獲贊 9 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章