Why does my website show <?php ... ?> instead of my content?
When I browse my website, instead of my page I see something that looks like:
<?php ... ?>
What is happening here and how do I fix it?
When this occurs, you are looking at the actual script or program that is supposed to make the page you want instead of the actual page.
There are lots of ways this can happen. In general these problems fall in to a few categories:
php is not installed
php is not set to run at startup (it wasn't enabled)
php is not currently running (somebody stoppped it)
Your webserver is not configured properly
Your php file is missing it's .php extension or had a hidden .txt extension appended to it when editing it on a Windows system
How to ask for help
To make things more confusing this can happen with more than one kind of web server, so to detangle what is happening for YOU, we will first need to figure out which software is involved and where it is put on your system so you can ask the appropriate questions when seeking help:
There are too many ways to run php to cover them all here, but to get the answers you need you will want to be able to provide specifics.
We want to find out:
How we are running or want to run php
Which web server we are using
Which Linux distribution we are using so we can learn how to install things if needed
To find out some of this info, we will need to login to your Linode first so we can run commands on the server. You can use the following guide to get to your console:
This post assumes that you are either logged in as root or as a user that can run commands as root with the sudo command.
Which Web Server are We Using?
The two most popular web servers that could be running on your Linode are Apache and nginx.
To find out which web server is serving your page, you can run (replace example.com with your own website):
curl -I example.com ... Server: nginx ...
If you do not have curl installed on your Linode, you can use
sudo netstat -tpln (The flags mean, t=show tcp, p=show process information, l=only show listening processes, n=disable hostname lookup) and look for which programs are associated with ports :80 and :443.
Determining your Linux Distribution
Another piece of useful information is knowing which Linux distribution you are running. You can usually find this out by running:
sudo cat /etc/*release
Ways of running php
Here are some of the more more common ways php is run.
- mod_php (Apache)
This is probably the most common way php is run. It is built into the very common Apache web server
FastCGI (nginx or Apache)
PHP-FPM (nginx or Apache)