I need to be able to run my Slim project from a folder below public_html

I am a hobbyist. My living doesn’t depend on Slim but my fun does! I have a shared hosting account and I run several static websites as folders off public_html.

My question is: Can I deploy my Slim project by just uploading all the files to a folder below public_html? I think I could if I knew some way of moving index.php out of the public folder and into the project folder.


Yes, you can totally have index.php in the root folder. Just make sure you have a way to prevent any other PHP file being served by the web server.

OK how would i do that?

That will depend which webserver you are using (Apache, Nginx, IIS, etc). For Apache, I recall doing something like this before within a .htaccess file.

<Files *.php>
    Order Deny,Allow
    Deny from all

<Files index.php>
    Order Allow,Deny
    Allow from all
1 Like

Sorry I took so long to respond. tflight I will try that. Akrabat states in his reply, to be sure I have a way to prevent any other php file from being served by the webserver. Does this mean all the other PHP files in my other websites will be unable to run? I don’t just have the one website under one domain but I have several websites that I access different folders under public_html

Correct. You want to prevent all PHP files other than index.php from being accessed directly. Your hosting environment and site setup doesn’t sound ideal. Good hosting doesn’t cost much and will save you loads of time trying to overcome the limitations of bad hosting.

OK I guess I will stick with codeigniter amd cakepp. Both have their index.php files out side already. I have the ideal setup for me as I am a hobbyist and having one host per website would not be ideal.

I haven’t used Codeigniter in a long time, but Cake uses the same “front controller” approach. So while yes… you can install it that way the same vulnerability we’re suggesting you avoid with Slim would also apply to Cake, and probably Codeigniter too. The issue here isn’t unique to Slim.