PHP 在 Apache 上的 VirtualHost 中不是 运行
PHP not running in VirtualHost on Apache
我不得不从旧服务器 (Plesk 14; CentOS 5; Apache 2.2; PHP 5.3.5)
迁移到新服务器 (Plesk Onyx 17; CentOS 7.3; Apache 2.4; PHP 7)
除自定义虚拟主机外,一切正常。
在旧服务器上,在我的 etc/httpd/conf/httpd.conf
中,我有以下内容并且可以正常工作:
<VirtualHost XX.XX.XX.XX:80>
DocumentRoot /var/www/vhosts/mycompany.com/httpdocs/myproject
ServerName myproject.com
ServerAlias www.myproject.com
<Directory /var/www/vhosts/mycompany.com/httpdocs/myproject>
<IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_flag safe_mode on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag safe_mode off
php_admin_value upload_tmp_dir "/tmp"
php_admin_value session.save_path "/tmp"
</IfModule>
php_admin_flag engine on
AddHandler php5-script .php
</Directory>
</VirtualHost>
如果我没有 php_admin_flag engine on
和 AddHandler
,它只会将 php 文件下载为文本。
在新服务器上,我尝试了完全相同的方法,它只下载了 php 文件。
我也尝试在 <Directory>
中添加以下内容但没有成功:
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
#Error: Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
php_admin_flag engine on
# Invalid command 'php_admin_flag', perhaps misspelled or defined by a module not included in the server configuration
AddType text/html .php
#I used this to make sure AddType works. It does - PHP displayed as HTML
AddType application/x-httpd-php .php
#Downloads the file as text
AddHandler application/x-httpd-php .php
#Downloads the file as text
AddType php5-script .php
#Shows php as plain text
值得一提的是,在这个 Plesk 上有多个 PHP 版本。当我执行 php -v
时,我得到 PHP 5.3.5 (cli)
,但是当我在页面中使用 phpinfo()
时,我得到 "PHP Version 7.0.18"。
我的猜测是它与此有关。
在 Plesk 的管理面板上显示 run PHP 7 as FPS Application
这是 phpinfo()
https://pste.eu/p/BGpI.html
的快照
知道会是什么吗?
嗨米罗,
您是否考虑过从 MPM-EVENT 切换到 MPM-PREFORK,以便能够使用 libapache2 - PHP - 模块?
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
#Error: Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
=>主页>工具与设置>Apache Web 服务器>(选项)MPM 模式
我不得不从旧服务器 (Plesk 14; CentOS 5; Apache 2.2; PHP 5.3.5)
迁移到新服务器 (Plesk Onyx 17; CentOS 7.3; Apache 2.4; PHP 7)
除自定义虚拟主机外,一切正常。
在旧服务器上,在我的 etc/httpd/conf/httpd.conf
中,我有以下内容并且可以正常工作:
<VirtualHost XX.XX.XX.XX:80>
DocumentRoot /var/www/vhosts/mycompany.com/httpdocs/myproject
ServerName myproject.com
ServerAlias www.myproject.com
<Directory /var/www/vhosts/mycompany.com/httpdocs/myproject>
<IfModule sapi_apache2.c>
php_admin_flag engine on
php_admin_flag safe_mode on
</IfModule>
<IfModule mod_php5.c>
php_admin_flag safe_mode off
php_admin_value upload_tmp_dir "/tmp"
php_admin_value session.save_path "/tmp"
</IfModule>
php_admin_flag engine on
AddHandler php5-script .php
</Directory>
</VirtualHost>
如果我没有 php_admin_flag engine on
和 AddHandler
,它只会将 php 文件下载为文本。
在新服务器上,我尝试了完全相同的方法,它只下载了 php 文件。
我也尝试在 <Directory>
中添加以下内容但没有成功:
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
#Error: Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
php_admin_flag engine on
# Invalid command 'php_admin_flag', perhaps misspelled or defined by a module not included in the server configuration
AddType text/html .php
#I used this to make sure AddType works. It does - PHP displayed as HTML
AddType application/x-httpd-php .php
#Downloads the file as text
AddHandler application/x-httpd-php .php
#Downloads the file as text
AddType php5-script .php
#Shows php as plain text
值得一提的是,在这个 Plesk 上有多个 PHP 版本。当我执行 php -v
时,我得到 PHP 5.3.5 (cli)
,但是当我在页面中使用 phpinfo()
时,我得到 "PHP Version 7.0.18"。
我的猜测是它与此有关。
在 Plesk 的管理面板上显示 run PHP 7 as FPS Application
这是 phpinfo()
https://pste.eu/p/BGpI.html
知道会是什么吗?
嗨米罗,
您是否考虑过从 MPM-EVENT 切换到 MPM-PREFORK,以便能够使用 libapache2 - PHP - 模块?
LoadModule php5_module /usr/lib64/httpd/modules/libphp5.so
#Error: Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.
=>主页>工具与设置>Apache Web 服务器>(选项)MPM 模式