How to install Laravel + Symfony! (BONUS)

Created March 27, 2022

1: Laravel

It is always the best practice to start any installation with the upgraded and updated system but it is necessary as Laravel does not work with PHP with a version lower than 7.2.

To update and upgrade your system, run the following command:

sudo apt update && apt upgrade -y

To install PHP on your system, run the following apt command:

sudo apt install php

Once you are done with the installation, check the installation version with the following command:

php -v

Now install the PHP extension with the same version with the following command:

sudo apt install php7.4-mbstring php7.4-xml php7.4-zip

Install Composer

You need the Composer to manage dependencies in Laravel.

To install composer, run the following command:

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Run the following command with your composer file path to run composer without sudo permission:

sudo chown -R $USER /usr/local/bin/composer/

Now that everything is set and running, install Laravel using the following composer command:

composer global require laravel/installer

Once the Laravel installation is done, open the .bashrc file:

nano .bashrc

Then add the following line of code at the end of the file:

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Press Ctrl+O and Ctrl+X to save and exit.

Next source the bashrc file:

source ~/.bashrc

Now you are done!


2: Symfony

Symfony can be installed via composer or from your installer which is the easiest and most feasible option.

So, open the terminal and upgrade Ubuntu 20.04:

sudo apt update
sudo apt upgrade

Symfony is a PHP framework, so it requires PHP to work. If you already have a LAMP or LEMP server you do not need this step:

sudo apt install php php-json php-ctype php-curl php-mbstring php-xml php-zip php-tokenizer php-tokenizer libpcre3 --no-install-recommends

After this, install GIT, unzip and zip for a successful installation:

sudo apt install git zip unzip

After that, download and install the symfony-cli tool:

wget https://get.symfony.com/cli/installer -O - | bash

After that, add the Symfony installation path to the PATH user.

export PATH="$HOME/.symfony/bin:$PATH"

And apply the changes by running

source ~/.bashrc

With this, we will be able to use the tool from any location of the prompt.

Now configure the email and user of your user in Git:

git config --global user.email "example@website.com"
git config --global user.name "HowToUbuntu"

Now you can create a new project by running it:

symfony new example --full

And now you can start working with your text editor like Visual Studio Code.

To start the local webserver you can run:

cd example
symfony server:start

Remember to replace example with the name of your project.

Now you can go to http://localhost:8000 and check your project.