Preparing your Debian Environment

Prepare your debian environment for working with Laravel

Preparing your Environment

Debian Based Systems

Before digging into working with Laravel, you will need to get your computer environment ready. This guide will walk you through that process.

This specific tutorial targets a Debian Linux based operating system, such as Debian, Ubuntu, or Mint. Alternative OS guides, for Windows or Mac, will be added at a later date.

In this guide, you will:

  • Install PHP Runtime
  • Install Composer, the PHP Package Manager
  • Install Docker, a virtualization environment
  • Remove apache
  • Acquire the Laravel Installer tool
  • Make Composer binaries globally available

You will need to perform most of these steps as root. Before beginning, open a new terminal window and switch users to root.

su -

example su response

Install PHP Runtime

PHP is the programming language used by Laravel. Before we can dig in, we need a working PHP runtime environment.

On Debian based systems, Installing php is as easy as a single apt command. You will need the base php package, as well as the mbstring and xml extensions.

apt-get install php php-mbstring php-xml 

install php

Install Composer, the PHP Package Manager

Next, you will need to install Composer.

Composer is a package manager for PHP which makes it easy to find and work with third party packages and tools, such as the Laravel framework.

While Composer is available via apt, I recommend installing it directly from the Composer website to get the most recent version. Composer has a self-update tool built in which makes keeping it up to date easy, and the benefits of the package manager aren’t useful in this case.

php -r "copy('', 'composer-setup.php');"
php composer-setup.php
rm composer-setup.php
mv composer.phar /usr/local/bin/composer

install composer

Install Docker, a virtualization environment

Docker is a virtualization solution which makes it easier for you to experiment with and develop web applications in your local environment without the need to install, configure, and maintain complex web server software.

You can install Docker using Docker’s official linux installation script located at

wget -qO- | sh
apt-get install docker-compose
systemctl start docker

install docker

The Docker script above will have created a docker group, which allows non-root accounts the ability to execute docker commands. It’s time to add your user to that group.

Be sure to replace 'james' with the username of your account.

usermod -aG docker james


Remove apache

Perhaps it's the result of an overlooked option during installation, but I've found that apache is often installed after a fresh installation of Debian.

If the apache web server is installed and running, it will conflict with Docker when you try to start a new project a few steps from now.

It is a good idea to resolve the problem right now, if it exists in your case.

service apache2 stop
apt-get purge apache2 apache2-utils
apt-get autoremove

If apache is installed and running, this will stop and remove it from the system.

If apache is not installed, this will simply state that there is nothing to do.

Either way, we are now clear to move forward!

remove apache steps

This completes the steps you need to run as root. Exit out of the root shell, and back your user account.


The usermod command from a few steps ago will not take effect until your shell is reinitialized, so let's do that now.

Once again, Be sure to replace 'james' with the username of your account.

su - james

reload environment

Acquire the Laravel Installer tool

There are a number of different ways to kick off a new installation of Laravel. The method I recommend is to acquire and use the Laravel installer.

The laravel installer is a small program which can handle creating a new laravel application for you. It is created and maintained by the makers of Laravel.

Installation is a matter of a simple composer command, which you should be able to run from anywhere on your system.

composer global require laravel/installer

install laravel installer

Make Composer binaries globally available

Composer maintains a folder of executable programs. Installing the Laravel Installer adds one, called simply 'laravel'.

Before you can easily use it, you need to tell linux about Composer’s folder of executable programs. To do this, you need to add the path to the directory to a system variable called PATH. This variable is intended for this very purpose - to give your system a list of places to look for any executable programs you try to use.

To easily add the directory to the PATH variable, add a new line to the bottom of the .bashrc file.

echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc

make composer binaries globally available

This new line will automatically be read and processed when you open a new terminal window in the future.

Since you already have a working terminal open, in this one instance, you will need to tell your terminal to reprocess the configuration file to find the new change:

source ~/.bashrc

That should do it, and you should now be able to execute any of composer’s commands from anywhere in your system.

Give it a try! Running the Laravel installer without any commands will give you some simple help information.



That's it!

You are ready to move on to the next tutorial, Starting a new Laravel Project!