<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashraf Chitambaa</title>
    <description>The latest articles on DEV Community by Ashraf Chitambaa (@ashrafchitambaa).</description>
    <link>https://dev.to/ashrafchitambaa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3161816%2Fac45ba8f-52b5-4e94-88c2-3c37b36aaf86.png</url>
      <title>DEV Community: Ashraf Chitambaa</title>
      <link>https://dev.to/ashrafchitambaa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashrafchitambaa"/>
    <language>en</language>
    <item>
      <title>Deploying Symfony 8 to cPanel Step by Step guide.</title>
      <dc:creator>Ashraf Chitambaa</dc:creator>
      <pubDate>Thu, 11 Jun 2026 21:31:50 +0000</pubDate>
      <link>https://dev.to/ashrafchitambaa/deploying-symfony-8-to-cpanel-step-by-step-guide-4k5o</link>
      <guid>https://dev.to/ashrafchitambaa/deploying-symfony-8-to-cpanel-step-by-step-guide-4k5o</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Double-check everything&lt;/li&gt;
&lt;li&gt;Configure your Environment Variables&lt;/li&gt;
&lt;li&gt;Install/Update your Vendors&lt;/li&gt;
&lt;li&gt;Clear your Symfony Cache&lt;/li&gt;
&lt;li&gt;Install symfony/apache-pack&lt;/li&gt;
&lt;li&gt;Update composer.json public directory&lt;/li&gt;
&lt;li&gt;Build the assets&lt;/li&gt;
&lt;li&gt;Update Kernel.php&lt;/li&gt;
&lt;li&gt;Upload the project to cPanel&lt;/li&gt;
&lt;li&gt;Final Thoughts&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;I'm new to Symfony and recently, I deployed a Symfony app to a shared hosting environment with cPanel.&lt;/p&gt;

&lt;p&gt;I could not figure out the best way to do it, let alone find useful resources online as most of them are outdated.&lt;/p&gt;

&lt;p&gt;I faced a lot of errors like: failing to load the app with a 500 Internal Server Error, some static assets not loading, etc. I figured it out in the end. This motivated me to write this post to reduce frustration for other Symfony newbies like me.&lt;/p&gt;

&lt;p&gt;Most deployment guides online assume you can run Composer, clear caches, execute migrations, and run Symfony commands directly on the server. In shared hosting environments, that is often not possible so, my examples will assume you don't have it installed on the server.&lt;/p&gt;

&lt;p&gt;Alright, let's get into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Double-check everything
&lt;/h2&gt;

&lt;p&gt;The first step to building for production is double-checking everything if it's in intact. Yes, this is very important. In my case, I was faced with some static image assets failing to load because of wrong reference which was ignored on dev mode. I had something like: &lt;code&gt;asset('/images/&amp;lt;filename&amp;gt;&lt;/code&gt;)&lt;code&gt;which was working in dev mode but failed to load the image in prod. the paths had to be like:&lt;/code&gt;asset('images/'). This was after checking how I defined other assets. So avoid things like this before hand.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Configure your Environment Variables
&lt;/h2&gt;

&lt;p&gt;For this, we will use the &lt;code&gt;dotenv:dump&lt;/code&gt; command which is not registered by default, so you must register first in your services:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# config/services.yaml&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Symfony\Component\Dotenv\Command\DotenvDumpCommand&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;~&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, run the command below. After running this command, Symfony will create and load the &lt;code&gt;.env.local.php&lt;/code&gt; file to get the environment variables and will not spend time parsing the &lt;code&gt;.env&lt;/code&gt; files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;prod &lt;span class="nv"&gt;APP_DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 php bin/console dotenv:dump
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Install/Update your Vendors
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--no-dev&lt;/span&gt; &lt;span class="nt"&gt;--optimize-autoloader&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Clear your Symfony Cache
&lt;/h2&gt;

