Nahidul Islam
php composer ubuntu

Setting Up PHP and Composer on Ubuntu Server

PHP is a popular scripting language used for web development, and Composer is a dependency manager for PHP. In this guide, we’ll go through the steps to install PHP 8.2 and Composer on an Ubuntu server.

Step 1: Add PHP Repository

Begin by adding the Ondrej PHP repository, which provides the latest PHP versions:

sudo add-apt-repository -y ppa:ondrej/php
sudo apt update

Step 2: Install PHP 8.2 and Required Extensions

Install PHP 8.2 along with various extensions commonly used in web development:

sudo apt install php8.2-{fpm,gd,mbstring,mysql,pgsql,xml,xmlrpc,opcache,cli,zip,soap,intl,bcmath,curl,imagick,common,imap,readline}
sudo systemctl status php8.2-fpm

Step 3: Install Composer

Move to the home directory and download Composer:

cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

Run the Composer installation script:

php composer-setup.php

Clean up the installation files:

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

Move Composer to the bin directory to make it globally accessible:

sudo mv composer.phar /usr/local/bin/composer

Conclusion

You’ve successfully installed PHP 8.2 and Composer on your Ubuntu server. PHP is now equipped with various extensions, and Composer is ready to manage your PHP project dependencies. This setup provides a solid foundation for developing and deploying PHP applications.

Open chat
1
Send me a Message
Hello, How can i help you?