PHP Classes

How to Deploy Laravel Applications on Vultr

Recommend this page to a friend!
  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Deploy Laravel...   Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)  

Author:

Updated on: 2024-08-29

Posted on: 2024-08-26

Categories: PHP Tutorials, Sponsored, Tools

Laravel is a popular PHP framework for developing applications. It allows developers to create packages that provide new features and make the framework more useful for developers using Laravel.

Read this article to learn how to deploy the package Laravel Marketplace App in the Vultr Web hosting service.




Loaded Article

Introduction

Laravel is a widely used PHP web framework that simplifies common tasks in web development. It offers a clear structure for organizing code and separates the application's logic from its presentation. Laravel provides tools for handling user authentication, managing databases, and creating web page templates. The framework includes features for protecting websites against common security threats and makes it easier to test code. With a supportive community and many ready-to-use add-ons, Laravel is a good choice for building small and large web applications.

In this article, you are going to deploy a Vultr server with the Laravel Marketplace App and host a Laravel application with Vultr Managed Database and Let's Encrypt SSL. The steps mentioned can be used to set up new Laravel applications or migrate existing applications.

Exploring Vultr's Laravel Marketplace App

  • Complete LAMP stack: Comes with Laravel 11.11.1, Apache 2.4.58, MySQL 8.0.37, and PHP 8.3.6 pre-installed and configured, providing a fully functional web development environment out of the box.

  • Security-Ready: Includes Certbot for easy SSL certificate installation, enhancing application security with HTTPS encryption.

  • Development Tools: Pre-installed Composer 2.7.7 for dependency management, and a pre-configured Laravel project structure in /var/www/html/my-laravel-app for immediate development.

  • Optimized Configuration: Apache virtual host files are pre-configured and stored in /etc/apache2/sites-available/, streamlining the setup process for hosting Laravel applications.

  • Latest Framework Features: Includes Laravel's robust ecosystem with features like Eloquent ORM, Blade Templating, Artisan CLI, task scheduling, and real-time event broadcasting capabilities.

Deploying a Server on Vultr

  1. Sign up and log in to the Vultr Customer Portal.

  2. Navigate to the Products page.

  3. From the side menu, select Compute.

  4. Click the Deploy Server button in the center.

  5. Select Cloud Compute as the server type.

  6. In the Choose Location section, select the region of your choice.

  7. In the Choose Image section, click the Marketplace Apps tab and select the Laravel image.

  8. In the Choose Plan section, select a plan as per requirement.

  9. Select any more features as required in the Additional Features section.

  10. Click the Deploy Now button on the bottom right corner.

  11. Refer to Deploy Vultr Managed Database for MySQL or Deploy Vultr Managed Database for PostgreSQL for deploying a managed database for your Laravel application.

Setting up DNS

  1. Navigate to the Products page.

  2. From the side menu, expand the Network dropdown, and select DNS.

  3. Click the Add Domain button in the center.

  4. Follow the setup procedure to add your domain name by selecting the IP address of your server.

  5. Set the following hostnames as your domain's primary and secondary nameservers with your domain registrar:

  • ns1.vultr.com

  • ns2.vultr.com

Deploying Laravel Application

In this section, you are going to deploy your Laravel application using an existing project, and secure it with Let's Encrypt SSL. And connect your application with Vultr Managed Database.

  1. Navigate into the existing Laravel project files.

$cd /var/www/html

  1. Backup the existing Laravel project files.

$ sudo mv my-laravel-app my-laravel-app-backup

  1. Upload your existing project.
    Use SCP or SFTP to upload your local Laravel project to the server. For ex: scp -r /path/to/your/local/project root@your_server_ip:/var/www/html/my-laravel-app

  2. Navigate into the Laravel project directory.

$ cd /var/www/html/my-laravel-app

  1. Copy the .env file.

$ cp .env.example .env

  1. Generate an app key.

$ cp .env.example .env

  1. Open .env file.

$ nano .env

  1. Update .env file with Vultr Managed Database credentials.

DB_CONNECTION=mysql DB_HOST=your_vultr_db_host

DB_PORT=your_vultr_db_port

DB_DATABASE=defaultdb

DB_USERNAME=your_vultr_db_username

DB_PASSWORD=your_vultr_db_password

  1. Database details can be retrieved from the Vultr Customer Portal.
    Save and close the file.

  2. Test database connection.

mysql -h your_vultr_db_host -P your_vultr_db_port -u your_vultr_db_username -p

  1. Set proper permissions.

$ sudo chown -R www-data:www-data /var/www/html/my-laravel-app && sudo chmod -R 755 /var/www/html/my-laravel-app/storage

  1. Run migrations.

$ php artisan migrate

  1. Install Certbot to secure application with SSL.

$ sudo apt install certbot python3-certbot-apache -y

  1. Request an SSL certificate for your domain.

$ sudo certbot --apache -d your_domain.com

  1. Update database configuration in config/database.php.

Copy'mysql' => [

    // ... other configurations ...

    'sslmode' => 'require',

],

  1. Set up firewall rules and allow incoming connections.

$ sudo ufw allow OpenSSH && sudo ufw allow 'Apache Full'

  1. Run migrations again.

$ php artisan migrate

  1. You can access your application on https://<your-domain>.

  2. For configuring backup strategy you can use Rclone, Veeam or Automatic backups for MySQL databases.

Conclusion

In this article, you deployed a Vultr server with the Laravel Marketplace App, hosted a Laravel application with Vultr Managed Database, and increased application security with Let's Encrypt SSL.

This is a sponsored article by Vultr. Vultr is the world’s largest privately-held cloud computing platform. A favorite with developers, Vultr has served over 1.5 million customers across 185 countries with flexible, scalable, global Cloud Compute, Cloud GPU, Bare Metal, and Cloud Storage solutions. Learn more about Vultr.




You need to be a registered user or login to post a comment

1,616,249 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:



Comments:

No comments were submitted yet.




  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog How to Deploy Laravel...   Post a comment Post a comment   See comments See comments (0)   Trackbacks (0)