PHP troubleshooting – Browser shows the PHP code instead of running it.

You have written your first PHP script and seeing the code in the browser instead of running the script? Here are few quick tips that will help you fix this issue.

Make sure you have a web server set up to run PHP. Even though most web servers support PHP, you can confirm it by any of the below two methods.

I) If you have the shell access on your server, run the command php -v in the shell to see if PHP is installed or not.
II) create a simple PHP script with the below content and upload it to the server.
<?PHP phpinfo(); ?>
Access the script to see your server’s PHP configuration.

Check the below points if your script is still not working.

I) Make sure your script is saved with .php extension.
II) Make sure you are not using short tags(<?) in your code. Use <?PHP instead. Not all servers have short tags enabled by default. If you already have developed a script with short tags you can enable the short tag support in php.ini file by setting short_open_tag=On.
III) Make sure you are accessing your file using a URL like http://localhost/index.php not like file://localhost/www/index.php


Leave a Reply