用过宝塔面板(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 

这个是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查看:

Ubuntu宝塔面板设置网站 Apache Server API为Apache 2.0 Handler模式的更多相关文章

  1. 宝塔面板设置腾迅COS自动备份网站

    之前写了如何配置腾迅云COS并挂载到服务器中,今天看到宝塔面板中有腾迅云COS的插件,不过研究了下,只是将COS绑定在宝塔面板中,不能自动备份,需要用到宝塔的计划任务功能 1.下载腾迅云COS插件 2 ...

  2. 【服务器】CentOs7系统使用宝塔面板搭建网站,有FTP配置(保姆式教程)

    内容繁多,请耐心跟着流程走,在过程中遇到问题请在下面留言(我只是小白,请专业人士喷轻点). 这次用thinkphp5.1做演示,单纯的做演示,我打算下一篇文章用typecho(博客框架)演示. 前言 ...

  3. IdentityServer4:IdentityServer4+API+Client实践OAuth2.0客户端模式(1)

    一.OAuth2.0 1.OAuth2.0概念 OAuth2.0(Open Authorization)是一个开放授权协议:第三方应用不需要接触到用户的账户信息(如用户名密码),通过用户的授权访问用户 ...

  4. How to install Apache Server on Windows

    Note Those of you interested in the Apache 2.0.X tutorial, it has been abandon and I will no longer ...

  5. APache PDFbox API使用(1)----简单介绍

    因为项目的须要.近期在学习APache  PDFbox API,Apache PDFbox API是Apache Java 开源社区中个一个项目,其受Apache 版权 V2的保护,其提供了以下的功能 ...

  6. 宝塔面板+djiango+mod wsgi +apache 配置多项目站点

    在一台服务器上同时有多个djiango项目,那么就需要配置多站点,利用不同的域名不同的端口  同时存在多个项目. 环境,centos + 宝塔面板+apache+django 1.在centos环境下 ...

  7. 腾讯云服务器安装宝塔面板快速配置LNMP/LAMP网站系统

    我们在选择购买腾讯云服务器之后,有部分用户肯定是用来建站用途的.毕竟云服务器的性能和功能比虚拟主机优秀很多.腾讯云服务器拥有香港.北京.广州.上海.美国等多个机房,可以安装Linux和Windows系 ...

  8. Server 主机屋云服务器 宝塔面板 部署nginx反向代理的vue项目

    图文记录云服务器上部署需要nginx反向代理的vue项目: 一.先登录并购买云服务器,根据自己需求购买,此处不详细介绍: 二.登录后如下图,点击进入云服务器界面: 三.在云服务器界面点击管理,进入管理 ...

  9. Ubuntu 16.04 LAMP server tutorial with Apache 2.4, PHP 7 and MariaDB (instead of MySQL)

    https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/ This tut ...

随机推荐

  1. python中生成JWK(json web token)

    #需要安装pyjwt import jwt import time # 使用 sanic 作为restful api 框架 def create_token(request): grant_type ...

  2. gitlab修改IP地址及仓库地址

    将IP修改为192.168.10.100,操作方法 . 先修改本地的IP地址 vim /etc/sysconfig/network-scripts/ifcfg-eth0TYPE=EthernetBOO ...

  3. 基于gin框架搭建的一个简单的web服务

    刚把go编程基础知识学习完了,学习的时间很短,可能还有的没有完全吸收.不过还是在项目中发现知识,然后在去回顾已学的知识,现在利用gin这个web框架做一个简单的CRUD操作. 1.Go Web框架的技 ...

  4. Tensorflow简单实践系列(三):图和会话

    当执行一个 TensorFlow 函数的时候,并不会马上执行运算,而是把运算存储到一个称为“图”(graph)的数据结构里面. 图存储的各种运算,只有在会话(session)里执行图,才会真正地执行. ...

  5. Exploit Kit——hacker入侵web,某iframe中将加载RIG EK登录页面,最终下载并执行Monero矿工

    RIG Exploit Kit使用PROPagate注入技术传播Monero Miner from:https://www.4hou.com/technology/12310.html 导语:Fire ...

  6. mmdetection安装教程

    如果官方教程不行再参考我的吧,我的环境如下: ubuntu cuda10 cudnn7.5 步骤: 1.使用conda创建一个虚拟环境 conda create -n mmdetection pyth ...

  7. Kotlin匿名函数与闭包详解

    Lambda表达式实例演练: 继续先来编写一些Lambda表达式相关的代码: 接下来想从上面的字符串数组中找到带有"h"的字符串并打印出来: 如果学习了Java8的Lambda表达 ...

  8. 【Java】SpringBoot-Ajax-Json:Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported for @RequestBody XXX

    1.重新组装数据 var params=JSON.stringify({"userword":XXXXX,"password":"XXXXX" ...

  9. jquery ajax在ie9下跨域不执行 crossDomain: true == !(document.all)

    <!DOCTYPE html> <html> <head> <title>jQuery CORS in IE7 - IE10</title> ...

  10. Codeforces Round #603 (Div. 2) E. Editor(线段树)

    链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...