I implemented my slim app and tested on localhost and everything seems to be working fine. I want to test the app on a shared host so that other developers can also access the apis.
I decided to deploy it to my shared host but not directly under the public_html rather in a subfolder called public_html/AppName.The reason is that I don’t want to lose my homepage accessible with the public.htlm in the public_html folder.
With FTP I uploaded all my files including the vendor folder so that I don’t need to install composer on the remote machine.
The problem is I can’t access any of my routes since it returns 404.
If call the root route /, I see the listing of my files under rather than the start page of the app.
I would appreciate if anyone could help me with this.
Kind regards
Ilker
Thanks for replying so fast. Yes it’s an apache web server.Actually there is no .htaccess file in public_html/subfolder. I only have one in the public_html.I can pretty new in Backend development so I apologise for my question but what should I need to write in .htaccess?
You will need one in there to route requests into the front controller. See Apache Configuration in the Slim Docs for an example. (There could be other issues as well, but that is a step in the right direction.)
didn’t help me a either.BTW the nested public_html is not listed when I call www.mysite.com/subFolder. This is the place where index.php resides.Could it be related with that ?
You shouldn’t need the public_html part in the RewriteRule unless that is actually in your public space.
Where is your front controller (index.php) relative to your document root? Based on what you’ve written above, I’d assume it is in AppName/public. Is that correct?
The actual place of the index.php is public_html/subFolder/public_html/index.php. I renamed the original public folder to public_html inside the slim project.
I assume the initial public_html is your document root? If so, inside SubFolder/public_html/, alongside the index.php file, you will need an .htaccess file with:
I tried an entry point http://www.mywebsite.com/fruitApp/products and got http status 500 , according to error logs of the server
[Thu Jun 01 15:45:46 2017] [warn] [client 212.114.132.66] mod_fcgid: stderr: PHP Parse error: syntax error, unexpected ‘class’ (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or ‘{’ or ‘$’ in /home/ilkerbal/public_html/fruitApp/vendor/slim/slim/Slim/Container.php on line 149.
the corresponding router is $app->get(’/products’, ‘ProductsController:getProducts’);
Sure, move everything in public_html up a directory level. Your index.php would then probably needed to be updated to point to the new relative location of the autoloader. Something else to keep in mind is that all of the files outside of your public directory should not be accessible from the outside as a security precaution, something that may or may not be possible with your shared host.
In one of your posts in the forum you advised to keep source file one level above the public_html folder. Do you think it is better practice to have it like this if I am allowed to write to root folder?
Best practice is to only have the public (or in your case public_html) folder exposed to the web. In the Slim-Skeleton example only the public folder would be exposed to the web as it would be the document root. All other files and directories wouldn’t be directly accessible.
I was api in same situation, when I moved to production the group function has just ‘/’, and always return 404. After some investigation I saw that routes are always with full path and add ‘/fruitApp’ (all path) to the route group.
My Problem was with routes was that index.php had a different place in the application when I uploaded to my host.Best practice is mimicking the remote folder structure when you develop on your local machine to avoid such problems.