To get latest versions of PHP

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl
sudo curl -sSLo /usr/share/keyrings/
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/] $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt-get update

Install latest PHP version.

sudo apt -y install php8.2-fpm

Add PHP extension

sudo apt install -y php8.2-mbstring php8.2-mysql php8.2-common php8.2-mysql php8.2-xml php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl php8.2-bz2

Switch PHP

sudo update-alternatives --config php


Use command line instructions of Composer website to download and install latest version of Composer


php -r "copy('', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"

You have just to copy installation instructions and composer will be download, this is an example:

sudo mv composer.phar /usr/local/bin/composer
sudo chown -R $USER ~/.config/composer/

To install global package like laravel

composer global require laravel/installer

Add this to .zshrc

vim ~/.zshrc
export PATH=~/.config/composer/vendor/bin:$PATH
source ~/.zshrc

Now you can use composer.

Table of Contents