Reputation: 21493
I am using OS-X Capitan
and Apache/2.4.18 (Unix)
. I have below phpinfo.php
file
<?php phpinfo(); ?>
when I run the command php phpinfo.php
it will show phpinfo()
correctly. 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
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
AddType application/x-httpd-php .php
Made sure that libexec/apache2/mod_rewrite.so
exists
php -v gives below result
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
sudo apachectl restart
Still it shows the php code <?php phpinfo(); ?>
when accessed from browser using url http://localhost/phpinfo.php
I have even tried enclosing the code above inside <html><body>
in which case the browser screen was blank
.
Upvotes: 1
Views: 7755
Reputation: 1320
Was having similar issue, but with Mac OS high Sierra 10.13.4. Simply needed to enable php in apache:
sudo nvim /etc/apache2/httpd.conf
uncomment the following line
#LoadModule php7_module libexec/apache2/libphp7.so
then restart apache
sudo apachectl restart
Upvotes: 1
Reputation: 1
Make sure to use launchctl
to stop all HTTP Services, and check the Activity Monitor.
Upvotes: 0
Reputation: 21493
I am having the directory
defined for the host as below
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. 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
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
This will enable to define virtual hosts
in apache2
Edit file /private/etc/apache2/extra/httpd-vhosts.conf
and declare virtual host as below, comment any default virtual host declaration
<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.
Include /private/etc/apache2/extra/httpd-vhosts.conf
and localhost/phpinfo.php
from browser just works awesome.
Upvotes: 1
Reputation: 2006
Check if PHP is enabled in php, look at the folder mod-enabled and search for PHP.
Upvotes: 0