<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Laravel Project Deploy on Ubuntu Server]]></title><description><![CDATA[Laravel Project Deploy on Ubuntu Server]]></description><link>https://laravel-project-deploy-on-ubuntu-server.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Sep 2026 10:34:21 GMT</lastBuildDate><atom:link href="https://laravel-project-deploy-on-ubuntu-server.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Laravel Project Deploy on Ubuntu Server]]></title><description><![CDATA[A comprehensive walkthrough for setting up a production-ready Laravel environment with Nginx, PHP 8.3, MySQL, Ubuntu server, and VPS hosting.
In today's digital landscape, efficiently deploying robust web applications is essential for developers and ...]]></description><link>https://laravel-project-deploy-on-ubuntu-server.hashnode.dev/laravel-project-deploy-on-ubuntu-server</link><guid isPermaLink="true">https://laravel-project-deploy-on-ubuntu-server.hashnode.dev/laravel-project-deploy-on-ubuntu-server</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Ubuntu]]></category><category><![CDATA[apache]]></category><category><![CDATA[deployment]]></category><category><![CDATA[server]]></category><dc:creator><![CDATA[Jalis Mahamud]]></dc:creator><pubDate>Fri, 11 Jul 2025 05:13:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1752210691263/ee382247-732c-42ec-a73f-a0c5dea6bd72.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>A comprehensive walkthrough for setting up a production-ready Laravel environment with Nginx, PHP 8.3, MySQL, Ubuntu server, and VPS hosting.</em></p>
<p>In today's digital landscape, efficiently deploying robust web applications is essential for developers and businesses. Laravel has become one of the most elegant PHP frameworks, offering a streamlined development experience. However, successful deployment requires careful configuration of various components to ensure optimal performance, security, and reliability.</p>
<p>This guide provides a comprehensive walkthrough for deploying a Laravel application on an Ubuntu server, covering everything from basic server setup to advanced configurations such as reverse proxies and automated deployments.</p>
<h2 id="heading-prerequisites"><strong>Prerequisites</strong></h2>
<ul>
<li><p>An Ubuntu server (preferably Ubuntu 22.04 LTS or newer)</p>
</li>
<li><p>SSH access with sudo privileges</p>
</li>
<li><p>A domain name pointing to your server (optional but recommended)</p>
</li>
<li><p>Basic knowledge of Linux commands</p>
</li>
</ul>
<h2 id="heading-step-1-install-and-configure-nginx"><strong>Step 1: Install and Configure Nginx</strong></h2>
<p>Nginx is a high-performance web server that will serve your Laravel application to users.</p>
<pre><code class="lang-bash">sudo apt update
sudo apt install -y nginx
sudo systemctl start nginx
sudo systemctl <span class="hljs-built_in">enable</span> nginx
</code></pre>
<h2 id="heading-step-2-install-php-83-and-required-extensions"><strong>Step 2: Install PHP 8.3 and Required Extensions</strong></h2>
<p>Laravel requires PHP and several PHP extensions to function properly. PHP 8.3 offers significant performance improvements over older versions.</p>
<pre><code class="lang-bash">sudo apt install -y php8.3 \
  php8.3-common \
  php8.3-opcache \
  php8.3-cli \
  php8.3-gd \
  php8.3-curl \
  php8.3-mysql \
  php8.3-mbstring \
  php8.3-zip \
  php8.3-xml \
  php8.3-intl \
  php8.3-bcmath \
  php8.3-soap \
  php8.3-fpm \
  php8.3-imagick \
  php8.3-ldap
