zoukankan      html  css  js  c++  java
  • Ubuntu宝塔面板设置网站 Apache Server API为Apache 2.0 Handler模式

    用过宝塔面板(https://www.bt.cn)的谁用谁知道;  以下来自官网的介绍:

    “宝塔Linux面板是提升运维效率的服务器管理软件,支持一键LAMP/LNMP/集群/监控/网站/FTP/数据库/JAVA等100多项服务器管理功能”。

    一个多平台开发集成工具, 宝塔安装Apache+php 默认Server API 是FPM/FastCGI模式,且不支持自动切换,要修改为Apache 2.0 Handler模式只能手动修改。https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=33550&highlight=handler

    为什么要改为Apache 2.0 Handler模式

    目前项目中server用的是Apache,服务器配置的是Server API= Apache 2.0 Handler,本地使用宝塔的集成环境,自然Server API=FPM/FastCGI模式,某天git pull代码后本地无法启动,查看error log 提示:

    Invalid command 'php_value', perhaps mis-spelled or defined by a module not included

    发现在根目录下的.htaccess 文件中多了一行

    php_value max_input_vars 4500

    这个是php提交post设置最大值提交参数,那么问题来了,为什么服务器支持而我本地提示不支持呢,找到了这篇文章;

    https://stackoverflow.com/questions/31270385/php-value-in-htaccess-show-internal-server-error

    You need to determine if PHP is setup in CGI mode. If it is you cannot add those lines to your .htaccess file. You will need to make your changes via php.ini

    so you cannot use the following directives in .htaccess files: php_flag, php_admin_flag, php_value, php_admin_value.

    直接注释掉,但每次git push都要忽略该文件。麻烦。。。。。

    设置 Server API为Apache 2.0 Handler模式

    在stackoverflow 中看到了类似的问题

    How to change Server API from CGI/FastCGI to apache2handler

    copy answer comment:

    To change Server Api FPM to apache2handler, As far you know yo need to compile PHP. Apache compile does not necessary. In fact if you are using Apache Passanger mod or else, compiling Apache might bring problems. So that is why you do not want to compile Apache to change Server Api for PHP.

    所以,是不是宝塔中配置的Apache不需要用重新编译,只要我重新编译下php即可。OK, Let's  go!

    下载 & 编译 php源码

    宝塔提供了N多个PHP版本,为了区分他们提供的版本,我下载了宝塔没有提供的一个php版本做为测试用,php5.6.23

    wget https://www.php.net/distributions/php-5.6.23.tar.gz

    从目前配置 Configure Command复制信息

     修改信息为如下:

    './configure' '--prefix=/www/server/php/56' '--with-config-file-path=/www/server/php/56/etc' '--with-apxs2=/www/server/apache/bin/apxs' '--disable-cgi'  '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl=/usr/local/curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl=/usr/local/openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo'  '--enable-intl'

    其中 --prefix指php要安装的位置,--with-config-file-path指配置文件的路径,--with-apxs2指Apache sapi 的目录文件。取消了'--enable-opcache'因为opcache一直编译报错。

    sudo make && make install 

    安装好之后复制php.ini-production文件到/www/server/php/56/etc/php.ini

    此时会发现在/www/server/apache/modules中生成了libphp5.so模块。

    修改Apache配置

    修改Apache配置文件: /www/server/apache/conf/httpd.conf

    查找  libphp5.so,理论上可以找的如下一行

    LoadModule php5_module        modules/libphp5.so

    将查找到那行移动到LoadModule 配置块的最上面,OK! Apache配置httpd.conf 就这么一行代码挪动,仅此而已!

    修改vhost配置

    宝塔默认vhost位于/www/server/panel/vhost/apache/***.conf文件,也可以登陆宝塔后台-站点修改-配置文件,将#php FilesMatch配置块去掉。

    ok,保存并重启服务。

    *注: 只要修改希望vhost提供Server API= Apache 2.0 Handler的vhost,不修改其他vhost依然可以提供FastCGI模式。so,Apache可以提供不同php版本的不同Server API。

    phpinfo查看:

  • 相关阅读:
    java入门 学习日志三 (面向对象1)
    java入门 学习日志二
    第八届蓝桥杯 b组试题解析
    java入门 学习日志一
    第九届蓝桥杯 b组 解析
    第九届蓝桥杯 b组 明码
    第十届蓝桥杯 b组
    包子凑数 、买不到的数目
    基础背包问题
    斐波那契数列第n项
  • 原文地址:https://www.cnblogs.com/dcb3688/p/4610651.html
Copyright © 2011-2022 走看看