Shubham S Nimje logo
Shubham Nimje
Apache

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

How to Point Domain and Host Laravel Project on Apache Web Server VPS Hosting
3 min read
#Apache

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

Step 1: Configure Domain Settings

  1. Login to Your Domain Provider Website:

    • Access your domain provider’s website and log in to your account.
  2. Navigate to Manage DNS:

    • Find and navigate to the DNS management section.
  3. Add DNS Records:

    • Add the following DNS records to point your domain to your VPS:

      TypeHost/NameValue
      A@Your Remote Server IP
      AwwwYour Remote Server IP
      AAAA@Your Remote Server IPv6
      AAAAwwwYour 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:

      scp -P Port_number Source_File_Path Destination_Path

      Example:

      scp -P 22 osmsProject.zip root@216.32.44.12:/var/www
  2. Access Remote Server via SSH:

    • SSH into your remote server:

      ssh -p PORT USERNAME@HOSTIP

      Example:

      ssh -p 22 root@216.32.44.12
  3. Unzip Project:

    • Navigate to the destination path where you copied the zip file.

    • Unzip the copied zip file:

      unzip zip_file_name

      Example:

      unzip osmsProject.zip

Step 3: Verify Software Installation and Apache Configuration

  1. Verify Required Software:

    • Check if all necessary software is installed:

      apache2 -v
      mysql
      php -v
      composer -v
  2. Verify Apache2 is Active:

    • Check the status of Apache:

      service apache2 status
  3. Verify Web Server Ports and Firewall:

    • Check the status of ports and firewall rules:

      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:

      nano /etc/apache2/sites-available/your_domain.conf
    • Add necessary configuration details for Apache.

  2. Enable Virtual Host and Mod Rewrite:

    • Enable the virtual host:

      a2ensite your_domain.conf
    • Enable the Apache mod_rewrite module:

      a2enmod rewrite
  3. Restart Apache:

    • Restart Apache to apply changes:

      service apache2 restart

Step 5: Configure Laravel Environment and Permissions

  1. Generate Application Key:

    • Generate a unique application key for Laravel:

      php artisan key:generate
  2. Install Dependencies and Set Permissions:

    • Install Composer dependencies and optimize autoloader:

      composer install --optimize-autoloader --no-dev
    • Set appropriate permissions for storage and bootstrap/cache directories:

      sudo chown -R www-data:www-data storage bootstrap/cache
  3. Database Configuration:

    • Open the .env file and configure the database settings.
  4. Create Database Tables:

    • Run database migrations to create tables:

      php artisan migrate
  5. Create Symbolic Link for Storage:

    • Create a symbolic link at public/storage pointing to storage/app/public:

      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:

      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
  2. Deploy Your Laravel Project:

    • Your Laravel project should now be accessible via your domain. 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 VPS hosting. Remember to keep your dependencies up to date and ensure proper security measures are in place for your production environment.