<?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: Fares Youssef</title>
    <description>The latest articles on DEV Community by Fares Youssef (@fares_youssef).</description>
    <link>https://dev.to/fares_youssef</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4219279%2F2e80a3e7-44d9-4bf9-99ad-b132a2640098.png</url>
      <title>DEV Community: Fares Youssef</title>
      <link>https://dev.to/fares_youssef</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fares_youssef"/>
    <language>en</language>
    <item>
      <title>How to Deploy a Laravel Application on Shared Hosting: A Complete Guide</title>
      <dc:creator>Fares Youssef</dc:creator>
      <pubDate>Sat, 31 Oct 2026 15:50:55 +0000</pubDate>
      <link>https://dev.to/fares_youssef/how-to-deploy-a-laravel-application-on-shared-hosting-a-complete-guide-19fc</link>
      <guid>https://dev.to/fares_youssef/how-to-deploy-a-laravel-application-on-shared-hosting-a-complete-guide-19fc</guid>
      <description>&lt;h1&gt;
  
  
  How to Deploy a Laravel Application on Shared Hosting: A Complete Guide
&lt;/h1&gt;

&lt;p&gt;Deploying a Laravel application on shared hosting can be challenging, especially when you're working with cPanel, limited server permissions, or an environment without full SSH access.&lt;/p&gt;

&lt;p&gt;While VPS and cloud hosting offer more flexibility, shared hosting remains a practical and affordable choice for many websites, small businesses, and client projects.&lt;/p&gt;

&lt;p&gt;In this guide, I'll walk through the essential steps for deploying a Laravel application on shared hosting, from preparing your project to configuring your database, optimizing performance, and avoiding common deployment mistakes.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Check Your Hosting Requirements
&lt;/h2&gt;

&lt;p&gt;Before uploading your Laravel project, make sure your hosting provider supports the requirements of your specific Laravel version.&lt;/p&gt;

&lt;p&gt;You will typically need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A compatible PHP version and required PHP extensions&lt;/li&gt;
&lt;li&gt;MySQL, MariaDB, or another supported database&lt;/li&gt;
&lt;li&gt;Composer or the ability to upload installed dependencies&lt;/li&gt;
&lt;li&gt;Apache with URL rewriting enabled, or an equivalent web server configuration&lt;/li&gt;
&lt;li&gt;File Manager or FTP access&lt;/li&gt;
&lt;li&gt;SSH access (recommended but not always required)&lt;/li&gt;
&lt;li&gt;Cron Jobs (if your application uses scheduled tasks)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Always check the official Laravel documentation for the version you're deploying.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Prepare Your Laravel Project
&lt;/h2&gt;

&lt;p&gt;Before deployment, make sure the application works correctly in your local environment.&lt;/p&gt;

&lt;p&gt;If your project uses Vite to compile frontend assets, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm ci
npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This generates production-ready CSS and JavaScript files, typically inside &lt;code&gt;public/build&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Make sure those generated files are included in your deployment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; Never use &lt;code&gt;npm run dev&lt;/code&gt; as your production asset strategy. The Vite development server is intended for local development.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Upload Your Project Securely
&lt;/h2&gt;

&lt;p&gt;One of the most important aspects of Laravel deployment is choosing the correct document root.&lt;/p&gt;

&lt;p&gt;Laravel's web entry point is located inside the &lt;code&gt;public&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;A recommended directory structure looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/username/
    laravel-app/
        app/
        bootstrap/
        config/
        database/
        public/
            index.php
            .htaccess
            build/
        resources/
        routes/
        storage/
        vendor/
        .env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your domain should point directly to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/home/username/laravel-app/public
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps sensitive Laravel files outside the publicly accessible directory.&lt;/p&gt;

&lt;p&gt;If your hosting provider allows you to change the document root in cPanel, configure it to point to the &lt;code&gt;public&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What if your main domain is locked to &lt;code&gt;public_html&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some shared hosting plans don't allow changing the main domain's document root.&lt;/p&gt;

