Laravel out of the box

Last Updated: Oct. 28th 2022 at 4:05pm Tags: blog php laravel

Laravel out of the box explains how to install Laravel, to a working development condition, on a Ubuntu system using Sail and docker.

Laravel is a PHP framework, this article shows you how to get setup in Linux (in this case Ubuntu) with the use of docker and Laravel sail.

Requirements

I will be using “Laravel Sail” to setup the environment so docker and curl will be the only requirements.

Create a Laravel project

curl -s https://laravel.build/example-app | sudo bash

Change example-app to whatever you want the file directory called.

You could also add the get parameter with= to specify different services Learn more here, alternatively just modify the docker-compose file.

Start using sail

sudo chown -R $USER:$USER example-app
cd example-app
chmod -R 777 storage/

# Create an alias to make life easy
alias sail="sudo bash vendor/bin/sail"
sail up -d

# check what containers are running (they will be prefixes by project name)
sudo docker ps | grep example-app

# When you want to stop
sail down

The first run will take several minutes, but don’t worry subsequent starts will be much faster.

Now that you are running sail, you will want to run your commands with sail instead of php artisan, as follows:

# Running Artisan commands locally...
php artisan queue:work

# Running Artisan commands within Laravel Sail
sail artisan queue:work

sail php script.php

sail node --version

sail test

All done, check your install

Open your web browser and navigate to http://localhost:8000, where 8000 is the port you have set.

Sail Gotcha

Here are all the notes about problems I’ve had with Sail.

dotenv file and ports

I’m running other containers on my local machine including a reverse proxy and mariadb, so I had to change the ports that docker uses for laravel and mysql.

If you make changes to the dotenv, you will need to run a sail up again.

Here are some of the dotenv file modifications and additions I’ve tweaked:

APP_PORT

If you are familiar with Docker, you can just read the docker-compose.yml file if you ever forget the variable names.

Under the ports yaml you will find ‘${APP_PORT:-80}:80’ change the APP_PORT to something you like, I use:

APP_PORT=8000

FORWARD_DB_PORT

Again you will see under the ports section of the docker-compose file that FORWARD_DB_PORT is used to set the mysql port. I use:

FORWARD_DB_PORT=8306

Note: you might need to change the db port if the app is trying to connect externally.

APP_URL

If you are working locally, you will need to change your APP_URL:

APP_URL=http://localhost:8000/

References

Comments

You need to login to comment.