Placing .env files ouside the htdocs folder

I have made an account into infinityfree and upon ftp I noticed that there’s a folder named htdocs where in it contains the content served via http.

In my case I want this folder to have only an index.php whereas the secrets will be stored outside the htdocs in an .env file. Similar approach is used in moden php frameworks such as symfony and laravel as well.

But I is any file locates outside htdocs folder is cleaned up via a cron?
Also, can I reference as a library any php file located outside the htdocs folder as well?

Hi and welcome to the forum

Scripts can only write to the htdocs directories they are in. Any directories outside the htdocs dir cannot be written - due to the open_basedir restriction (is set for security reasons).

also

If you create some directory in htdocs and you add a .htaccess file with the content Require all denied, then nobody will be able to access the files directly either.

7 Likes

Is there a way to have a default public folder in htdocs and the / to serve content through it?

What I want is to serve only files located in ./htdocs/public whereas anything outside from it I want not to be served. I other words I want to set my website’s root folder as ./htdocs/public.

htdocs is the root of your website (public, www, and some other names on other servers)

so if you visit only the domain, the index file from htdocs will be served

3 Likes

Well yes, you can.

8 Likes