&lt;p&gt;In that case, an alternative is to keep the application outside &lt;code&gt;public_html&lt;/code&gt;, copy only the contents of Laravel's &lt;code&gt;public&lt;/code&gt; directory into &lt;code&gt;public_html&lt;/code&gt;, and update the bootstrap paths in &lt;code&gt;index.php&lt;/code&gt; to match the actual directory structure.&lt;/p&gt;

&lt;p&gt;You must also ensure that public assets and storage links point to their correct locations.&lt;/p&gt;

&lt;p&gt;Never upload your entire Laravel project into a publicly accessible directory without properly securing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Install Composer Dependencies
&lt;/h2&gt;

&lt;p&gt;If SSH access is available, navigate to your Laravel project:&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="nb"&gt;cd&lt;/span&gt; /home/username/laravel-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the production dependencies:&lt;br&gt;
&lt;/p&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;p&gt;This installs the dependencies from your lock file without development packages.&lt;/p&gt;

&lt;p&gt;If your hosting provider doesn't support Composer, you may need to prepare compatible dependencies in another environment and upload the generated &lt;code&gt;vendor&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Make sure the dependencies are compatible with the PHP version running on your hosting server.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Configure Your Environment File
&lt;/h2&gt;

&lt;p&gt;Create your production &lt;code&gt;.env&lt;/code&gt; file in the Laravel application root, outside the web document root.&lt;/p&gt;

&lt;p&gt;A typical configuration looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APP_NAME="My Laravel App"
APP_ENV=production
APP_DEBUG=false
APP_URL=https://example.com

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace these example values with your actual hosting configuration.&lt;/p&gt;

&lt;p&gt;Also make sure your application has a valid &lt;code&gt;APP_KEY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For a brand-new application, you can generate one using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan key:generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Never regenerate your application key when deploying an existing application that already uses encryption.&lt;/strong&gt; Doing so can invalidate encrypted data and sessions.&lt;/p&gt;

&lt;p&gt;Two important production settings are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;APP_ENV=production
APP_DEBUG=false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Leaving debug mode enabled in production can expose sensitive application information.&lt;/p&gt;

&lt;p&gt;Never commit your production &lt;code&gt;.env&lt;/code&gt; file to Git.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Set Up Your Database
&lt;/h2&gt;

&lt;p&gt;Open cPanel and navigate to the database management section.&lt;/p&gt;

&lt;p&gt;Depending on your hosting provider, you may need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new MySQL database.&lt;/li&gt;
&lt;li&gt;Create a database user.&lt;/li&gt;
&lt;li&gt;Assign the user to the database.&lt;/li&gt;
&lt;li&gt;Grant the required permissions.&lt;/li&gt;
&lt;li&gt;Update your &lt;code&gt;.env&lt;/code&gt; configuration.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you're deploying an existing application, import the database backup using phpMyAdmin or another database management tool.&lt;/p&gt;

&lt;p&gt;For an application that uses Laravel migrations, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan migrate &lt;span class="nt"&gt;--force&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--force&lt;/code&gt; flag allows migrations to run in production without an interactive confirmation.&lt;/p&gt;

&lt;p&gt;Always back up your database before applying production migrations.&lt;/p&gt;

&lt;p&gt;Avoid destructive commands such as &lt;code&gt;migrate:fresh&lt;/code&gt; on a live application.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Configure Directory Permissions
&lt;/h2&gt;

&lt;p&gt;Laravel needs write access to two important directories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;storage/
bootstrap/cache/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact permissions depend on your hosting environment and PHP process ownership.&lt;/p&gt;

&lt;p&gt;A common configuration uses directory permissions such as &lt;code&gt;755&lt;/code&gt; or &lt;code&gt;775&lt;/code&gt;, provided the appropriate process has write access.&lt;/p&gt;

