[英]phpinfo() not working on mac OS-X Capitan apache2 server
I am using OS-X Capitan
and Apache/2.4.18 (Unix)
. 我正在使用OS-X Capitan
和Apache/2.4.18 (Unix)
。 I have below phpinfo.php
file 我下面有phpinfo.php
文件
<?php phpinfo(); ?>
when I run the command php phpinfo.php
it will show phpinfo()
correctly. 当我运行命令php phpinfo.php
,它将正确显示phpinfo()
。 This is not showing correctly from browser but instead shows the code as below 这无法从浏览器正确显示,而是显示如下代码
<?php phpinfo(); ?>
I have made following changes to /etc/apache2/httpd.conf
我对/etc/apache2/httpd.conf
进行了以下更改
uncommented below lines 以下行未注释
LoadModule rewrite_module libexec/apache2/mod_rewrite.so LoadModule php5_module libexec/apache2/libphp5.so
Added MIME Type
inside <IfModule mime_module>
tag to above httpd.conf
file 将<IfModule mime_module>
标记内的MIME Type
添加到上述httpd.conf
文件中
AddType application/x-httpd-php .php
Made sure that libexec/apache2/mod_rewrite.so
exists 确保libexec/apache2/mod_rewrite.so
存在
php -v gives below result php -v给出以下结果
PHP: parse error in /etc/php.ini on line 107 PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
sudo cp /etc/php.ini.default /etc/php.ini
Restarted apache2 using command 使用命令重启apache2
sudo apachectl restart
Still it shows the php code <?php phpinfo(); ?>
仍然显示php代码<?php phpinfo(); ?>
<?php phpinfo(); ?>
when accessed from browser using url http://localhost/phpinfo.php
<?php phpinfo(); ?>
使用URL从浏览器进行访问时, http://localhost/phpinfo.php
I have even tried enclosing the code above inside <html><body>
in which case the browser screen was blank
. 我什至尝试将上面的代码包含在<html><body>
在这种情况下, browser screen was blank
。
I am having the directory
defined for the host as below 我正在为主机定义以下directory
DocumentRoot "/var/www/html" <Directory "/var/www/html"> Options Indexes FollowSymLinks Order allow,deny Allow from all AllowOverride All </Directory>
The problem was solved by enabling and configuring virtual host, however I still think there was no absolute need for virtual host for making php work. 通过启用和配置虚拟主机解决了该问题,但是我仍然认为并没有绝对需要使PHP工作的虚拟主机。 Thoughts welcome on this
. Thoughts welcome on this
。
I then realised that I must enable and configure virtual host as well. 然后,我意识到我还必须启用和配置虚拟主机。 I followed steps below 我按照以下步骤
/etc/apache2/httpd.conf
在/etc/apache2/httpd.conf
以下行取消注释 LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
This will enable to define virtual hosts
in apache2
这将允许在apache2
定义virtual hosts
Edit file /private/etc/apache2/extra/httpd-vhosts.conf
and declare virtual host as below, comment any default virtual host declaration 编辑文件/private/etc/apache2/extra/httpd-vhosts.conf
并声明虚拟主机,如下所示,注释任何默认的虚拟主机声明
<VirtualHost *:80> DocumentRoot "/var/www/html" ServerName myserver ServerAlias myserver-pro ErrorLog "/private/var/log/apache2/myserver-error_log" CustomLog "/private/var/log/apache2/myserver-access_log" common </VirtualHost>
know that this file is included by default in /etc/apache2/httpd.conf
using line below. 知道此文件默认包含在/etc/apache2/httpd.conf
使用下面的行。
Include /private/etc/apache2/extra/httpd-vhosts.conf
and localhost/phpinfo.php
from browser just works awesome. 和来自浏览器的localhost/phpinfo.php
很棒。
Was having similar issue, but with Mac OS high Sierra 10.13.4. 遇到类似的问题,但Mac OS的Sierra 10.13.4较高。 Simply needed to enable php in apache: 只需在apache中启用php:
sudo nvim /etc/apache2/httpd.conf
uncomment the following line 取消注释以下行
#LoadModule php7_module libexec/apache2/libphp7.so
then restart apache 然后重新启动Apache
sudo apachectl restart
检查php中是否启用了PHP,查看启用了mod的文件夹并搜索PHP。
确保使用launchctl
停止所有HTTP服务,然后检查“活动监视器”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.