# Laravel App on Digital Ocean Ubuntu 19.04 droplet (Step by Step Guide)

By Bobby Iliev, 2019-06-12. https://bobbyiliev.com/post/laravel-app-on-digital-ocean-ubuntu-1904-droplet-step-by-step-guide/

This is a step by step guide on how to create a new droplet via your **Digital Ocean** control panel, manually install and configure your **LAMP** stack, deploy **Laravel** and then install **Voyager**.

We will go though the following steps:

1.  Create a droplet
2.  SSH to the droplet
3.  Install Apache, PHP and MySQL
4.  Install Composer
5.  Install Laravel
6.  Configure Apache
7.  Configure MySQL
8.  Install Voyager

At the end we would have a fully functional Laravel installation.

## Create a Droplet

Login to your Digital Ocean account:

__[https://cloud.digitalocean.com/login](https://cloud.digitalocean.com/login)__

Hit the Create a Droplet button:

![](https://cdn.devdojo.com/posts/images/June2019/Create-Droplet.png)

Choose the Ubuntu 19.04

![](https://cdn.devdojo.com/posts/images/June2019/Ubuntu-19.png)

Choose the size of your Droplet, I would recommend having at least 2GB of RAM

![](https://cdn.devdojo.com/posts/images/June2019/3-VM-size.png)

After that choose your region



![](https://cdn.devdojo.com/posts/images/June2019/4-region.png)

Lastly choose a name for your VM and hit the create button

![](https://cdn.devdojo.com/posts/images/June2019/5-choose-name.png)

Finally wait a minute or two and your server would be ready. You can then get your server IP that we would use to access the server

![](https://cdn.devdojo.com/posts/images/June2019/6-get-ip.png)

## Access the VM

We will use SSH to access the newly created droplet.

- For Linux and Mac you can use the builtin terminal.

- For Windows you could use [putty](https://www.putty.org/)

Run the command below (change the IP accordingly) and then enter your password:

```
ssh root@178.62.37.250
```

If you managed to access the server successfully, you should see the following:

![](https://cdn.devdojo.com/posts/images/June2019/8-accessed.png)

## Install Apache, PHP and MySQL

As we now have the VM up and running and we've managed to successfully SSH, we can now proceed with the setup.

We would need to first update the system

```
apt update
```

Then with this command here we would install all of the required **PHP** modules, **Apache** and **MySQL** in one go:

```
apt install apache2 apache2-utils curl mysql-server mysql-client php libapache2-mod-php php-mysql php-common php-mbstring php-xmlrpc php-soap php-gd php-xml php-mysql php-cli php-mcrypt php-zip -y
```

Now you have all of the required components to start with the **Laravel** deploy. You can test that apache is running by accessing your IP:

![](https://cdn.devdojo.com/posts/images/June2019/10-check-apache.png)

## Install Composer

We will use **[Composer](https://getcomposer.org/)** to deploy our Laravel project:

```
apt install composer
```

Then to test if composer is working, run:

```
composer
```

You should get this output here:

![](https://cdn.devdojo.com/posts/images/June2019/11-composer.png)

## Install Laravel

With all that out of the way, we can now deploy our Laravel project.

First go to the _/var/www/_ folder_:_

```
cd /var/www/
```

And run this command to create your Laravel project:

```
composer create-project --prefer-dist laravel/laravel project
```

Once this has been completed, we need to adjust our permissions:

```
chown -R www-data:www-data /var/www/project/
```

Example:

![](https://cdn.devdojo.com/posts/images/June2019/12-install.png)

## Configure Apache

Once the project has been created, we would have to configure Apache. We need to adjust the configuration a little bit so that the document root points to our Laravel project folder and make sure that the Apache server accepts the .htaccess file.

Open the following file with your favourite text editor:

```
nano /etc/apache2/sites-enabled/000-default.conf
```

Adjust the document root with the correct path to your Laravle public folder:

```
    DocumentRoot /var/www/project/public
```

Setup the server to accept the .htaccess file

```
   <Directory /var/www/project/public>
        Require all granted
        AllowOverride All
   </Directory>
```

At the end your Config should look something like this:

![](https://cdn.devdojo.com/posts/images/June2019/13-apache-config.png)

After that we have to enable **mod_rewrite,** we can do that with this command here:

```
a2enmod rewrite
```

After those changes make sure to run a config test and then restart **apache**

```
apachectl configtest
```

Restart Apache:

```
apachectl restart
```

Make sure that you can now access your new project via your browser by just visiting your IP:

![](https://cdn.devdojo.com/posts/images/June2019/14-running-apache.png)

## Configure MySQL

More often than not you would need a database for your project, so let's go ahead and configure MySQL.

First run this command to secure the installation:

```
mysql_secure_installation
```

The output that you would get would look something like this:

![](https://cdn.devdojo.com/posts/images/June2019/15-mysql-secure.png)

Now let’s create a database and a user for our Laravel app.

First access MySQL

```
mysql -u root -p
```

Then create your database and user:

```
mysql> CREATE DATABASE laravel_main;
mysql> GRANT ALL PRIVILEGES ON laravel_main.* TO 'laravel_user'@'%' IDENTIFIED BY 'SuperSecurePa55!';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
```

Example:

![](https://cdn.devdojo.com/posts/images/June2019/16-create-db.png)

Now that we have our new database and username, we have to adjust our .env file so that our Laravel can connect to the new database. Open your .env file with your favourite text editor and adjust the database details:

```
nano /var/www/project/.env
```

Adjust the Database section:

![](https://cdn.devdojo.com/posts/images/June2019/17-env.png)

## Install Voyager

If we want to go one step further now we could even install Voyager:

Go to your project dir /var/www/project

```
cd /var/www/project
```

Then run this command:

```
composer require tcg/voyager
```

Also Update your APP_URL in your .env file to your server IP.

Next, add the Voyager service provider to the config/app.php file in the providers array:

```
'providers' => [

// Laravel Framework Service Providers...

//...

// Package Service Providers

TCG\Voyager\VoyagerServiceProvider::class,

// ...

// Application Service Providers

// ...

],
```

To install Voyager without dummy data simply run

```
php artisan voyager:install
```

If you prefer installing it with the dummy data run

```
php artisan voyager:install --with-dummy
```

That's pretty much it! Now when you visit your http://your-IP/admin via your browser you would get the voyager login panel:

![](https://cdn.devdojo.com/posts/images/June2019/18-login.png)

The default login details for voyager are:

Username: **admin@admin.com**

Password**: password**

![](https://cdn.devdojo.com/posts/images/June2019/19-admin.png)

## Conclusion

That's pretty much it! Now you have a running Digital Ocean droplet with a LAMP stack along with Laravel and Voyager.

Feel free to reach out to me in case you get stuck :)