&lt;p&gt;Make sure you clear and warm-up your Symfony cache by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APP_ENV&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;prod &lt;span class="nv"&gt;APP_DEBUG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 php bin/console cache:clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Install &lt;code&gt;symfony/apache-pack package&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;You can skip step if you already have it installed. The Symfony deployment documentation mentions that Apache shared hosting may need &lt;code&gt;apache-pack&lt;/code&gt;. To be safe, install it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require symfony/apache-pack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates the .htaccess configuration required for Symfony routing.&lt;/p&gt;

&lt;p&gt;Without it, Apache may display directory listings or fail to route requests through index.php.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Update &lt;code&gt;composer.json&lt;/code&gt; to override the public directory.
&lt;/h2&gt;

&lt;p&gt;Since cPanel uses &lt;code&gt;public_html&lt;/code&gt; as the public folder, add the following to &lt;code&gt;composer.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"extra"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"public-dir"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"public_html"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;composer.json&lt;/code&gt; is primarily used during the build process. Composer, Symfony Flex, recipes, asset installation, and other tools read it when Composer commands run.So, editing it after deployment does not reconfigure Symfony.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://symfony.com/doc/current/configuration/override_dir_structure.html#override-the-public-directory" rel="noopener noreferrer"&gt;Override Public Dir&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Build the assets
&lt;/h2&gt;

&lt;p&gt;I'm using assetMapper for this. I had tailwindcss installed so I had to build it first then compile the assets. Run the following commands in order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;symfony console tailwind:build
symfony console asset-map:compile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may encounter an error that &lt;code&gt;public_html&lt;/code&gt; directory does not exist. Don't panic, just edit the &lt;code&gt;public&lt;/code&gt; folder to &lt;code&gt;public_html&lt;/code&gt; and the error should be fixed.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Update &lt;code&gt;src/Kernel.php&lt;/code&gt; file.
&lt;/h2&gt;

&lt;p&gt;This step is important before we select the files we have to upload to &lt;code&gt;cPanel&lt;/code&gt;. We need to define the &lt;code&gt;project_dir&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;This parameter stores the absolute path of the root directory of your Symfony application, which is used by applications to perform operations with file paths relative to the project's root directory.&lt;/p&gt;

&lt;p&gt;By default, its value is calculated automatically as the directory where the main &lt;code&gt;composer.json&lt;/code&gt; file is stored. This value is also exposed via the &lt;code&gt;getProjectDir()&lt;/code&gt; method of the kernel class.&lt;/p&gt;

&lt;p&gt;Add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// src/Kernel.php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Symfony\Component\HttpKernel\Kernel&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;BaseKernel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Kernel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;BaseKernel&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;getProjectDir&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;\dirname&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;__DIR__&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can skip this step and upload the &lt;code&gt;composer.json&lt;/code&gt; file together with the &lt;code&gt;composer.lock&lt;/code&gt;(not really needed) since the Kernel an use it to determine the project_dir. However, the best way to do it is to add the above code.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="https://symfony.com/doc/8.0/reference/configuration/kernel.html#kernel-project-dir" rel="noopener noreferrer"&gt;kernel Project Dir&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Upload the project to &lt;code&gt;cPanel&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Important folders and files to upload:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bin/
config/
migrations/
public_html/ # in our case
src/
templates/
translations/ # if being used
vendor/
var/
.env.local.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exclude:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.git/
.github/
node_modules/
tests/
var/cache/
var/log/
assets/ # Note: this is not the public/assets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Symfony recreates cache and log files automatically.&lt;/p&gt;

&lt;p&gt;Now, zip the selected folders and files then, upload them. The rest is history, you're a developer.&lt;/p&gt;

&lt;p&gt;If you have reached this far, congratulations, your app should be running in production by now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Deploying Symfony 8 on shared hosting is definitely possible.&lt;/p&gt;

&lt;p&gt;The biggest challenge is understanding which files affect the build process and which files affect runtime behaviour. Upon understanding the distinction, deployment became much more easy.&lt;/p&gt;

&lt;p&gt;Read more here: &lt;a href="https://symfony.com/doc/8.0/deployment.html" rel="noopener noreferrer"&gt;How to Deploy a Symfony Application&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you!&lt;/p&gt;

</description>
      <category>symfony</category>
      <category>php</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
