Update the system packages to the latest versions:
sudo apt-add-repository ppa:ondrej/php
sudo apt update && sudo apt upgrade
Run the following command to install PHP and all required PHP modules:
sudo apt install php7.2-common php7.2-cli
sudo apt install php7.2-gd php7.2-mysql
sudo apt install php7.2-intl php7.2-mbstring
sudo apt install php7.2-bcmath php7.2-imap
sudo apt install php7.2-xml php7.2-zip
sudo apt install php7.2-curl
or just one command
sudo apt install php7.2-common php7.2-cli php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-mbstring php7.2-bcmath php7.2-imap php7.2-xml php7.2-zip
Composer is a dependency manager for PHP and we will be using it to download the Laravel core and install all necessary Laravel components.
To install composer globally, download the Composer installer and install it by following command.
sudo apt install curl
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Verify the installation by printing the composer version:
composer --version
The output should look something like this:
Composer version 1.8.0....
Run the Composer create-project command to install Laravel in the my_app directory:
composer create-project --prefer-dist laravel/laravel my_app
The process may take few minutes and if it is successful the end of the output should look like the following:
Package manifest generated successfully.
> @php artisan key:generate --ansi
Application key set successfully.
Now you can start the development server by navigating to the Laravel project directory and executing the artisan serve command:
cd my_app
php artisan serve
The output will look something like this:
Laravel development server started: <http://127.0.0.1:8000>
Open your browser, type http://127.0.0.1:8000
Congratulations, you have successfully installed Laravel on your Linux machine. You can now start developing your application.. .