This tutorial will guide you step by step on how to install PHP 8.3, 8.2, 8.1 with composer on CentOS 9|8.
How to Install PHP 8.3, 8.2, 8.1 on CentOS 9|8
Here are few steps to follow and install PHP 8.3, 8.2, 8.1 with composer on centOS 8|9:
- Step 1 – Update CentOS System
- Step 2 – Install the PHP 8.3, 8.2, 8.1
- Step 3 – Download Composer with curl
- Step 4 – Move Composer file
- Step 5 – Getting Started with Composer
Step 1 – Update CentOS System
Centos system packages are always up to date updated before updating the system. Run the command to update the Cent OS system packages:
sudo yum update sudo yum upgrade
Step 2 – Install the PHP 8.3, 8.2, 8.1
Run the following command to install PHP on centOS:
sudo dnf install php php-cli -y
To install php common extensions:
sudo dnf install php-cli php-fpm php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache
Step 2 – Download Composer with curl
Using the curl, you can download composer. Here is the command:
curl -sS https://getcomposer.org/installer |php
Step 4 – Move Composer file
Now, you need to move the composer file on centOS 8:
sudo mv composer.phar /usr/local/bin/composer
Step 5 – Getting Started with Composer
Create PHP project using the composer command:
mkdir ~/my-first-composer-project cd ~/my-first-composer-project
A project is being made to show the current times. We need to install the datetime package. Which will happen by command.
composer require nesbot/carbon
Then create a file named testing.php
and add the following code:
<?php require __DIR__ . '/vendor/autoload.php'; use Carbon\Carbon; printf("Now: %s", Carbon::now());
Finally, execute the following command n command line or terminal to test above created PHP project with the help of PHP composer:
php testing.php
The output should look something like this:
Now: 2023-12-25 22:12:26
Conclusion
Through this tutorial, we have learned how to install and use PHP 8.3, 8.2, 8.1 with composer on CentOS 9|8 machine. And also how to use Composer to create a basic PHP project.