heapzero
heapzero

Reputation: 1433

PHP in Mac OS X : Shows up the PHP code when opening the page

PHP Source Code is being shown up when opening PHP page in my localhost. This looks strange to me. I'm using using PHP 5.3.1 on Mac OS X Snow Leopard.

$ php --version
PHP 5.3.1 (cli) (built: Feb 28 2010 15:02:51) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

I'm running the default httpd webserver on my machine. The /etc/apache2/httpd.conf file has the following line to load php module:

LoadModule php5_module        libexec/apache2/libphp5.so

The httpd.conf file Syntax is OK.

$ httpd -t            
Syntax OK

am I missing something? Please suggest!

Thanks!

Upvotes: 6

Views: 10176

Answers (3)

M.Gökay Borulday
M.Gökay Borulday

Reputation: 350

For OS X Yosemite 10.10 need to add:

AddType application/x-httpd-php .php

Upvotes: 7

Marko Mitic
Marko Mitic

Reputation: 41

One possible reason why this is happening to you is because you're using short PHP tags <? instead of <?php

Either change that in all php files that are included or simply allow short PHP tags by adding short_open_tag=On in php.ini and then restart your apache server.

Upvotes: 4

mkoistinen
mkoistinen

Reputation: 7773

You need to add AddType to your server config:

AddType x-httpd-php .php

This can be added to the httpd.conf file, or even in an .htaccess file.

Upvotes: 7

Related Questions