How to Install a Laravel Development Environment

Create a Laravel Development Environment

Laravel provides not only a complete and developer-friendly framework for creating PHP web applications, it also provides a local server for configuring your app. In this article, you’ll learn how to create a complete Laravel development environment in your local server, which you can then upload to a live production environment.

In order to follow along with this tutorial, you will need to have some comfort with the Linux command line. For these examples, I’ll be using the apt package manager which comes bundled with Debian, Ubuntu, and some other Linux distributions.

If you are using a different Linux distribution or alternate package manager, you should check to see what default packages are available, what you have installed, and veer where possible with the examples provided. Managing local and production Laravel apps is an ideal task for a managed or unmanaged VPS accounts. Learn more about VPS vs dedicated server hosting.

Installing PHP For Your Laravel Development Environment

In order to start creating Laravel apps locally, you need to have access to PHP in the local server. (By local server, I mean your local computer. For the purposes of this tutorial, and other Laravel tutorials, it’s helpful to think of your local computer as a server.) With a running PHP installation, you can install and configure a virtually unlimited number of Laravel apps.

Not a Basic LAMP Stack

As you likely already know, PHP comes installed with a standard LAMP (Linux, Apache, MySQL, and PHP) stack. However, in order to run the necessary PHP scripts to run your Laravel development environment, you need PHP plus a few extra executable programs.

sudo apt install php7.4 php7.4-mysql php-common php7.4-cli php7.4-json php7.4-common php7.4-opcache libapache2-mod-php7.4 php7.4-mbstring php7.4-xml

Also, you will need to install the Composer package manager for PHP:

sudo apt install composer

Completing The Lamp Stack (Optional, But Recommended)

Optional, but recommended, you should complete the LAMP stack, especially if you want to create an app that uses a MySQL (or, in this case, MariaDB) database, or if you want to be able to administer those databases with phpMyAdmin.

Install Apache web server:

sudo apt install apache2

Check to see that apache2 is running:

sudo systemctl status apache2

Install MariaDB:

sudo apt install mariadb-server mariadb-client

Check to make sure that MariaDB is running:

sudo systemctl status mariadb

Create a New Laravel App

Make Sure You Have the Composer Path Added to Your Bash Profile

In order to properly run composer packages from the command line, like the Laravel installer, for example, you must make sure you have the path to the /composer/vendor/ directory available in your bash configuration. You can ensure this by placing this PATH= directive in your bash ~/.profile file:

if [ -d "$HOME/.config/composer/vendor/bin" ] ; then
    PATH="$HOME/.config/composer/vendor/bin:$PATH"
fi

Install the Laravel Installer and Create a Laravel App

Now that you have a path for Composer to install and run apps, go ahead and install the Laravel installer:

composer global require laravel/installer

Now you can carry out the complete installation of a new Laravel app:

laravel new <name-of-project-working-directory>

To make sure that all services are installed and running, cd (change directory) into your project working directory and run an update for Composer packages:

composer update

You should now see that your app working directory contains a /vendor directory, where Composer packages and modules will be installed. To see your app in a browser, you can initiate the local server with PHP artisan:

php artisan serve

Navigate to localhost:8000 and you can see your app served locally.

If you get an error about a security key, run this command:

php artisan key:generate

Reload your app with php artisan serve again, and you should now see a fresh Laravel splash page to indicate that the process was successful. Your Laravel app and local development environment are complete. Now you can begin developing your app.

 

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

Was this article helpful? Join the conversation!