PHP code is returned instead of executed
Solution 1:
The configuration file /etc/apache2/mods-available/php5.conf
controls which files Apache recognizes as php scripts (based on their extensions).
Be default (in PHP 5.3.2), the file contains the following code:
<FilesMatch "\.ph(p3?|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
This affects files with the following extensions:
.php
.php3
.phtml
From our discussion in chat, I know that your files have a html
extension. The server was configured to treat .html
files as php files, but your home computer is not. That leaves you with two options:
Rename your
.html
files that contain php code to one of the above extensions.-
Replace the line
<FilesMatch "\.ph(p3?|tml)$">
in your
php5.conf
by<FilesMatch "\.(ph(p3?|tml)|html?)$">
and reload apache by executing the following command:
sudo service apache2 reload
In addition to the previously mentioned extensions, the new configuration also affects:
.htm
.html
Solution 2:
is apache running?
when open localhost, you must see "It works!" page.
if apache isn't running, you can use /etc/init.d/apache2 start
Maybe php module is not enabled. To enable
a2enmod php5
after
/etc/init.d/apache2 reload
You can use
tail -f /var/log/apache2/error.log
to see the error logs.