One minute
Install Symfony framework on CPanel hosting
Yesterday, I ordered a shared hosting package for malam.or.id and planned to run a minimal Symfony project on it.
I needed to customize the Symfony folder structure because the hosting used CPanel and Apache as the web server.
CPanel served all html files under public_html
directory and Symfony
uses public
directory as entry point or front page.
So, all I need to do is tell Symfony that we will use public_html
as front page instead of public
directory.
# new structure
root/
├─ public_html/
│ └─ index.php
└─ sfapp/
├─ bin/
├─ config/
├─ src/
├─ ...
├─ vendor/
└─ .env
To achieve this, we need to follow the instructions in the documentation.
-
Copy index.php from the
public
directory topublic_html
and change the path toautoload_runtime.php
file.
In my case, change to:require_once dirname(__DIR__).'/sfapp/vendor/autoload_runtime.php';
-
Add extra configuration to
composer.json
{ "extra": { "...": "...", "public-dir": "../public_html" } }
-
Because the hosting use Apache as web server, add
symfony/apache-pack
tocomposer
. This package will create a.htaccess
file inpublic_html
directory.
Done! we ready to deploy Symfony app to the hosting.
Source code: https://gitlab.com/team-amorid/malam.or.id