First, add the apt repository by running this command:
sudo add-apt-repository ppa:ondrej/php
This adds the ppa:ondrej/php repository, which contains various PHP versions and related packages, to the list of sources that APT can use to install packages.
After adding the repository, update the package list with this command:
sudo apt update
The apt update command updates the package list from the repositories specified in the sources.list file and the added PPAs (Personal Package Archives). This is necessary to make sure that you have access to the latest versions of packages available in the repository.
To check if the repository was added correctly and the package can be found, use this command:
sudo apt-cache search php8.1-curl
The apt-cache search command is used to search the package cache for a package with a specific name. In this case, you are searching for the package php8.1-curl, which is the CURL module for PHP 8.1.
This should return:
php8.1-curl - CURL module for PHP
Now that you've added the repository and updated the package list, you can install the desired PHP package with this command:
sudo apt install php8.1-cgi php8.1-cli php8.1-xml php8.1-curl
In addition to PHP, you'll also need to install the composer package to install Laravel. Do so with this command:
sudo apt install composer
The "apt install" command installs one or more packages. In this case, you are installing four PHP packages: php8.1-cgi, php8.1-cli, php8.1-xml, php8.1-curl and composer.
After installing composer, you can create a new Laravel project in the current directory with this command:
composer create-project laravel/laravel myProject
The composer create-project command creates a new Laravel project in the current directory, using the latest stable release of Laravel. You can specify the name of the project directory (in this case, myProject) as an argument.
Then navigate to the project directory with:cd myProjectFinally, start the Laravel development server with:
php artisan serve
Finally, the php artisan serve command starts a development server at http://127.0.0.1:8000, which you can use to test your Laravel application.
This should start the server and print:
INFO Server running on [http://127.0.0.1:8000]