Deploy Symfony 4 App in Shared Host.
So recently I had to host my Symfony 4 Application in Godaddy shared host ,but encountered so much problem with the URL esp with /public folder where index.php recides.
As we know when we first upload our Symfony 4 Files in host we need /public in URL to run our Application
In the official Symfony Docs they instruct to create .htaccess inside /public with the following command:-
composer require symfony/apache-pack
I tried ,but didn’t worked until I created .htaccess in public_html.
So here in this article I’m going to show you all how to deploy Symfony 4 Application successfully in shared host without /public in url in a very simple steps.
- Upload All your Files to the host using FTP.
- Create .htaccess in your main project folder like following
\public_html
bin
config
public
src
templates
translations
vendor
.env
.htaccess
composer.json
composer.lock
3. Set APP_ENV=prod in .env
4. Edit .htaccess (Avoid .htaccess in /public)
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/public/index.php [L]
</IfModule><IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 302 ^/$ /public/index.php/
</IfModule>
</IfModule>
5. If the images/css/js doesn’t load properly then add /public in css/js/image like following:-
<link rel="stylesheet" href="{{ asset('/public/css/style.css') }}">
<img src="{{ asset('/public/image/image.png') }}">
I hope the above steps works. I did exactly for my Symfony 4 application. If doesn’t work then then make sure you delete cache from var/cache/prod either manually or with the command:
php bin/console c:c