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.
Related videos on Youtube
joespam
Updated on September 18, 2022Comments
-
joespam almost 2 years
SOLVED: issue was the masonry-rails gem; it used an older fork of masonry that did not have the stamp option. Adding the masonry CDN to the project has resolved the issue.
I’ve been trying to get the ‘stamp’ functionality in masonry working in a Rails project. What I want is for the masonry items to fit themselves into the empty space around my 'stamp'ed object, and for my stamped object to be locked to the upper right corner of the parent element. However, the stamped element appears to be excluded from any Masonry positioning altogether, and instead masonry tiles everything in the div as if the stamp doesn’t exist in the layout. I can’t get the functionality to work the way I intend at all.
Nothing happens when I press the button in desandro's codepen example: https://codepen.io/desandro/pen/wKpjs, so I don't really know if I have some kind of browser/OS/library problem or if I'm just stamping wrong.
This is the current state of the page: images tiled underneath stamped element, instead of tiled around it
Layout in HAML:
#signupGal.centered - if @displayPix.present? - @displayPix.each_with_index do |pic,i| = link_to pic do .picTile{:id => "tile#{i}"} :javascript $('#tile#{i}').css({ "background-image":'url(' + "#{pic.image.url(:medium)}" + ')', "background-position":"center", "background-size":"cover" }); .signupForm.bg.tc
CSS:
.bg { background-color: rgb(63,168,161); } .tc { color: white; } .signupForm { width: 752px; height: 558px; position: absolute; right: 1%; top: 10px; width: 80%; border-radius: 5px; border: 3px solid white; padding: 1em; } #signupGal { max-width: 1200px; position: relative; .picTile { width: 160px; height: 120px; float: left; margin-bottom: 3px; margin-right: 3px; } } /* clearfix */ #signupGal:after { content: ''; display: block; clear: both; }
And in a coffeescript file:
$ -> $('#signupGal').imagesLoaded -> $gallery = $('#signupGal') $gallery.masonry isAnimated: true isFitWidth: true itemSelector: '.picTile' stamp: '.signupForm'
-
Dennis about 12 years1. The problem is [...] when on localhost. Does that mean it works from elsewhere? 2. [...] I can't seem to get php to execute [...] What exactly happens?
-
Russell Butler about 12 years1. Yeah it works when I have that very folder structure on the server. But if I copy the website to my local computer and put it into the localhost... no php. 2. What happends is that the php code simply gets printed directly instead of being interpreted.
-
Dennis about 12 yearsTry copying the files
/etc/apache2/mods-available/php5.*
from your server to your home computer and restartapache2
. Just to be sure, make backup copies first. -
Dennis about 12 yearsDo your php files have a non-standard extension? Did you copy all hidden files (specifically,
.htaccess
). Did you check the downloaded files in the (remote) case they got modified somehow by downloading? -
Russell Butler about 12 yearswhat im trying to run exactly now is not even a php file at all, its an .html file, and it ends with .html. I copied .htaccess.
-
Dennis about 12 years
-
Russell Butler about 12 yearsa very related question: superuser.com/questions/290964/php-not-working-on-fresh-install
-
-
Russell Butler about 12 yearsit's already installed and at the newest version.
-
Russell Butler about 12 yearsapache is running and the module is enabled. But when i run that tail command i get "[Wed May 16 13:24:11 2012] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico [Wed May 16 13:24:30 2012] [notice] caught SIGTERM, shutting down [Wed May 16 13:25:25 2012] [notice] Apache/2.2.17 (Ubuntu) PHP/5.3.5-1ubuntu7.8 with Suhosin-Patch configured -- resuming normal operations [Wed May 16 13:25:57 2012] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico "
-
Russell Butler about 12 yearsthe favicon error is weird because that picture file is definitely there.
-
Matthias about 12 yearsdo you check permissions?
-
Russell Butler about 12 yearsthe problem is solved so i don't really care. but thanks.