Deploy Symfony 4 App in Shared Host.

Pranan Subba
1 min readSep 18, 2019

--

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

eg. http://example.com/public

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.

  1. Upload All your Files to the host using FTP.
  2. 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

--

--

Pranan Subba
Pranan Subba

Written by Pranan Subba

0 Followers

<?php echo “Hello World!”; ?>

No responses yet