Jakey.Dev

Laravel, vuejs and more dev stuff

Getting a DigitalOcean Droplet ready for Laravel

I wrote this article on Thursday, December 12, 2019

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!

TLDR;

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!

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!

$ mysql -u root
$ CREATE USER 'app'@'localhost' IDENTIFIED BY 'PUT_YOUR_NEW_PASSWORD_HERE';
$ GRANT ALL PRIVILEGES ON * . * TO 'app'@'localhost';
$ FLUSH PRIVILEGES;
$ exit;

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? 🙏

Yup - 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
$ wget https://gist.githubusercontent.com/JakePrice86/9086783c681b32465c7d26b8ef4ee41b/raw/5af170b0f920c738ea03bff9ade2761f432da4fb/everything.bash && bash everything.bash
Jakey.dev

A collection of my thoughts, experiments and videos based around my work as a web developer.

Links

Feeds