Skip to content

Instantly share code, notes, and snippets.

@bewithdhanu
Last active January 3, 2024 08:19
Show Gist options
  • Save bewithdhanu/79d0e5aae2d2d8da3de7d1ef299819b8 to your computer and use it in GitHub Desktop.
Save bewithdhanu/79d0e5aae2d2d8da3de7d1ef299819b8 to your computer and use it in GitHub Desktop.
This Gist provides a concise set of steps to set up a server for a Laravel-based web application. From cloning the repository to configuring Apache and running artisan commands, these steps guide you through a seamless server setup process.

Server Setup Gist:

  1. Open Server:

    • Access the server environment.
  2. Navigate to Root Directory:

    • Use the command: cd /var/www/html/ to reach the root directory.
  3. Clean Previous Files (Optional):

    • Delete any existing files in the directory with sudo rm -rf /var/www/html/* (Optional but recommended).
  4. Clone Repository:

    • Execute git clone [url] . to clone the repository.
  5. Install Composer:

    • Run sudo apt composer install to install Composer.
    • Execute composer install afterwards.
  6. Set Permissions:

    • Set permissions using the following commands [Mandatory]:
      sudo chmod -R 775 /var/www/html
      sudo chown -R $USER:www-data /var/www/html
      sudo chgrp -R www-data storage bootstrap/cache
      sudo chmod -R ug+rwx storage bootstrap/cache
      sudo chmod 0440 .env
      
  7. Create .env File:

    • Run sudo nano .env to create and edit the environment file.
    • Add database credentials to the file.
  8. Configure Apache:

    • Navigate to /etc/apache2/sites-enabled.
      cd /etc/apache2/sites-enabled
      
    • Open default-ssl.conf, with sudo sudo vi default-ssl.conf
    • if we don't have default-ssl.conf then open sudo vi 000-default.conf
    • Set the following configuration:
      DocumentRoot /var/www/html/public
      <Directory /var/www/>
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
      </Directory>
      
  9. Restart Apache:

    • Grant required permissions and restart Apache with sudo service apache2 restart.
  10. Run Artisan Commands:

    • Execute sudo -u www-data php artisan migrate and
    • sudo -u www-data php artisan passport:install.
  11. Setup Complete:

    • The server is now set up and ready to use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment