How To install Laravel on a Raspberry Pi

Why Laravel?

Why should you install Laravel on the Raspberry Pi? There are many reasons for this. With Laravel you can develop professional web applications. It’s free and easy to use, making it a perfect framework for object-oriented programming according to many experts. Laravel has an expressive and elegant syntax that is simple for even inexperienced programmers, Laravel also offers a wide range of libraries, tools, and templates.. The framework is based on the model-view-controller (MVC) architectural pattern that facilitates the management of complex and large-scale projects.

Screen once Laravel is installed
Default screen once Laravel is installed on your Raspberry Pi

 

Table of Contents

  • Why Raspberry Pi?

  • Installing the software components for Laravel on Raspberry Pi

    • Step 1: Update package sources, upgrade software

    • Step 2: Install Apache and PHP

    • Step 3: Install MariaDB as database and security settings

    • Step 4: Set user access to database

    • Step 5: Install database software “phpmyadmin

      • Step 6: Download, install and update Composer

    • Step 7: Add missing packages

    • Step 8: Create a project with Laravel on Raspberry Pi

    • Step 9: Test the executability of your PHP framework Laravel

Why Raspberry Pi?

The main argument is the use of a low-cost development environment. The Raspberry Pi scores with:

  • Very low power consumption;

  • Good performance;

  • Resource-saving operating system Raspberry Pi OS;

Furthermore, we recommend a working memory of at least 4 GB. The variant with 8 GB of memory is even better.

Installing the software components for Laravel on Raspberry Pi

Now we will show you how to set up the PHP framework Laravel. For this we use the Raspberry Pi OS operating system . This used to have the name Raspbian.

Step 1: Update package sources, upgrade software

Before installing, you should update the package sources and upgrade the packages.

  • sudo apt-get update

  • sudo apt upgrade

Step 2: Install Apache and PHP

The packages for Apache and PHP serve as the basis for the PHP framework Laravel. Install them now.

  • sudo apt-get install apache2

  • sudo apt-get install php

Step 3: Install MariaDB as database and security settings

First, install the packages for the database. After that, you can go through the security settings. If you confirm the prompts with yes, the MariaDB security standard will be activated.

  • sudo apt-get install mariadb-client

  • sudo apt install mariadb-server

  • sudo mysql_secure_installation

Step 4: Set user access to database

In this step you define the user for the database. You also set read and write permissions for all tables. Instead of the user “pi” we recommend another user name. Use a secure password of your own instead of YOURPASSWORD. With the command “sudo mysql” you get into the console of MariaDB.

  • sudo mysql

  • CREATE USER ‘pi’@’localhost‘ IDENTIFIED BY ‘YOURPASSWORD’;

  • GRANT ALL PRIVILEGES ON . TO ‘pi’@’localhost‘;

Step 5: Install database software “phpmyadmin

Finally, install the software “phpmyadmin”. Although there are still a few adjustments to avoid error messages in the program. However, this does not matter for the time being, as we only use the program to keep track of created tables and data.

  • sudo apt install phpmyadmin

Step 6: Download, install and update Composer

Composer is a package manager for PHP applications. First, download the Composer Installer. After that, install Composer. Finally, check the version. Then remove the installation file. In the last step, you request the update of Composer.

  • sudo wget -O composer-setup.php https://getcomposer.org/installer

  • sudo php composer-setup.php –install-dir=/usr/local/bin –filename=composer

  • composer –version

  • sudo rm -rf composer-setup.php

  • sudo composer self-update

Step 7: Add missing packages

After installing Composer, add necessary packages. These are among others phpunit and php-xml.

  • sudo apt-get install phpunit

  • sudo apt install php-xml

Step 8: Create a project with Laravel on Raspberry Pi

Now create your first Laravel project. To do this, use Composer. Use the cd command to change to the project folder.

  • composer create-project laravel/laravel YOURPROJECTNAME

  • cd YOURPROJECTNAME

Step 9: Test the executability of your PHP framework Laravel

After that, test if Laravel works on Raspberry Pi. You should be in the console and in the project folder.

  • php artisan serve

Open a browser on the Raspberry Pi OS interface. Then open the address “localhost:8000”. Here appears the demo page of Laravel. If you see this, you have successfully installed the Laravel framework.

Leave a Reply

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