×

怎么将apache支持php

怎么将apache支持php(apache配置php8)

admin admin 发表于2023-03-31 09:28:08 浏览47 评论0

抢沙发发表评论

本文目录一览:

请问php在apache下运行有几种模式,区别是什么?该怎样设置,谢谢

分类: 电脑/网络 程序设计 其他编程语言

解析:

Windows 下有两种方法使 PHP 工作于 Apache 2.0.x 之中。一种是 使用 CGI 可执行程序,另一种是适用 Apache 模块的 DLL。不管哪种都需要编辑 d.conf 来配置 Apache 支持 PHP 并重新启动服务器。 -怎么将apache支持php

注: 记住在 Windows 下给 Apache 的配置文件中加入路径值的时候,所有的反斜线例如 c:\directory\file.ext 必须转换成正斜线,如 c:/directory/file.ext。-怎么将apache支持php

以 CGI 方式安装

需要将以下三行加入到 Apache 的 d.conf 配置文件中以设定 CGI: 例子 6-5. PHP 在 Apache 2.0 中的 CGI 方式

ScriptAlias /php/ "c:/php/"

AddType application/x-d-php .php

# 对 PHP 4 用这行

Action application/x-d-php "/php/php.exe"

# 对 PHP 5 用这行

Action application/x-d-php "/php/php-cgi.exe"

警告

如果使用 CGI 方式安装,则服务器对于某些可能的攻击是开放的。请阅读 CGI 安全一章以学习如何防御这些攻击。

以 Apache 模块方式安装

需要将以下两行加入到 Apache 的 d.conf 配置文件中以设定 Apache 2.0 的 PHP 模块: 例子 6-6. PHP 在 Apache 2.0 中的模块方式

# 对 PHP 4 用这两行:

LoadModule php4_module "c:/php/php4apache2.dll"

# 别忘了从 sapi 目录中把 php4apache2.dll 拷贝出来!

AddType application/x-d-php .php

# 对 PHP 5 用这两行:

LoadModule php5_module "c:/php/php5apache2.dll"

AddType application/x-d-php .php

# 配置 php.ini 的路径

PHPIniDir "C:/php"

注: 记得用自己 PHP 实际所在的路径替换掉上例中的 c:/php/。要留意在 LoadModule 指令中用的是 php4apache2.dll 或 php5apache2.dll,而不是 php4apache.dll 或 php5apache.dll,后者是设计用于 Apache 1.3.x 的。 -怎么将apache支持php

注: 如果要使用内容协商机制,请阅读有关 FAQ。

警告

不要在安装中混合使用来自不同 PHP 版本的 DLL。使用下载回来的 PHP 版本中所提供的 DLL 和扩展库是唯一选择。

如何让我的apache支持php

进入php源程序目录中的ext目录中,这里存放着各个扩展模块的源代码,选择你需要的模块,比如curl模块:cd curl

执行phpize生成编译文件,phpize在PHP安装目录的bin目录下

/usr/local/php5/bin/phpize

运行时,可能会报错:Cannot find autoconf. Please check your autoconf installation and

the $PHP_AUTOCONF

environment variable is set correctly and then rerun this

script.,需要安装autoconf:

yum install autoconf(RedHat或者CentOS)、apt-get install

autoconf(Ubuntu Linux)

/usr/local/php5/bin/php -v

执行这个命令时,php会去检查配置文件是否正确,如果有配置错误,

这里会报错,可以根据错误信息去排查!

PHP运行于Apache 模块方式

当使用 PHP 作为 Apache 模块时,也可以用 Apache 的配置文件(例如 httpd.conf)和 .htaccess 文件中的指令来修改 PHP 的配置设定。需要有“AllowOverride Options”或“AllowOverride All”权限才可以。-怎么将apache支持php

有几个 Apache 指令可以使用户在 Apache 配置文件内部修改 PHP 的配置。哪些指令属于 PHP_INI_ALL,PHP_INI_PERDIR 或 PHP_INI_SYSTEM 中的哪一个,请参考附录中的 php.ini 配置选项列表。-怎么将apache支持php

php_value name value

设定指定的值。只能用于 PHP_INI_ALL 或 PHP_INI_PERDIR 类型的指令。要清除先前设定的值,把 value 设为 none。

Note: 不要用 php_value 设定布尔值。应该用 php_flag(见下面)。

php_flag name on|off

用来设定布尔值的配置指令。仅能用于 PHP_INI_ALL 和 PHP_INI_PERDIR 类型的指令。

php_admin_value name value

设定指定的指令的值。不能用于 .htaccess 文件。任何用 php_admin_value 设定的指令都不能被 .htaccess 或 virtualhost 中的指令覆盖。要清除先前设定的值,把 value 设为 none。-怎么将apache支持php

php_admin_flag name on|off

