Wordpress droplet downloads file rather than serving

Posted June 2, 2020 536 views
NginxWordPressUbuntu 18.04


I need to migrate my website from old server to Digital Ocean.I stopped the apache2 server and installed nginx on the Wordpress droplet. On restarting the Nginx server and hitting the IP in the browser, I get a prompt to download the index.php file rather than the loading the WP website.
Upon searching the web, one of the solutions was to delete the .htaccess file. However, that file is missing from the /var/www/html directory.
What am I missing. Stuck on this for too long without any progress.
Below is my Nginx server block:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm  index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri  /index.php  =404;

        # pass PHP scripts to FastCGI server
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #        # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #        # With php-cgi (or other tcp sockets):
        #       fastcgi_pass;

edited by bobbyiliev

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.

Submit an Answer
1 answer

Hi there @babelprashant94,

I would recommend following the steps from this tutorial here on how to install WordPress with LEMP:

One of the prerequisites is to follow the steps from this tutorial here on how to install and configure LEMP:

As far as I can see the piece that is missing from your Nginx server block is the PHP FPM configuration:

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

Let me know how this goes!

by Justin Ellingwood
by Mark Drake
This tutorial details the process for installing and configuring the components that constitute a LEMP stack on an Ubuntu 18.04 server, including Nginx, MySQL, and PHP. It also includes instructions for testing that these components can communicate effectively and serve your content correctly.