Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.

Get Started Now!

How to Deploy a Laravel Project on a Linux Server Using HTDOCS and GitHub – Complete Step-by-Step Guide

Deploying a Laravel project on a Linux server becomes simple when you follow a structured process. In this guide, we will deploy a Laravel project by cloning it from GitHub and placing it inside the htdocs directory, which is commonly used in XAMPP or LAMP-based server setups.

This tutorial is ideal for developers who prefer using the htdocs folder structure instead of the traditional /var/www directory.


Prerequisites

Before starting, ensure you have:

  • A Linux server with SSH access
  • GitHub repository of your Laravel project
  • Apache/XAMPP or LAMP stack installed
  • PHP and Composer installed
  • Database access (MySQL/MariaDB)
  • Basic Linux command knowledge

Step 1: Connect to Your Linux Server

Login via SSH from your local machine:

ssh username@server_ip

Example:

ssh myeventadmin@your_server_ip

Step 2: Update Your Server

Always update packages before setup:

sudo apt update && sudo apt upgrade -y

Step 3: Install Required Packages

Install Apache, PHP, Git, Composer dependencies, and tools:

sudo apt install apache2 mysql-server unzip git curl -y

Install PHP extensions required by Laravel:

sudo apt install php php-cli php-mysql php-zip php-gd php-mbstring php-curl php-xml libapache2-mod-php -y

Check PHP version:

php -v

Step 4: Install Composer

cd ~
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Verify installation:

composer -V

Step 5: Move to HTDOCS Directory

Depending on your server setup, the htdocs directory may be located at:

/opt/lampp/htdocs

or

/var/www/html

Navigate to htdocs:

cd /opt/lampp/htdocs

Step 6: Clone Laravel Project from GitHub

sudo git clone https://github.com/username/project.git

Move into project folder:

cd project

Step 7: Set Folder Permissions

sudo chown -R daemon:daemon /opt/lampp/htdocs/project
sudo chmod -R 775 storage
sudo chmod -R 775 bootstrap/cache

(If using Apache instead of XAMPP, replace daemon with www-data)


Step 8: Configure Environment File

Create the environment file:

cp .env.example .env
nano .env

Update important settings:

APP_NAME=Laravel
APP_ENV=production
APP_DEBUG=false
APP_URL=http://yourdomain.com

Add your database credentials as well.


Step 9: Install Laravel Dependencies

composer install

Step 10: Generate Application Key

php artisan key:generate

Step 11: Create Database and Run Migration

Login to MySQL:

sudo mysql

Create database:

CREATE DATABASE laravel_db;
EXIT;

Run migrations:

php artisan migrate

Step 12: Configure Apache to Use Public Folder

Edit Apache configuration:

sudo nano /opt/lampp/etc/extra/httpd-vhosts.conf

Add:

<VirtualHost *:80>
    ServerName yourdomain.com
    DocumentRoot "/opt/lampp/htdocs/project/public"

    <Directory "/opt/lampp/htdocs/project">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Restart Apache/XAMPP:

sudo /opt/lampp/lampp restart

Step 13: Test Laravel Application

Open browser:

http://your_server_ip/project/public

or

http://yourdomain.com

If everything is configured properly, your Laravel website will be live.


Important Production Tips

  • Always set APP_DEBUG=false
  • Never make .env publicly accessible
  • Ensure correct folder permissions
  • Use SSL (HTTPS) for live websites
  • Regularly pull updates from GitHub

Conclusion

Deploying a Laravel project using the htdocs directory and GitHub cloning is a practical and efficient workflow for Linux servers running XAMPP or Apache environments. By following this step-by-step process — cloning the repository, configuring environment variables, setting permissions, and configuring Apache — you can successfully deploy your Laravel application in a production-ready environment.

This method is especially useful for developers who prefer traditional htdocs-based hosting environments while maintaining version control through GitHub.

Related Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Artificial Intelligence
0
Would love your thoughts, please comment.x
()
x