用来设定布尔值的配置指令。不能用于 .htaccess 文件。任何用 php_admin_flag 设定的指令都不能被 .htaccess 或 virtualhost 中的指令覆盖。

Example #1 Apache 配置例子

IfModule mod_php5.c

php_value include_path ".:/usr/local/lib/php"

php_admin_flag engine on

/IfModule

IfModule mod_php4.c

php_value include_path ".:/usr/local/lib/php"

php_admin_flag engine on

/IfModule

Caution

PHP 常量不存在于 PHP 之外。例如在 httpd.conf 中不能使用 PHP 常量如 E_ALL 或 E_NOTICE 来设定 error_reporting 指令,因为其无意义,实际等于 0。应该用相应的掩码值来替代。这些常量可以在 php.ini 中使用。-怎么将apache支持php

通过 Windows 注册表修改 PHP 配置

在 Windows 下运行 PHP 时,可以用 Windows 注册表以目录为单位来修改配置。配置值存放于注册表项 HKLM\SOFTWARE\PHP\Per Directory Values 下面,子项对应于路径名。例如对于目录 c:\inetpub\wwwroot 的配置值会存放于 HKLM\SOFTWARE\PHP\Per Directory Values\c\inetpub\wwwroot 项下面。其中的设定对于任何位于此目录及其任何子目录的脚本都有效。项中的值的'名称是 PHP 配置指令的名字,值的数据是字符串格式的指令值。值中的 PHP 常量不被解析。不过只有可修改范围是 PHP_INI_USER 的配置值可以用此方法设定,PHP_INI_PERDIR 的值就不行。-怎么将apache支持php

其它接口下的 PHP

无论怎样运行 PHP,都可以在脚本中通过 ini_set() 而在运行时修改某个值。更多信息见手册中 ini_set() 的页面。

如果对自己系统中的配置设定及其当前值的完整列表感兴趣,可以运行 phpinfo() 函数并查看其结果的页面。也可以在运行时用 ini_get() 或 get_cfg_var() 取得个别配置指令的值。-怎么将apache支持php

add a note add a note

User Contributed Notes 13 notes

up

down

3 Anteaus ?2 years ago

One of the most serious problems here is that it is hard to determine programmatically which of three or more possible configuration methods (php.ini, .user.ini, .htaccess) should be used on any given hosting company's server.-怎么将apache支持php

The worst outcome is if an install.php routine attempts to set .htaccess directives on a cgi-mode server, in which case the outcome is usually a '500' crash. Once in that situation the php installation routine cannot be rerun to correct the problem, so you effectively have a hosting lockout situation which can only be corrected by manual intervention.-怎么将apache支持php

up

down

-2 contrees.du.reve at gmail dot com ?9 years ago

Being able to put php directives in httpd.conf and have them work on a per-directory or per-vitual host basis is just great. Now there's another aspect which might be worth being aware of:-怎么将apache支持php

A php.ini directive put into your apache conf file applies to php when it runs as an apache module (i.e. in a web page), but NOT when it runs as CLI (command-line interface).-怎么将apache支持php

Such feature that might be unwanted by an unhappy few, but I guess most will find it useful. As far as I'm concerned, I'm really happy that I can use open_basedir in my httpd.conf file, and it restricts the access of web users and sub-admins of my domain, but it does NOT restrict my own command-line php scripts...-怎么将apache支持php

up

down

-3 nick at vistaworks dot net ?4 years ago

On Windows, as the documentation above states, you cannot set max_upload_filesize and post_max_size in the registry, because they are PHP_INI_PERDIR.-怎么将apache支持php

Confusingly, however, is the fact that phpinfo() will show your changes if you do add those to the regsitry, as if they were taking effect. However, the upload size is *not* changed, regardless of what phpinfo() reports.-怎么将apache支持php

I believe the reading of registry values and override happen 'too late' in the request processing, ie, after the file has already been uploaded and rejected.-怎么将apache支持php

In a perfect world, phpinfo() would recognize this and not report the overridden values, which is very confusing.-怎么将apache支持php

up

down

-4 Woody/mC ?9 years ago

@ pgl: As the documentation says:

"To clear a previously set value use none as the value."

Works fine for me.

up

down

-6 user at NOSPAM dot example dot com ?5 years ago

PHP Constants will work with php_value; for example:

如何配置apache支持php

编译安装php,并且把php模块放到apahce里,然后apache conf中添加php模块配置 apache要开启模块加载模式 #./configure --prefix=/usr/apache2 --enable-module=so --enable-ssl 配置文件加入 LoadModule php5_module modules/libphp5.so php编译模块到modules目录下 #./configure --prefix=/usr/php5 --with-apxs2=/usr/apache2/bin/apxs --with-mysql=/usr/mysql --with-curl=/usr/include/curl --with-zlib --with-gd --enable-mbstring-怎么将apache支持php