Error Setting Up Nginx As A Reverse Proxy. PHP Shows Plain text

For reference, I am using the guide linked by this sentence.. The issues arise when it comes if my PHP is working. I installed Apache from scratch, as well as Nginx.

Using this command (sudo nano /etc/nginx/sites-available/example), I put in this as the configuration:

server {
        listen   80; 

        root /var/www/; 
        index index.php index.html index.htm;


        location / {
        try_files $uri $uri/ /index.php;

        location ~ \.php$ {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;


         location ~ /\.ht {
                deny all;

I then activated the virtual Nginx host, and deleted the default server block. Next I installed Apache. The first thing I did was (sudo nano /etc/apache2/ports.conf) in order to open the port file. I changed [Listen 80] to [NameVirtualHost Listen].

I then had to copy the layout from the default apache configuration file. The tutorial told me to use (sudo cp /etc/apache2/sites-available/default), but after looking it up, I was told the new default conf. file is (sudo nano /etc/apache2/sites-enabled/000-default.conf ). So I copy this file to (/etc/apache2/sites-available/example) and then using nano, I edit <VirtualHost *:80> to <VirtualHost>.

Before, when I used (sudo a2ensite example), it would say the a2ensite example didnt exist. To fix this, I had to add .conf to the end of /etc/apache2/sites-available/example. Is this correct?

Afterwords, I used ( sudo apt-get install php5) to get php5. This is where my issue comes in which so far I have found no solution to. After restarting both Apache and Nginx, when I create the php file with (sudo nano /var/www/info.php) , I try and visit the file in MYIPADDRESS/info.php and all it shows me is info.php in plain text!

Using (sudo netstat -plunt), I can see that my ports are correct. So I assume this is an error with my PHP compatability. I have been looking at this issue all day, and frankly, I think I’ve gone bald from how much stress I have gotten from it. I am using Ubuntu 14.04 for reference.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


This usually happens when there is no PHP handler configured. You could, for example, use Mod PHP:

sudo apt install libapache2-mod-php

Then restart Apache again:

systemctl restart apache2

That why Apache would ‘know’ how to handle those PHP files rather than displaying them in plain text.

Of course, there are better PHP handlers like PHP-FPM that you could use instead of the good old Mod PHP.

Regards, Bobby