Person Encoding in Laptop

How to Point Domain and Host Laravel Project on Apache Web Server VPS Hosting

Hosting a Laravel project on a VPS hosting server involves configuring your domain, setting up Apache, MySQL, PHP, and Composer, as well as making adjustments specific to Laravel. Let’s go through each step in detail.

Step 1: Configure Domain Settings

  1. Login to Your Domain Provider Website:
  • Access your domain provider’s website and log in to your account.
  1. Navigate to Manage DNS:
  • Find and navigate to the DNS management section.
  1. Add DNS Records:
  • Add the following DNS records to point your domain to your VPS:
    • A Record:
    • Host/Name: @
    • Value: Your Remote Server IP
    • A Record:
    • Host/Name: www
    • Value: Your Remote Server IP
    • AAAA Record (for IPv6):
    • Host/Name: @
    • Value: Your Remote Server IPv6
    • AAAA Record (for IPv6):
    • Host/Name: www
    • Value: Your Remote Server IPv6

Step 2: Copy Laravel Project to Remote Server

  1. Copy Project Zip File to Remote Server:
  • On your local Windows machine, zip your Laravel project folder.
  • Use SCP to copy the zip file to your remote server:
bash scp -P Port_number Source_File_Path Destination_Path
  • Example:
bash scp -P 22 root@
  1. Access Remote Server via SSH:
  • SSH into your remote server:
  • Example:
bash ssh -p 22 root@
  1. Unzip Project:
  • Navigate to the destination path where you copied the zip file.
  • Unzip the copied zip file:
bash unzip zip_file_name
  • Example:
bash unzip

Step 3: Verify Software Installation and Apache Configuration

  1. Verify Required Software:
  • Check if all necessary software is installed:
bash apache2 -v mysql php -v composer -v
  1. Verify Apache2 is Active:
  • Check the status of Apache:
bash service apache2 status
  1. Verify Web Server Ports and Firewall:
  • Check the status of ports and firewall rules:
bash ufw status verbose

Step 4: Configure Virtual Host for Laravel Project

  1. Create Virtual Host File:
  • Create a virtual host configuration file for your domain:
bash nano /etc/apache2/sites-available/your_domain.conf
  • Add necessary configuration details for Apache.
  1. Enable Virtual Host and Mod Rewrite:
  • Enable the virtual host:
bash a2ensite your_domain.conf
  • Enable the Apache mod_rewrite module:
bash a2enmod rewrite
  1. Restart Apache:
  • Restart Apache to apply changes:
bash service apache2 restart

Step 5: Configure Laravel Environment and Permissions

  1. Generate Application Key:
  • Generate a unique application key for Laravel:
bash php artisan key:generate
  1. Install Dependencies and Set Permissions:
  • Install Composer dependencies and optimize autoloader:
bash composer install --optimize-autoloader --no-dev
  • Set appropriate permissions for storage and bootstrap/cache directories:
bash sudo chown -R www-data:www-data storage bootstrap/cache
  1. Database Configuration:
  • Open the .env file and configure the database settings.
  1. Create Database Tables:
  • Run database migrations to create tables:
bash php artisan migrate
  1. Create Symbolic Link for Storage:
  • Create a symbolic link at public/storage pointing to storage/app/public:
bash php artisan storage:link

Step 6: Finalize Deployment and Maintenance

  1. Clear Cache and Enable Maintenance Mode:
  • Clear cache and enable maintenance mode if needed:
bash php artisan cache:clear php artisan config:clear php artisan route:cache # Optional php artisan config:cache # Optional php artisan view:cache # Optional php artisan down # Enable maintenance mode
  1. Deploy Your Laravel Project:
  • Your Laravel project should now be accessible via your domain. You can continue to develop and maintain your project on the live server.

By following these steps, you can successfully host your Laravel project on an Apache web server using a VPS hosting environment. Remember to keep your dependencies up to date and ensure proper security measures are in place for your production environment.