PHP code is not being executed, but the code shows in the browser source code
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 -v
from 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 forLoadModule 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.php
files 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
.php
extension 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<?php
instead (or enable short tags in your php.ini withshort_open_tag=On
if you have code that relies on them).Make sure you are accessing your file over your webserver using an URL like
http://localhost/file.php
not via local file accessfile://localhost/www/file.php
And lastly check the PHP manual for further setup tips.
php code not executing instead just showing on page screen
After setting xampp on your local pc, you've created a local server with apache, mysql, php stack. So when you write any php code, you need to execute/interpret it through your local server.
For example you need to use localhost/phpmailer_test/index.php
not file:///C:/xampp/htdocs/phpmailer_test/index.php
. If it was a .html
file then you can use the file path to execute it but for server side language like php, python and so called server side languages you've to execute your code base through a server.
PHP code is not being executed, but the code shows in the browser source code
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 -v
from 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 forLoadModule 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.php
files 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
.php
extension 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<?php
instead (or enable short tags in your php.ini withshort_open_tag=On
if you have code that relies on them).Make sure you are accessing your file over your webserver using an URL like
http://localhost/file.php
not via local file accessfile://localhost/www/file.php
And lastly check the PHP manual for further setup tips.
View PHP file, not downloading it
You need to configure a web server to execute the PHP locally.
You can install and run an actual webserver (e.g. nginx or apache) or run the embedded version of the php server.
Related Topics
Openssl Ssl_Read: Ssl_Error_Syscall, Errno 104
View My PHP Source Code in a Browser Via a Button
Object of Class Mysqli_Result Could Not Be Converted to String
Redirect That Same Page from Where Id Is Coming
Telegram Botapi, Send Message to Multiple Chat_Id
How to Prevent Multiple Inserts When Submitting a Form in PHP
How to Get Max and Min Value in a Multidimensional Array
Codeigniter Call to a Member Function Num Rows on Boolean
Session Id Is Changing After Every Request
How to Fetch Data After Selecting from Dropdown List
How to Set the Default Value of an Attribute on a Laravel Model
Codeigniter - Call to a Member Function Result() on Boolean In
How to Get Comma Separated Values from a Table in Laravel
Showing Image Binary Data Using JavaScript
How to Resolve MySQL Port 3306 Error on Wamp
Php Substring Remove Everything in a String After Certain Character