Author: Manuel Lemos
Updated on: 2024-08-26
Posted on: 2024-08-26
Categories: PHP Tutorials, Tools
Read this article to learn how to deploy the package Laravel Marketplace App in the Vultr Web hosting service.
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
Sign up and log in to the Vultr Customer Portal.
Navigate to the Products page.
From the side menu, select Compute.
Click the Deploy Server button in the center.
Select Cloud Compute as the server type.
In the Choose Location section, select the region of your choice.
In the Choose Image section, click the Marketplace Apps tab and select the Laravel image.
In the Choose Plan section, select a plan as per requirement.
Select any more features as required in the Additional Features section.
Click the Deploy Now button on the bottom right corner.
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
Navigate to the Products page.
From the side menu, expand the Network dropdown, and select DNS.
Click the Add Domain button in the center.
Follow the setup procedure to add your domain name by selecting the IP address of your server.
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.
Navigate into the existing Laravel project files.
$cd /var/www/html
Backup the existing Laravel project files.
$ sudo mv my-laravel-app my-laravel-app-backup
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-appNavigate into the Laravel project directory.
$ cd /var/www/html/my-laravel-app
Copy the .env file.
$ cp .env.example .env
Generate an app key.
$ cp .env.example .env
Open .env file.
$ nano .env
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
Database details can be retrieved from the Vultr Customer Portal.
Save and close the file.Test database connection.
mysql -h your_vultr_db_host -P your_vultr_db_port -u your_vultr_db_username -p
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
Run migrations.
$ php artisan migrate
Install Certbot to secure application with SSL.
$ sudo apt install certbot python3-certbot-apache -y
Request an SSL certificate for your domain.
$ sudo certbot --apache -d your_domain.com
Update database configuration in config/database.php.
Copy'mysql' => [
// ... other configurations ...
'sslmode' => 'require',
],
Set up firewall rules and allow incoming connections.
$ sudo ufw allow OpenSSH && sudo ufw allow 'Apache Full'
Run migrations again.
$ php artisan migrate
You can access your application on https://<your-domain>.
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,144 PHP developers registered to the PHP Classes site.
Be One of Us!
Login Immediately with your account on:
Comments:
No comments were submitted yet.