Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP code is not being executed, but the code shows in the browser source code

Tags:

php

apache

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?

Note: The file is already named as filename.php

Edit: The Code..:

<? include_once("/code/configs.php"); ?> 

The print

like image 349
Gui Avatar asked Feb 25 '11 19:02

Gui


People also ask

Why is my PHP file not running?

To get PHP execution working properly, you need to disable and then enable mpm_event_module, and enable mpm_prefork and php7 modules.

Can I do a view source and see the PHP code from browser?

PHP is a server-side programming language, meaning it is executed at the web server before the website is sent to the end-user. This is why you can't see the PHP code when you view the source code.

Why my PHP file is not working in HTML?

Php files can always read and display HTML code, but HTML does not automatically parse php code. To do so, you will need to make adjustments to your . htaccess file. Once that is done, the php code will display within HTML files without issue.

What is the PHP code line does not executed as a part of program?

A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code. Comments can be used to: Let others understand your code.


2 Answers

Sounds like there is something wrong with your configuration, here are a few things you can check:

  1. 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 -v from a command line and see if returns version information or any errors.

  2. 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.

  3. 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 .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

  4. Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

  5. 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 <?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them).

  6. Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php

And lastly check the PHP manual for further setup tips.

like image 91
shmeeps Avatar answered Sep 20 '22 17:09

shmeeps


php7 :

sudo a2enmod proxy_fcgi setenvif sudo a2enconf php7.0-fpm sudo service apache2 restart 
like image 36
sj59 Avatar answered Sep 21 '22 17:09

sj59