</code></pre>
<p>Verify your PHP installation with:</p>
<pre><code class="lang-bash">php -v
</code></pre>
<h2 id="heading-step-3-set-up-mysql-database"><strong>Step 3: Set Up MySQL Database</strong></h2>
<pre><code class="lang-bash">sudo apt install -y mysql-server
sudo systemctl start mysql
sudo systemctl <span class="hljs-built_in">enable</span> mysql
</code></pre>
<h2 id="heading-step-4-create-database-and-user"><strong>Step 4: Create Database and User</strong></h2>
<pre><code class="lang-bash">sudo mysql -u root
</code></pre>
<pre><code class="lang-bash">CREATE USER <span class="hljs-string">'admin'</span>@<span class="hljs-string">'localhost'</span> IDENTIFIED BY <span class="hljs-string">'yourpassword'</span>;
GRANT ALL PRIVILEGES ON *.* TO <span class="hljs-string">'admin'</span>@<span class="hljs-string">'localhost'</span> WITH GRANT OPTION;
FLUSH PRIVILEGES;
CREATE DATABASE `tech_adda`;
EXIT;
</code></pre>
<p><strong><em>Note: Remember to replace 'yourpassword' with a strong, unique password in a production environment.</em></strong><br /><strong>Step 5: Install Supervisor for Queue Management</strong></p>
<h2 id="heading-step-5-install-supervisor-for-queue-management"><strong>Step 5: Install Supervisor for Queue Management</strong></h2>
<pre><code class="lang-bash">sudo apt-get install -y supervisor
sudo systemctl start supervisor
sudo systemctl <span class="hljs-built_in">enable</span> supervisor
</code></pre>
<h2 id="heading-step-6-install-git-for-version-control"><strong>Step 6: Install Git for Version Control</strong></h2>
<pre><code class="lang-bash">sudo apt-get install -y git
</code></pre>
<pre><code class="lang-bash">sudo mkdir -p /var/www/tech_adda
sudo chown -R www-data:www-data /var/www/tech_adda
</code></pre>
<h2 id="heading-step-8-clone-your-repository"><strong>Step 8: Clone Your Repository</strong></h2>
<p>For private repositories, you'll need to set up SSH keys:  </p>
<pre><code class="lang-bash"><span class="hljs-comment"># Generate SSH key</span>
ssh-keygen -t rsa -b 4096 -C <span class="hljs-string">"your-email@example.com"</span>

