Serverless Laravel with Bref using AWS Lambda Part 2 Serverless Laravel with Bref using AWS Lambda Part 2

November 28, 2022

aws laravel

So my first idea is to get it working and up and running using my AWS ec2 debian instance which will call a lambda function and spider the website and save the data in the mysql db on the ec2 box.

Firstly I changed a few settings to work with Lambda. You can only write to the /tmp directory, so it is necessary to change these in the .env file. Following this tutorial

VIEW_COMPILED_PATH =/tmp/storage/framework/views 

pasted the following into app/Providers/AppServiceProvider.php

public function boot()
        // Make sure the directory for compiled views exist
        if (! is_dir(config('view.compiled'))) {
            mkdir(config('view.compiled'), 0755, true);

and run

php artisan config:cache

php artisan config:clear

mysql for remote access to EC2 instance

Next up I wanted to access a mysql db which is in an EC2 instance on AWS.

Update the mysql config in the /etc/mysql directory to allow external ips like so:

sudo nano 50-server.cnf

bind-address            =

you can alternatively bind to multiple addresses thus:

bind-address =,,

open the mysql db in the firewall

iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT

add a user to the mysql config

GRANT ALL ON database_name.* TO user@ IDENTIFIED BY 'password';

And most importantly, adding port 3306 for the mysql db to the AWS security group for the EC2 instance

aws security group

Testing the connection with

mysql -u user -h ec2ipAddress -p

so now I have a lambda laravel repo which can connect to an external database.

If you would like to contact me you can either use this form on or via Twitter @andylondon