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.

INCLUDES:

  • Installing Apache
  • Installing PHP 7.1
  • Download & Install Composer
  • Configuring Apache
  • Set the Permissions
  • Test
Note:
We are assuming that you have root permission, otherwise, you may start commands with “sudo”.

Install Apache

First of all, you need to issue the following command to update your repository list:

apt-get update

Then you can install Apache 2 easily using “apt” with the following command:

apt-get install apache2

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 apache2

systemctl enable apache2

Install PHP 7.1

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

First, install Python Software Package with the following command:

apt-get install python-software-properties

Now you can add the preferred repository:

add-apt-repository ppa:ondrej/php

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

apt-get update

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

apt install php7.1 php7.1-xml php7.1-mbstring php7.1-mysql php7.1-json php7.1-curl php7.1-cli php7.1-common php7.1-mcrypt php7.1-gd libapache2-mod-php7.1 php7.1-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/apache2/sites-available/000-default.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 apache2

Set the Permissions

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

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

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

Test if everything works fine

Now you can open your favorite browser and enter your public IP address or Domain. Should see a page like this:

And you can  also verify that you have 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.19
Was this answer helpful? 0 Users Found This Useful (0 Votes)