Install And Setup Laravel Development Environment On Ubuntu

Exported on 28-Sep-2021 12:28:57

Install Laravel Development Environment On Ubuntu Server With AttuneOps

This Blueprint Installs LEMP Stack Components On A Ubuntu Server

Laravel is a free, open-source PHP web framework, created by Taylor Otwell and intended for the development of web applications following the model–view–controller architectural pattern and based on Symfony.

Laravel makes it easy to develop production ready websites and backend APIs with its power packed development utilities. Using Laravel saves a lot of time and cost as it brings along the basic requirements of any backend service such as Authentication, Notifications, Models, Views, Controllers, Middle-wares, etc.

Pre-Blueprint Attune setup
  1. On the Inputs tab, create a Linux node for the host you wish to install the stack on.
  2. On the Inputs tab, create Linux credentials to connect to the host you wish to install the stack on.
Steps Involved
  • Install and configure PHP
  • Install composer - PHP package management system
  • Clone Laravel project
  • Install MySQL 8 database.
  • Configure and launch Laravel development server

Parameters

Name Type Script Reference Default Value Comment
Linux Node Linux / Unix Server linuxNode
Linux User Linux OS Credential linuxUser
Linux node Linux / Unix Server linuxNode
Linux user Linux OS Credential linuxUser

1 - Install PHP

Installs PHP 7.3 and following PHP extensions:

  • MySQL client
  • MbString
  • XML
  • ZIP
  • BcMath
  • MyCrypt
The connection details have changed from the last step.

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Update apt repositories
sudo apt update

# Install PHP 7.4
sudo apt -y install php
sudo apt -y install php-mysql php-common php-mbstring php-xml php-zip php-bcmath zip unzip php-zip php-dev

# Install MyCrypt extension
sudo apt-get -y install libmcrypt-dev
echo "y" | sudo pecl install mcrypt

# Enable MyCrypt extension
sudo bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.4/cli/conf.d/mcrypt.ini"

2 - Install Composer

Installs composer for PHP dependency management.

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Download composer installer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

# Setup composer
php composer-setup.php

# Add to path
sudo mv composer.phar /usr/local/bin/composer

3 - Setup Laravel

Downloads Laravel project scaffold, configures laravel environment and installs composer dependencies.

The connection details have changed from the last step.

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Download composer
git clone https://github.com/laravel/laravel.git

# Install dependencies
cd laravel && composer i

#Create .env file
cp .env.example .env

#Set MySQL password
sed -i 's/DB_PASSWORD=/DB_PASSWORD=rootpass/g' .env

# Generate Laravel application key
php artisan key:generate

4 - Install MySQL8

Install MySQL database server and configures the UFW firewall.

4.1.1 - Enable UWF Firewall

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Enable UFW and allow SSH & MySQL Ports
sudo apt install ufw -y
sudo ufw enable
sudo ufw allow 22
sudo ufw allow 3306

4.1.2 - Setup sql

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
sudo apt update

# Install MySQL (MariaDB) Server in a Non-Interactive mode. Default root password will be "root"
export DEBIAN_FRONTEND=noninteractive
sudo debconf-set-selections <<< 'mariadb-server-5.5 mysql-server/root_password password rootpass'
sudo debconf-set-selections <<< 'mariadb-server-5.5 mysql-server/root_password_again password rootpass'

sudo apt-get install mysql-server -y
sudo service mysql restart

5 - Start Laravel Dev Server

Starts the Laravel development server in background.

Once this step is complete, open http://YOUR_IP:8000 to see the installation.

Note: the development server is running in a screen session inside the target machine in background, which can be accessed with the command "screen -x"

The connection details have changed from the last step.

Login as user on node

Connect via SSH
ssh user@hostname
This is a Bash Script make sure you run it with bash -l from a terminal session
# Install screen
sudo apt -y install screen

# Configure screen 
sudo echo "zombie xy" >> ~/.screenrc

# Change working directory
cd ~/laravel

# Start Laravel artisan server in backaground
screen -d -m php artisan serve --host 0.0.0.0