Laravel

Laravel is an open-source PHP framework that provides a set of tools and resources to build modern PHP applications.

Software Included

Package Version License
Laravel 11.26.0 MIT License
Nginx 1.18.0 Custom
MySQL server 8.0.37 GPL 2 with modifications
PHP 8.3.12 PHP v3.01
Certbot 2.11.0 Apache 2
Composer 2.7.7 MIT license

Creating an App using the Control Panel

Click the Deploy to DigitalOcean button to create a Droplet based on this 1-Click App. If you aren’t logged in, this link will prompt you to log in with your DigitalOcean account.

Deploy to DO

Creating an App using the API

In addition to creating a Droplet from the Laravel 1-Click App using the control panel, you can also use the DigitalOcean API. As an example, to create a 4GB Laravel Droplet in the SFO2 region, you can use the following curl command. You need to either save your API access token) to an environment variable or substitute it in the command below.

curl -X POST -H 'Content-Type: application/json' \
         -H 'Authorization: Bearer '$TOKEN'' -d \
        '{"name":"choose_a_name","region":"sfo2","size":"s-2vcpu-4gb","image": "devdojo-laravel-20-04"}' \
        "https://api.digitalocean.com/v2/droplets"

Getting Started After Deploying Laravel

In addition to the package installation, the One-Click also:

  • Enables the UFW firewall to allow only SSH (port 22, rate limited), HTTP (port 80), and HTTPS (port 443) access.
  • Creates the initial Laravel configuration file to set up database credentials and allow the Laravel instance to connect to the database.
  • After you create a Laravel One-Click Droplet, you’ll need to log into the Droplet via SSH to finish the Laravel setup.

From a terminal on your local computer, connect to the Droplet as root. Make sure to substitute the Droplet’s public IPv4 address.

ssh root@your_droplet_public_ipv4

If you did not add an SSH key when you created the Droplet, you’ll first be prompted to reset your root password.

Then, the interactive script that runs will first prompt you for your domain or subdomain:

--------------------------------------------------
This setup requires a domain name.  If you do not have one yet, you may
cancel this setup, press Ctrl+C.  This script will run again on your next login
--------------------------------------------------
Enter the domain name for your new Laravel site.
(ex. example.org or test.example.org) do not include www or http/s
--------------------------------------------------
Domain/Subdomain name:

The next prompt asks if you want to use SSL for your website via Let’s Encrypt, which we recommend:

Next, you have the option of configuring LetsEncrypt to secure your new site.  Before doing this, be sure that you have pointed your domain or subdomain to this server's IP address.  You can also run LetsEncrypt certbot later with the command 'certbot --nginx'

Would you like to use LetsEncrypt (certbot) to configure SSL(https) for your new site? (y/n):

Next, run your Laravel migrations:

cd /var/www/laravel
php artisan migrate

At this point, you can visit the Droplet’s IP address or your domain name in your browser to see the Laravel installation.

The web root is /var/www/laravel, and the Laravel configuration file is /var/www/laravel/.env.

You can get information about the PHP installation by logging into the Droplet and running php -i.

In addition, there are a few customized setup steps that we recommend you take.

  • You should consider securing the MySQL instance by running the mysql_secure_installation command.
  • Creating an Nginx server block file for each new site and makes it easier to manage changes when hosting multiple sites.

To do so, you’ll need to create two things for each domain: a new directory in /var/www for that domain’s content, and a new server block file in /etc/nginx/sites-available for that domain’s configuration. For a detailed walkthrough, you can follow How to Set Up Nginx Server Blocks.

  • If you didn’t enable HTTPS during the initial setup script, you can enable it manually at any time after your domain name has been pointed to the Droplet’s IP address.

Setting up an SSL certificate enables HTTPS on the web server, which secures the traffic between the server and the clients connecting to it. Certbot is a free and automated way to set up SSL certificates on a server. It’s included as part of the Laravel One-Click to make securing the Droplet easier.

To use Certbot, you’ll need a registered domain name and two DNS records:

  • An A record from the domain (e.g., example.com) to the server’s IP address
  • An A record from a domain prefaced with www (e.g., www.example.com) to the server’s IP address

Additionally, if you’re using a server block file, you’ll need to make sure the server name directive in the Nginx server block (e.g., server_name example.com) is correctly set to the domain.

Once the DNS records and, optionally, the server block files are set up, you can generate the SSL certificate. Make sure to substitute the domain in the command.

certbot --nginx -d example.com -d www.example.com

For a more detailed walkthrough, you can follow How to Secure Nginx with Let’s Encrypt or view Certbot’s official documentation.

You can serve files from the web server by adding them to the web root (/var/www/laravel) using SFTP or other tools.

To add multiple websites, you can use the LaraSail automation script.

About DigitalOcean Managed DBaaS

If you select to install a DigitalOcean Managed Database while creating this 1-click app, DigitalOcean handles the creation of the database cluster as well as the Droplet. The Droplet will have a DATABASE_URL environment variable configured including a database connection string, such as:

*** postgresql://doadmin:@dbaas-db-11111-do-user-1111111-1.b.db.ondigitalocean.com:25060/defaultdb?sslmode=require***

Your managed database configuration and credentials will be stored in /root/.digitalocean_dbaas_credentials

Please note that there is additional configuration needed to connect your managed database to this Droplet after creation.