PHP
PHP is a popular general-purpose scripting language that is especially suited to web development.
Requirements
- For Debian, use Sury PHP.
- For Ubuntu, use Ondřej Surý.
sudo apt update -y
sudo apt -y install lsb-release ca-certificates curl
sudo curl -sSL -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update -ysudo add-apt-repository ppa:ondrej/php
sudo apt update -yInstall PHP
Here, PHP 8.2 is used as an example. You can replace it with the version you want.
INFO
This guide uses fpm as the PHP handler to use with NGINX.
sudo apt -y install php8.2-fpmInstall extensions
Here are some common PHP extensions:
sudo apt install -y php8.2-mbstring \
php8.2-mysql \
php8.2-common \
php8.2-cli \
php8.2-dev \
php8.2-xml \
php8.2-curl \
php8.2-gd \
php8.2-imagick \
php8.2-imap \
php8.2-opcache \
php8.2-soap \
php8.2-zip \
php8.2-bz2 \
php8.2-intlFix PHP-FPM owner
If you use NGINX, you need to change the PHP-FPM owner to nginx. You have to change the owner in the PHP-FPM configuration file for each PHP version you have installed.
sudo sed -i 's/www-data/nginx/' /etc/php/8.2/fpm/pool.d/www.conf
sudo sed -i 's/www-data/nginx/' /var/run/php/php8.2-fpm.sockRestart PHP-FPM:
sudo systemctl restart php8.2-fpmComposer
Use command line instructions of Composer website to download and install latest version of Composer

php -r "copy('https://getcomposer.org/installer', '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/Global package
To install global package like laravel
INFO
This is an example, you can replace laravel with any package you want.
composer global require laravel/installerAdd this to .zshrc
vim ~/.zshrcexport PATH=~/.config/composer/vendor/bin:$PATHsource ~/.zshrcNow you can use composer.
Switch PHP
To switch PHP versions, use the following command:
sudo update-alternatives --config phpUsage
Specific PHP version
If you installed multiple PHP versions, you can use a specific version by specifying the version number.
php8.2 -vPHP version
To see the current PHP version, run the following command:
php -vYou can change current version with Switch PHP
PHP modules
php -mSpecific module
php -m | grep <module>Example:
php -m | grep curlIf you see curl in the output, it means the curl module is installed.