How to Install Laravel on Amazon Linux 2

Hakan Bayraktar
2 min readFeb 4, 2019

--

Laravel is an open source PHP framework designed for the faster development of MVC web applications in PHP.

Setup Amazon Linux Extra

First of all, you need to check the system architecture.

cat /etc/*-release

Install Apache

sudo yum install httpd -y
sudo systemctl restart httpd
sudo systemctl enable httpd

Install MySQL

sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpmsudo yum install mysql-community-server -ysudo systemctl start mysqld
sudo grep 'temporary password' /var/log/mysqld.log
sudo mysql_secure_installation

Install PHP

To list the available topics, use the following command:

sudo amazon-linux-extras list

To enable PHP, use the following command:

sudo amazon-linux-extras enable php7.4

And now you can install PHP with php7.4-fpm and additionally libraries:

sudo yum install php-cli php-xml php-json php-mbstring php-process php-common php-fpm php-zip php-mysqlnd git -y

PHP version check:

php --version

Install Composer

Composer is required for installing Laravel dependencies. So use below commands to download and use as a command in our system.

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
sudo chmod +x /usr/bin/composer

Install Laravel

To download latest version of Laravel, Use below command to clone master repo of laravel from github.

cd /var/www/html
sudo git clone https://github.com/laravel/laravel.git

Dependencies installation will take some time. After that set proper permissions on files.

sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www && find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

Navigate to Laravel code directory and use composer to install all dependencies required for Laravel framework.

cd /var/www/html/laravel
composer install

Set Encryption Key:

cp .env.example .env

Now set the 32 bit long random number encryption key, which used by the Illuminate encrypter service.

php artisan key:generate

Create Apache Virtual Host

sudo vim /etc/httpd/conf/httpd.conf

Add the File bottom

<VirtualHost *:80>
ServerName laravel.example.com
DocumentRoot /var/www/html/laravel/public
<Directory /var/www/html/laravel>
AllowOverride All
</Directory>
</VirtualHost>

Disabling Apache Welcome Page

sudo mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf_backup

Restart Apache service and php-fpm service:

sudo systemctl start httpdsudo systemctl start php-fpm
sudo systemctl enable php-fpm

Now access the Laravel website in a web browser.

--

--

Responses (3)