403 Forbidden when changing index.html to index.php

I hope someone can help me here. I just want to change the index.html to index.php, but when I do so I get the 403 forbidden error. I followed a bunch of tutorials on permission and installing php etc. to no avail. I am a complete newbie, so most of the time I don’t really know what I am doing but I am trying to follow the tutorials.

If someone could give me complete newbie intructions on how to solve this, I’d be very grateful. I learned how to access files and other simple stuff but not much more.

I am using nginx on ubuntu. With the html files my website works fine, but I need it .php to run something.

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.

Hi @karpred , I had to start new answer again :D Thanks for the latest result, and please provide one couple more. So, it will be two files: get_me_and_remove_me_2 and get_me_and_remove_me_3


For sudoer:

sudo grep -e server_name -e root -e index -e include /etc/nginx/sites-available/* > ~/get_me_and_remove_me_2 && sudo cp /home/$USER/get_me_and_remove_me_2 /var/www/

For root:

grep -e server_name -e root -e index -e include /etc/nginx/sites-available/* > /var/www/get_me_and_remove_me_2


For sudoer:

sudo ls -la /etc/nginx/sites-enabled/  > ~/get_me_and_remove_me_3 && sudo cp /home/$USER/get_me_and_remove_me_3 /var/www/

For root:

sudo ls -la /etc/nginx/sites-enabled/  > /var/www/get_me_and_remove_me_3

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 @karpred,

It seems like you might not have PHP installed.

Please follow the last reply from @Yannek, they provided you with steps on how to install PHP on your droplet. See if that works.

Hello @karpred,

You need to check 2 or 3 things In your domain’s Nginx configuration file.

The first is your root or referred to as DocumentRoot directive. In your case it’s /var/www/html but are you sure that’s where your files are located? Enter that directory and see if the files are there or located in another folder named after your domain. If it’s the second option just add the domain in your root directive :

root /var/www/html

to be

root /var/www/html/

That’s only if the files are in the said folder.

The next thing to change would be the server_name

server_name _;

You should change it to include your domain


After you make those changes, restart nginx and see if your website works properly now.

Regards, KFSys

Hi @karpred , I had to start new answer because we got to many replies to the previous one :D

@karpred wrote
here is my config file code...

I meant nginx config file of your website, or rather nginx server block of your website. Sorry, I did not specify it clearly. This file is usually located in a directory /etc/nginx/sites-available/

@karpred wrote
I don’t know how to copy the code from the console

I do not know that too :) I ssh my droplets using gnome terminal what gives me text copy-paste feature. But in your case, having an FTP access to the droplet, you can transfer the file in easy way, e.g.

1. Copy the file to the directory you can reach with an FTP client

sudo cp /etc/nginx/sites-available/your_website_config /var/www/get_me_and_remove_me

2. Change an owner of the copied file

sudo chown your_ftp_user /var/www/get_me_and_remove_me

3. Get the file through the FTP and remove it from FTP directory. Now you can open this file in a text editor, copy text, and paste it here :)

@karpred wrote
When I use http://your_droplet_ip/index.php, I get a '404 Not Found’ now.

We are just one step to solving the problem, I think so :D