Install And Setup Laravel Development Environment On Red Hat Linux

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

Install LEMP (Linux, Nginx, MySQL and PHP) On Red Hat Server With AttuneOps

This Blueprint Installs LEMP Stack Components On A RedHat 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.
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.
Pre-Blueprint Attune setup
  1. On the Inputs tab, create a Linux node for the host## This Blueprint Install LEMP Stack Components On A Red Hat Server 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

1 - Install Prerequisite For Rhel

We will being by installing epel-release respository for this automation task. This makes Nginx package available to be installed by Yum.

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 yum repository
sudo yum -y update

# Install epel repository
sudo yum -y install epel-release

2 - Install MySQL Server

Installs MySQL database server

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 MySQL server rpm
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

# Install MySQL Server rpm
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm

# Download and start mysql server
sudo yum -y install mysql-server

3 - Install PHP v7.4 and FPM

Installs PHP version 7.4 and PHP-FPM package which is used as the php interpreter for Nginx.

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 PHP remi repository
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

# Enable remi repository
sudo yum-config-manager --enable remi-php74

#Install dependencies
sudo yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/apr-1.4.8-7.el7.x86_64.rpm
sudo yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/apr-util-1.5.2-6.el7.x86_64.rpm
sudo yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/mailcap-2.1.41-2.el7.noarch.rpm
sudo yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/httpd-tools-2.4.6-95.el7.centos.x86_64.rpm
sudo yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/httpd-2.4.6-95.el7.centos.x86_64.rpm

# Install requiered php plugins 
sudo yum -y install php php-mysqlnd php-mbstring php-dom

4 - Install Laravel Project

Allows port 80 for HTTP traffic on the target machine

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
# Clone laravel scaffold proejct
wget https://github.com/laravel/laravel/archive/refs/heads/8.x.zip

# Install unzip
sudo yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/unzip-6.0-21.el7.x86_64.rpm
unzip 8.x.zip

# Install composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

# Install composer dependencies
cd laravel-8.x
COMPOSER_MEMORY_LIMIT=-1 composer install

# Configure laravel project
cp .env.example .env
php artisan key:generate

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

5 - Start Laravel Development Server

Finally, move the configuration files to their respective directories and restart the servers. To test that PHP is working fine with Nginx, a info.php file is created in the root directory of the server.

Visit http://YOUR_IP/info.php , once this step has been completed to verify the installation.

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 yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/screen-4.1.0-0.26.20120314git3c2946.el7.x86_64.rpm

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

# Change working directory
cd ~/laravel-8.x

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