I’m trying to execute some PHP code on a project (using Dreamweaver) but the code isn’t being run.
When I check the source code, the PHP code appears as HTML tags (I can see it in the source code). Apache is running properly (I’m working with XAMPP), the PHP pages are being opened properly but the PHP code isn’t being executed.
Does someone have a suggestion about what is happening?
Sounds like there is something wrong with your configuration, here are a few things you can check:
- Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run
php -vfrom a command line and see if returns version information or any errors.
- Make sure that the PHP module is listed and uncommented inside of your Apache’s httpd.conf This should be something like
LoadModule php5_module "c:/php/php5apache2_2.dll"in the file. Search for
LoadModule php, and make sure that there is no comment (
;) in front of it.
- Make sure that Apache’s httpd.conf file has the PHP MIME type in it. This should be something like
AddType application/x-httpd-php .php. This tells Apache to run
.phpfiles as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.
- Make sure your file has the
.phpextension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.
- Make sure you are not using short tags in the PHP file (
<?), these are not enabled on all servers by default and their use is discouraged. Use
<?phpinstead (or enable short tags in your php.ini with
short_open_tag=Onif you have code that relies on them).
- Make sure you are accessing your file over your webserver using an URL like
http://localhost/file.phpnot via local file access
And lastly check the PHP manual for further setup tips.
sudo a2enmod proxy_fcgi setenvif sudo a2enconf php7.0-fpm sudo service apache2 restart
I’m running Apache on Ubuntu and my issue was that the
/etc/apache2/mods-available/php5.conf file was missing this:
<FilesMatch ".+\.ph(p?|t|tml)$"> SetHandler application/x-httpd-php </FilesMatch>
I added it back in and PHP was parsing PHP files correctly.
You’re just opening your php file into browser. You have to open it using localhost url. if you open a file directly from your directory it will not execute the php code in any case.
Enable php short code. In your case, you are using
<? which is php short code for
<?php. By default php short codes are disabled.
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt if you are a ubuntu user.
I’m posting this answer because my Virtualmin/Webmin admin interface decided it was a good idea to disable my PHP engine.. took me a while to find the solution, so I thought I’d share it with you guys:
Also, be sure to check that none of your website config files related to this specific host or virtualhost have any php_admin_value’s in them that turn off PHP, like this:
php_admin_value engine Off
When in doubt, comment it…
# php_admin_value engine Off
And restart your webserver.
This just happened to me again, along with the server downloading html files, rather than processing. I had not use the webserver apache for some time on the computer and meanwhile Ubuntu updated like two more versions from originally installed LTS. Now it is
$ cat /etc/issue Ubuntu 16.04 LTS
So the php worked after like so:
$ sudo apt-get install lamp-server^ $ sudo a2enmod php7.0 $ sudo service apache2 restart
The webserver was now parsing the php. Maybe now got to update some webs since php7.0 now running where as it was before running php5. Oh well.
Hope this post helped you.
Follow Programming Articles for more!