&lt;p&gt;Avoid setting your entire Laravel project to &lt;code&gt;777&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you experience errors involving logs, sessions, caching, or compiled views, verify the ownership and permissions of these directories first.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Create the Storage Link
&lt;/h2&gt;

&lt;p&gt;If your application stores public files using Laravel's public disk, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan storage:link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This normally creates a symbolic link:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public/storage
    -&amp;gt; storage/app/public
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some shared hosting providers restrict symbolic links.&lt;/p&gt;

&lt;p&gt;If this command fails, check whether your hosting environment supports them and verify your public directory configuration.&lt;/p&gt;

&lt;p&gt;When using a modified &lt;code&gt;public_html&lt;/code&gt; deployment structure, make sure the storage link is created in the actual web document root.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Optimize Laravel for Production
&lt;/h2&gt;

&lt;p&gt;Laravel provides several built-in optimization commands.&lt;/p&gt;

&lt;p&gt;For production deployments, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan optimize:clear
php artisan optimize
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;optimize&lt;/code&gt; command caches the applicable configuration, routes, events, and views to reduce unnecessary work during requests.&lt;/p&gt;

&lt;p&gt;You can also run individual commands when appropriate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php artisan config:cache
php artisan route:cache
php artisan view:cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One thing to remember: after caching configuration, you should not rely on calling &lt;code&gt;env()&lt;/code&gt; directly from application code outside configuration files.&lt;/p&gt;

&lt;p&gt;Use Laravel's &lt;code&gt;config()&lt;/code&gt; helper instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Configure Laravel Scheduler
&lt;/h2&gt;

&lt;p&gt;If your application uses scheduled commands, you will need to configure a Cron Job.&lt;/p&gt;

&lt;p&gt;Open cPanel and navigate to &lt;strong&gt;Cron Jobs&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A typical scheduler entry looks like this:&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="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;cd&lt;/span&gt; /home/username/laravel-app &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; /usr/bin/php artisan schedule:run &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /dev/null 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the paths with the correct project and PHP executable paths on your server.&lt;/p&gt;

&lt;p&gt;This executes Laravel's scheduler every minute.&lt;/p&gt;

&lt;p&gt;Your scheduled tasks can then be defined in Laravel without creating a separate cron entry for each task.&lt;/p&gt;

&lt;p&gt;Be aware that some shared hosting providers restrict the minimum cron frequency.&lt;/p&gt;

&lt;p&gt;For applications that depend heavily on persistent queue workers, WebSockets, or long-running processes, a VPS or managed Laravel hosting solution may be more appropriate.&lt;/p&gt;

&lt;h2&gt;
  
  
  11. Common Laravel Deployment Problems
&lt;/h2&gt;

&lt;p&gt;Here are some common issues you may encounter.&lt;/p&gt;

&lt;h3&gt;
  
  
  500 Internal Server Error
&lt;/h3&gt;

&lt;p&gt;Possible causes include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Incorrect PHP version or missing extensions&lt;/li&gt;
&lt;li&gt;Missing Composer dependencies&lt;/li&gt;
&lt;li&gt;Invalid environment configuration&lt;/li&gt;
&lt;li&gt;Incorrect file permissions&lt;/li&gt;
&lt;li&gt;Incorrect document root&lt;/li&gt;
&lt;li&gt;Web server configuration problems&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Start by reviewing your application logs and hosting error logs.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS and JavaScript Are Not Loading
&lt;/h3&gt;

&lt;p&gt;If your application loads but looks broken, check whether the Vite production assets were uploaded correctly.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then deploy the generated assets.&lt;/p&gt;

&lt;p&gt;Also verify that your web server can access the &lt;code&gt;public/build&lt;/code&gt; directory and that no stale Vite development-server configuration remains on production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Images Are Not Displaying
&lt;/h3&gt;

