HugeServer Knowledgebase

How to install Laravel 5.5 + PHP 7.1 with Apache on CentOS 7

Introduction

Laravel is a powerful MVC-PHP framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications. Laravel was created by Taylor Otwell. In this guide, we will install Laravel 5.5 on CentOS 7 and as you might already know Laravel 5.5 depends on PHP 7.0+ so we are going to install the latest stable version of PHP which is 7.1 and finally serve the whole thing with Apache web server.

This Tutorial Contains

Laravel 5.5 Logo

We are assuming that you have root permission, otherwise, you may start commands with “sudo”.

Install Apache

You can install Apache easily using “yum” with the following command:

yum install httpd

After the installation process is finished you can use the commands below to start your Apache service and make it run at startup:

systemctl start httpd

systemctl enable httpd

Install PHP 7.1

PHP 7.1 is not provided by the official repository so you have to add “Webtatic” repo in order to install it easily.

First, install EPEL repository with the following command:

yum install epel-release

Now you can add the Webtatic repository using an RPM package:

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Update your repository list to fetch the latest packages with the command below:

yum repolist

execute the command below to easily install PHP 7.1 and the needed extensions:

yum install php71w php71w-xml php71w-mbstring php71w-mysql php71w-json php71w-curl php71w-cli php71w-common php71w-mcrypt php71w-gd php71w-zip

Download Composer

For installing the latest version of Laravel we need to get the Composer dependency manager:

curl -sS https://getcomposer.org/installer | php

Execute the following command to move your Composer binary file to the executable path:

mv composer.phar /usr/bin/composer

Now you can run the command below to download and install Laravel directly into your Apache document root:

composer create-project laravel/laravel /var/www/html/laravel

Set the correct DocumentRoot

Open the Apache configuration file:

nano /etc/httpd/conf/httpd.conf

Find the line that refers to:

DocumentRoot "/var/www/html"

and change it like below:

DocumentRoot "/var/www/html/laravel/public"

Then save and exit.

Restart Apache to take effect:

systemctl restart httpd

Set the Permissions

Execute the following command one by one to set the proper permissions:

chown -R apache:apache /var/www/html/laravel

chmod -R 755 /var/www/html/laravel/storage

Test if everything works fine

Now you can open your browser and see your public IP address or your Domain through it.

You should see a page like below:

Laravel Welcome Page

And you can verify that you installed Laravel 5.5 with the following command:

cd /var/www/html/laravel

php artisan -V

You probably see something like below:

Laravel Framework 5.5.25

 
For more information and news you can check out Laravel official website!

Was this tutorial helpful?

Thank you for your vote.Thank you for your vote.

Similar Posts

One thought on “How to install Laravel 5.5 + PHP 7.1 with Apache on CentOS 7”

  1. You’ll also want to install the SQL driver
    yum install php71w-mysql.x86_64
    as otherwise you’ll get PDO exception driver missing errors

Leave a Reply to Rob Cancel reply

Your email address will not be published. Required fields are marked *

*