Deploying Laravel on Cloud (AWS, DigitalOcean, or VPS)

Deploying Laravel on Cloud (AWS, DigitalOcean, or VPS)

1. Introduction to Cloud Deployment

Deploying Laravel on cloud platforms like AWS, DigitalOcean, or a VPS ensures scalability, security, and high performance.

2. Setting Up a Server

  • AWS: Create an EC2 instance with Ubuntu.
  • DigitalOcean: Create a Droplet with Ubuntu.
  • VPS: Get SSH access and set up an Ubuntu server.

3. Installing Required Packages

sudo apt update && sudo apt upgrade -y
sudo apt install apache2 php php-cli php-mbstring php-xml php-bcmath php-curl unzip git mysql-server -y

4. Setting Up Laravel Application

cd /var/www/
git clone https://github.com/your-repo.git laravel-app
cd laravel-app
composer install
cp .env.example .env
php artisan key:generate

5. Configuring Apache for Laravel

sudo nano /etc/apache2/sites-available/laravel.conf

Add the following:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    DocumentRoot /var/www/laravel-app/public
    ServerName yourdomain.com
    <Directory /var/www/laravel-app/public>
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

6. Setting Up Supervisor for Queues

sudo apt install supervisor
sudo nano /etc/supervisor/conf.d/laravel-worker.conf

Add the following:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/laravel-app/artisan queue:work
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/laravel-app/storage/logs/worker.log
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker

7. Securing with SSL

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d yourdomain.com

8. Conclusion

Deploying Laravel on AWS, DigitalOcean, or a VPS enhances application performance and security. Following these steps ensures a smooth cloud deployment.

Published by Developer Sahayak - Helping Developers Solve PHP, Laravel, and Drupal Issues.

0 Comments