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

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

Install Apache

You can install Apache 2 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 RHEL 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 repo:

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

Update your repository list with the command below:

yum repolist

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

yum install php71w php71w-common php71w-gd php71w-phar php71w-xml php71w-cli php71w-mbstring php71w-tokenizer php71w-openssl php71w-pdo

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/local/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 HTTPD global 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

If your Firewall is active you should execute the following commands in order to allow HTTP and HTTPS ports:

firewall-cmd –permanent –add-port=80/tcp

firewall-cmd –permanent –add-port=443/tcp

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

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

Was this tutorial helpful?

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

Similar Posts

25 thoughts on “How to install Laravel 5.5 + PHP 7.1 with Apache on CentOS 7”

  1. Thank you for taking the time to post the installation instructions. I have followed them to the letter. However, when I browse to the default Laravel page via my servers IP I still see the default Centos 123 Testing Page. Your assistance would be greatly appreciated. Peter

    1. Hi Peter,

      Your problem is probably because of the DocumentRoot configuration, Make sure to set the correct DocumentRoot from the “Configuring Apache” section and restart your Apache service.

      Thanks

        1. Hi,

          In some versions of Apache, Your running DocumentRoot configurations are in the following path:

          # /etc/httpd/sites-available/000-default.conf

          Change your DocumentRoot in that file then save and restart the service. your problem should be solved

          Thanks

          1. I had the same issue. What I did?
            Changed the SELinux settings to disabled and restarted the server. The Laravel page loads as the default one.

  2. Hello.
    Please tell me, why I am giving an error when entering the command:
    php artisan -V
    Error: PHP Parse error: syntax error, unexpected ‘?’ in /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php on line 233

    1. Hello,

      Regarding your problem, make sure that you are using the correct PHP (CLI) version (in this case PHP 7.0+) you can check your PHP version with the following command:
      # php -v

  3. might want to add ?
    firewall-cmd –permanent –add-port=80/tcp
    firewall-cmd –permanent –add-port=443/tcp
    Before adding this page would never load, how ever by adding this now it does. How ever now I’m dealing with the default Apache Test page :).

    1. Hi Brian,

      Thanks for the suggestion, we have modified the article.
      About your problem: make sure you have completed the “Set the correct DocumentRoot” section and then restart your Apache service with “systemctl restart httpd”.

      Thanks

  4. To enable write files in /var/www/html wiith SE linux enable, must run follow comand after “Set the Permissions”:
    chcon -R -t httpd_sys_rw_content_t /var/www/html/

    Works sweet! Great article!

    1. Thanks for this suggestion.
      I spent hours looking for a solution to this problem, and yours worked perfectly!!

  5. You put composer into /usr/bin, but that is a directory that should be controlled by yum. Don’t mess with stuff in there. Put composer into /usr/local/bin instead.

  6. Hi guys, thanks for the awesome article! Works perfectly, but I am having a little problem. After I install laravel, it works on “www.subplanet.org/public” but I want it work on “www.subplanet.org”. How can I solve this problem? Thank you for your helps! 🙂

    1. Hi friend,
      please check your /etc/httpd/conf/httpd.conf file.
      if it’s DocumentRoot “/var/www/html/laravel”
      change it to DocumentRoot “/var/www/html/laravel/public”

  7. Hello, how to change default PHP version on centos 7. my current version
    ————————
    I entered the command on Webmin command shall: php -v
    —————————– Result ——————————————-
    PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)
    Copyright (c) 1997-2013 The PHP Group
    Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
    —————————————————-
    But I still have PHP 5.6 and 7.0 installed on the server but it also shows the above result after entering the command ” php -v ” in shall.
    Thanks

  8. Thank you so much Please insert
    Mr. Carlos Bascunans Solution
    -> chcon -R -t httpd_sys_rw_content_t /var/www/html/
    to let Laravel Run in html folder instead of apache.
    This is very Helpful!!!!!
    🙂

Leave a Reply

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

*