Laravel 12 installation on InfinityFree free hosting

Website URL

https://e-learning-ia.site.je

Error Message

No error yet. I have not deployed Laravel because I need to confirm the recommended secure installation structure for InfinityFree free hosting.

Other Information

Hello,

I want to deploy my Laravel 12 E-Learning application on InfinityFree free hosting.

My hosting account has PHP 8.4.27, the required PHP extensions, and an imported MySQL database.

My application uses Composer, Vite, DomPDF, and an external Python FastAPI service.

The file manager shows an htdocs directory and a warning not to upload files outside it.

I would like to know:

  1. Can I store the Laravel application files (app, bootstrap, config, vendor, storage, and .env) securely outside htdocs?
  2. If this is not possible, what is the recommended secure installation structure for Laravel?
  3. Can I use .htaccess to redirect requests to Laravel’s public directory and protect internal files?
  4. Does InfinityFree allow outgoing HTTPS requests to an external Python FastAPI service?

I have prepared the production dependencies locally but have not uploaded the application or any credentials.

Thank you for your help.

Welcome to the InfinityFree community forum! Good to have you here.

  • Most people answering here are volunteers. They’re often the fastest source of help. Admin (the only staff member) checks in about once a day for issues on our end.
  • Volunteers can’t see your account or website. Share what you actually see, like error messages and what happens when you try something. That’s more useful than your theory of what’s wrong.
  • AI tools often get InfinityFree wrong. If a volunteer’s advice differs from what an AI told you, please try the volunteer’s suggestion first.
  • Solving an issue is a joint effort. Try the suggestions you get and report back what happened.

Beep boop, I’m a bot! I dug through the forum to get you started. I sometimes get things wrong though, so do with this what you will until a human has a look.

1 and 2. I found an article that covers this. The web root on InfinityFree is always htdocs, and it can’t be changed. So the usual Laravel layout, with the app files outside the web root, isn’t the setup here. The recommended structure is to upload the whole Laravel project into htdocs, including vendor, storage and .env. Your local prep (composer install --no-dev, npm run build, no node_modules) matches what the article says to do.

Full guide:

3. Yes, and that’s how the article keeps it secure. You create a .htaccess in htdocs, next to Laravel’s own public/.htaccess, with this:

RewriteEngine On
RewriteRule (.*) /public/$1 [L]

Every request is then rewritten into public. A request for /.env or /storage/logs/laravel.log becomes /public/.env or /public/storage/logs/laravel.log. Those files don’t exist, so visitors get a 404. If you use the public disk for uploads, the article adds a storage/ rewrite rule before the catch-all, because symlinks aren’t supported. It also lists .env settings: APP_DEBUG=false, file sessions and cache, and QUEUE_CONNECTION=sync. It says scheduled tasks and queue workers can’t run on free hosting either.

4. Yes, with limits. Outbound requests from your site work through cURL, file_get_contents() and similar, so Laravel’s HTTP client is fine. But only ports 80, 443 and 587 are open, and they can’t be opened on request. Your FastAPI service therefore has to answer HTTPS on port 443, not on something like 8000 or 8080. Connections to blocked ports time out instead of being refused. The article also lists a few services that are blocked entirely, such as Discord, Telegram, Cloudflare Workers and Google Apps Script, so don’t host the FastAPI service on one of those. Outbound IPs aren’t fixed, so you can’t allowlist your site’s IP on the FastAPI side.

Details on ports and blocked services:

The article still works, but it is not possible to place files outside of the htdocs folder, but only if the domain has it’s own folder, not if it’s linked to the main htdocs folder. If you have a free subdomain now, you can remove it and then add it again to have it assigned to a domain specific folder.

Besides that, everything that Lemni said applies.