[centos] apache、php配置

来源:互联网 发布:品质365 知乎 编辑:程序博客网 时间:2024/05/19 20:45
  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 test@test.comDocumentRoot /var/www/test2ServerName 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
原创粉丝点击