Question

Wordpress droplet downloads file rather than serving

Hi,

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 127.0.0.1:9000;
        #}

        
}

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there @babelprashant94,

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

https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-lemp-on-ubuntu-18-04

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

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-ubuntu-18-04

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! Regards, Bobby