&lt;p&gt;Check the configured filesystem disk, uploaded file locations, and the public storage link.&lt;/p&gt;

&lt;p&gt;For applications using Laravel's public disk, the storage link is often the missing piece.&lt;/p&gt;

&lt;h3&gt;
  
  
  Laravel Routes Return 404
&lt;/h3&gt;

&lt;p&gt;If the homepage works but other routes return 404 errors, verify that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The domain points to the correct public directory.&lt;/li&gt;
&lt;li&gt;Apache rewrite rules are enabled.&lt;/li&gt;
&lt;li&gt;Laravel's &lt;code&gt;public/.htaccess&lt;/code&gt; is present when using Apache.&lt;/li&gt;
&lt;li&gt;Your web server forwards application requests to &lt;code&gt;index.php&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Changes Are Not Appearing
&lt;/h3&gt;

&lt;p&gt;Cached application configuration or views may explain why a recent change isn't visible.&lt;/p&gt;

&lt;p&gt;After reviewing your deployment, clear and rebuild the appropriate caches.&lt;/p&gt;

&lt;h2&gt;
  
  
  12. Final Deployment Checklist
&lt;/h2&gt;

&lt;p&gt;Before considering your Laravel deployment complete, verify the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;[ ] The domain points to the correct public directory.&lt;/li&gt;
&lt;li&gt;[ ] Production debug mode is disabled.&lt;/li&gt;
&lt;li&gt;[ ] Sensitive configuration files are not publicly accessible.&lt;/li&gt;
&lt;li&gt;[ ] Composer dependencies are installed.&lt;/li&gt;
&lt;li&gt;[ ] Database connectivity works.&lt;/li&gt;
&lt;li&gt;[ ] Migrations have been applied safely.&lt;/li&gt;
&lt;li&gt;[ ] Frontend production assets are available.&lt;/li&gt;
&lt;li&gt;[ ] Required directories are writable.&lt;/li&gt;
&lt;li&gt;[ ] Public file storage works.&lt;/li&gt;
&lt;li&gt;[ ] Scheduled tasks are configured when needed.&lt;/li&gt;
&lt;li&gt;[ ] HTTPS is enabled.&lt;/li&gt;
&lt;li&gt;[ ] Application logs show no unexpected errors.&lt;/li&gt;
&lt;li&gt;[ ] Authentication, forms, uploads, and critical application features have been tested.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Shared hosting isn't the perfect solution for every Laravel project, but it can be a reliable and affordable option for smaller applications when configured correctly.&lt;/p&gt;

&lt;p&gt;The most important things are keeping application files secure, pointing the domain to the correct public directory, using production-ready assets, and maintaining a predictable deployment process.&lt;/p&gt;

&lt;p&gt;As your application grows, you can consider moving to a VPS, managed Laravel hosting, or a cloud platform that offers better control over queues, workers, scaling, and automated deployments.&lt;/p&gt;

&lt;h2&gt;
  
  
  About the Author
&lt;/h2&gt;

&lt;p&gt;I'm &lt;strong&gt;Fares Youssef&lt;/strong&gt;, a Full-Stack Developer specializing in Laravel, PHP, React, REST APIs, and custom web applications.&lt;/p&gt;

&lt;p&gt;I enjoy building practical software solutions and sharing insights from web development.&lt;/p&gt;

&lt;p&gt;You can explore my work and projects on &lt;a href="https://www.faresyoussef.com" rel="noopener noreferrer"&gt;my personal website&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/deployment" rel="noopener noreferrer"&gt;Laravel Deployment Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/vite" rel="noopener noreferrer"&gt;Laravel Vite Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/scheduling" rel="noopener noreferrer"&gt;Laravel Task Scheduling&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://laravel.com/docs/13.x/filesystem" rel="noopener noreferrer"&gt;Laravel File Storage&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Have you deployed Laravel on shared hosting? Share the challenges you encountered in the comments!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
