HugeServer Knowledgebase

How to install Laravel 5.5 + PHP 7.1 with Apache on Ubuntu 16.04

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 Ubuntu 16.04 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

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 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.19

Check out Laravel official website for more information and news!

Was this tutorial helpful?

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

Similar Posts

11 thoughts on “How to install Laravel 5.5 + PHP 7.1 with Apache on Ubuntu 16.04”

  1. I stumbled through a lot of tutorials that failed miserably to tell me concisely and clearly what to do. Then I found yours and — laravel is looking good. Thanks a lot for the time you invested to do this!
    Ian

  2. You can also set the DocumentRoot this way:
    sudo sed -i ‘s/DocumentRoot.*/DocumentRoot \/var\/www\/html\/laravel\/public/’ /etc/apache2/sites-available/000-default.conf
    (all on one line)

  3. E: Some index files failed to download. They have been ignored, or old ones used instead.
    root@vps427958:/tmp/php-7-debian# 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
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package php7.1
    E: Couldn’t find any package by regex ‘php7.1’
    [SNIPPED]
    root@vps427958:/tmp/php-7-debian#

    Is the are tut that does work, none of them works.

    1. Hi Roel,

      This article has been tested on Ubuntu 16.04 as you see in the title, Installing PHP 7.1 on Debian could be different.

      Thanks

  4. Thanks this was exactly what I was looking to install. I think it was the php install line with all the dependancies that I needed but it finally works. Now I get to stop working about server installation and focus on learning Laravel. Thanks!

  5. error!!! please help me…

    Warning: require(/var/www/html/api1/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/miapi/public/index.php on line 24

    Fatal error: require(): Failed opening required ‘/var/www/html/api1/../vendor/autoload.php’ (include_path=’.:/usr/share/php’) in /var/www/html/miapi/public/index.php on line 24

  6. I have had to read through over 3 articles other than the official laravel documentation without success of installation.
    However, following every step on your article I managed to install successfully.
    There is a warning of Do not install using root (superuser) I had to ignore this and it went on successfully.
    Thank you.

Leave a Reply to Roel Cancel reply

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

*