<span class="hljs-comment"># Display the public key to add to GitHub/GitLab</span>
cat ~/.ssh/id_rsa.pub
</code></pre>
<p>Then clone your repository:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /var/www
sudo git <span class="hljs-built_in">clone</span> https://github.com/yourusername/your-repo.git tech_adda
sudo chown -R www-data:www-data /var/www/tech_adda
</code></pre>
<h2 id="heading-step-9-configure-nginx-for-your-laravel-application"><strong>Step 9: Configure Nginx for Your Laravel Application</strong></h2>
<p>Create a new server block configuration:</p>
<pre><code class="lang-bash">sudo nano /etc/nginx/sites-available/tech_adda
</code></pre>
<p>Add the following configuration:</p>
<pre><code class="lang-bash">server {
    listen 80;
    listen [::]:80;
    server_name your-domain.com;  <span class="hljs-comment"># Replace with your domain</span>
    root /var/www/tech_adda/public;

    add_header X-Frame-Options <span class="hljs-string">"SAMEORIGIN"</span>;
    add_header X-Content-Type-Options <span class="hljs-string">"nosniff"</span>;

    index index.php;

    charset utf-8;

    location / {
        try_files <span class="hljs-variable">$uri</span> <span class="hljs-variable">$uri</span>/ /index.php?<span class="hljs-variable">$query_string</span>;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME <span class="hljs-variable">$realpath_root</span><span class="hljs-variable">$fastcgi_script_name</span>;
        include fastcgi_params;
        fastcgi_hide_header X-Powered-By;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
</code></pre>
<p>Enable the site and test your configuration:</p>
<pre><code class="lang-bash">sudo ln -s /etc/nginx/sites-available/tech_adda /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default  <span class="hljs-comment"># Remove default site if needed</span>
sudo nginx -t
sudo systemctl restart nginx
</code></pre>
<h2 id="heading-step-10-set-up-supervisor-for-laravel-queue-workers"><strong>Step 10: Set Up Supervisor for Laravel Queue Workers</strong></h2>
<p>Create a Supervisor configuration file:</p>
<pre><code class="lang-bash">sudo nano /etc/supervisor/conf.d/tech_adda.conf
</code></pre>
<p>Add this configuration:</p>
<pre><code class="lang-bash">[program:tech_adda-worker]
process_name=%(program_name)s_%(process_num)02d
<span class="hljs-built_in">command</span>=php /var/www/tech_adda/artisan queue:work --sleep=3 --tries=3
autostart=<span class="hljs-literal">true</span>
autorestart=<span class="hljs-literal">true</span>
user=www-data
numprocs=2
redirect_stderr=<span class="hljs-literal">true</span>
stdout_logfile=/var/www/tech_adda/storage/logs/worker.log
stopwaitsecs=3600
</code></pre>
<p>Update Supervisor:</p>
<pre><code class="lang-bash">sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start tech_adda-worker:*
</code></pre>
<h2 id="heading-step-11-configure-laravel-environment"><strong>Step 11: Configure Laravel Environment</strong></h2>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> /var/www/tech_adda
sudo cp .env.example .env
sudo php artisan key:generate
sudo php artisan config:cache
sudo php artisan route:cache
</code></pre>
<p>Install dependencies:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># For Composer dependencies</span>
sudo composer install --no-dev --optimize-autoloader

<span class="hljs-comment"># For frontend assets</span>
sudo npm install
sudo npm run production
</code></pre>
<h3 id="heading-set-proper-file-permissions"><strong>Set Proper File Permissions</strong></h3>
<p>Laravel requires specific permissions to function correctly. The web server needs to be able to write to certain directories:</p>
<pre><code class="lang-bash">
 <span class="hljs-built_in">cd</span> /var/www/tech_adda
 <span class="hljs-comment"># Set the web server as the owner</span>
 sudo chown -R www-data:www-data .
 <span class="hljs-comment"># Add your user to group</span>
 sudo usermod -a -G www-data user
 <span class="hljs-comment"># Set file(s) permission</span>
 sudo find . -<span class="hljs-built_in">type</span> f -<span class="hljs-built_in">exec</span> chmod 644 {} \;
 <span class="hljs-comment"># Set folder(s) permission</span>
 sudo find . -<span class="hljs-built_in">type</span> d -<span class="hljs-built_in">exec</span> chmod 755 {} \;
 <span class="hljs-comment"># Set cache directory permission</span>
 sudo chgrp -R www-data storage bootstrap/cache
 sudo chmod -R ug+rwx storage bootstrap/cache
</code></pre>
<p>These commands ensure that:</p>
<ul>
<li><p>All files have 644 permissions (owner can read/write, group and others can read)</p>
</li>
<li><p>All directories have 755 permissions (owner can read/write/execute, group and others can read/execute)</p>
</li>
<li><p>Storage and cache directories have 775 permissions (owner and group can read/write/execute, others can read/execute)</p>
</li>
</ul>
<blockquote>
<p><strong><em>Note: Incorrect permissions are a common source of issues in Laravel applications, particularly for caching, session handling, and file uploads.</em></strong></p>
<h2 id="heading-step-12-automated-deployments-optional"><strong>Step 12: Automated Deployments (Optional)</strong></h2>
<p>Create a deployment script for easier updates:</p>
</blockquote>
<pre><code class="lang-bash">sudo nano /var/www/deploy.sh
</code></pre>
<p>Add this script:</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
<span class="hljs-built_in">cd</span> /var/www/tech_adda
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
sudo supervisorctl restart tech_adda-worker:*
sudo systemctl restart php8.3-fpm
</code></pre>
<p>Make the script executable:</p>
<pre><code class="lang-bash">sudo chmod +x /var/www/deploy.sh
</code></pre>
<h2 id="heading-step-14-secure-your-installation"><strong>Step 14: Secure Your Installation</strong></h2>
<p>Install Certbot for SSL certificates:</p>
<pre><code class="lang-bash">sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com
sudo certbot --nginx -d proxy.your-domain.com  <span class="hljs-comment"># For your reverse proxy</span>
</code></pre>
<p>Set up a basic firewall:</p>
<pre><code class="lang-bash">sudo apt install -y ufw
sudo ufw allow <span class="hljs-string">'Nginx Full'</span>
sudo ufw allow ssh
sudo ufw <span class="hljs-built_in">enable</span>
</code></pre>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>You now have a fully configured Laravel application running on Ubuntu with Nginx, PHP 8.3, MySQL, and all the necessary components for a production environment. This setup provides:</p>
<ul>
<li><p>High-performance web serving with Nginx</p>
</li>
<li><p>Latest PHP version with optimized extensions</p>
</li>
<li><p>Reliable database with MySQL</p>
</li>
<li><p>Background job processing with Supervisor</p>
</li>
<li><p>Version control with Git</p>
</li>
<li><p>Optional reverse proxy capabilities</p>
</li>
<li><p>HTTPS security with Let's Encrypt</p>
</li>
<li><p>Basic firewall protection</p>
</li>
</ul>
<p>Remember to regularly update your server's packages and your Laravel application to maintain security and performance. With this foundation in place, your Laravel application is ready to serve users efficiently and securely.</p>
<hr />
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Thank you!</div>
</div>]]></content:encoded></item></channel></rss>