Experiments, status updates, tutorials and opinions on web development - particularly surrounding Laravel, Vue and interacting with third party APIs’.

Getting a DigitalOcean Droplet ready for Laravel

I wrote this on Thursday, December 12, 2019


Want a script that does all this for you? Skip to the end for a one-liner that I shamelessly use everytime I need a new enviroment!

When I am out and about, I tend to fire up a DigitalOcean droplet to do all my work on because of dodgy public WIFI - but I always need to play around and configure them manually. Here are my steps I take along with a quick and easy script to automate this!

Firstly - the settings I usually choose for my droplets are the following:

  • Choose an image -> LAMP on 18.04
  • Plan - Starter
  • $20 a month
  • London 1 (Because am based in the UK!)

There are a few issues with this droplet for Laravel development - below are what they are, and how we deal with them!

Composer isn't installed by default

This is the easiest one to remedy - go to Composer Download Page and run the command line installation. After installation I will usually make sure composer is available globally by following these extra instructions: Global install.

PHP dependancies missing! 😒

Awesome - composer is done, lets try a composer install. LOTS of errors! Lets fix that by installing the depencies that Laravel needs:

$ sudo apt-get install php7.2-curl php7.2-xml php7.2-zip php7.2-gd php7.2-mysql php7.2-mbstring -y

My URLS don't work?! 😠

Looks like mod_rewrite isn't enabled by default! Lets change that!

$ a2enmod rewrite

I can't connect to MYSQL?! 😑

Makes sense - all we are ever given by the DigitalOcean droplet is the ROOT password, which shouldn't be used by your app. To get round this, we'll need to create a new user, with its own password. MYSQL on the command line is fun - lets create a new user!

Before you continue - generate a really good, long password for your new user. I reccomend using this Random.org - use this link to get one generated for you!

Try and login to MYSQL again now with this user, entering your new password in when prompted to:

$ mysql -u app -p

Are we done now? πŸ™

Yeah - apart from a bit of apache vhost stuff of thats what you need! Lets restart APACHE and then you'll be good to go...

$ sudo service apache2 restart

You promised us a script! πŸ±β€πŸ’»

I did - and after you have read the above you *should* know how everything works! Run the below line and you'll be good to go in a few seconds after the server does the following:

  • Installs PHP 7.2
  • Sets up PHP dependancies
  • Installs Composer
  • Creates MYSQL user
  • Generates a password for the MYSQL user
  • Installs NODEJS
  • Sorts out vhost

Good luck 😎

$ wget https://gist.githubusercontent.com/JakePrice86/9086783c681b32465c7d26b8ef4ee41b/raw/5af170b0f920c738ea03bff9ade2761f432da4fb/everything.bash && bash everything.bash

Recommended Posts

The posts below have been selected based on the post you've just read!

Lets Stream - Side Projects

Serverless Websites