Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

Step-by-Step Guide to Fix PHP 8.2 & Missing Extensions Error

Uncategorized

Below is a Complete Guide to fix your PHP 8.2 missing error (Unable to locate package) and properly install PHP 8.2, required extensions, and Composer for your Laravel project on Ubuntu/Linux Server. This will also help you avoid the “mbstring extension is missing” error in Composer.


Error:

root@ip-111-20-60-60:/opt/lampp/htdocs# sudo apt install php8.2-cli php8.2-mbstring php8.2-xml
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package php8.2-cli
E: Couldn't find any package by glob 'php8.2-cli'
E: Unable to locate package php8.2-mbstring
E: Couldn't find any package by glob 'php8.2-mbstring'
E: Unable to locate package php8.2-xml
E: Couldn't find any package by glob 'php8.2-xml'

✅ Step-by-Step Guide to Fix PHP 8.2 & Missing Extensions Error


⚠️ Why This Error Happens

Ubuntu’s default package repositories often do not include PHP 8.2, especially on older versions of Ubuntu (20.04, 22.04). To get PHP 8.2, you need to add a special PHP PPA (Personal Package Archive) maintained by Ondřej Surý, a trusted PHP package maintainer.


📖 Step 1 – Add the PHP PPA (Trusted Source)

Run the following commands to add the PPA that contains PHP 8.2 packages.

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

📖 Step 2 – Install PHP 8.2 and Required Extensions

Once the PPA is added, you can install PHP 8.2 and all the necessary extensions.

sudo apt install php8.2-cli php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip unzip curl

Explanation

  • php8.2-cli – Command Line PHP (for running php commands)
  • php8.2-mbstring – Required by Laravel and Composer
  • php8.2-xml – Required for parsing XML files
  • php8.2-curl – Required for downloading packages
  • php8.2-zip – Required for extracting Laravel packages
  • unzip – Needed for Composer
  • curl – Needed to download Composer

📖 Step 3 – Verify PHP Installation

To confirm PHP 8.2 is installed, run:

php -v

You should see output like:

PHP 8.2.x (cli) (built: ...)

📖 Step 4 – Install Composer (Globally)

Download and install Composer (works with system PHP 8.2).

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

Verify Composer is working:

composer --version

You should see:

Composer version 2.x.x

📖 Step 5 – Use System PHP for Composer in Your Laravel Project

If your project is inside /opt/lampp/htdocs (XAMPP directory), you need to tell Composer to use system PHP (not XAMPP’s PHP).

To install Laravel dependencies:

cd /opt/lampp/htdocs/your-laravel-project
/usr/bin/php /usr/local/bin/composer install

This ensures system PHP 8.2 (with all extensions) is used instead of XAMPP’s PHP.


📖 Step 6 (Optional) – Make System PHP Default (If You Want)

If you want to make system PHP 8.2 the default PHP everywhere, you can change the $PATH in your user profile.

Edit your .bashrc file:

nano ~/.bashrc

Add this at the end:

export PATH=/usr/bin:$PATH

Save and reload:

source ~/.bashrc

This will ensure running php always uses system PHP 8.2, not XAMPP PHP.


🔔 Why This is Recommended

  • System PHP is better for CLI work (Composer, Artisan commands).
  • XAMPP PHP is often missing important extensions like mbstring, iconv, etc.
  • System PHP gets regular security updates via apt update.

Complete Command Summary

# 1. Update system and add PHP PPA
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

# 2. Install PHP 8.2 and required extensions
sudo apt install php8.2-cli php8.2-mbstring php8.2-xml php8.2-curl php8.2-zip unzip curl

# 3. Verify PHP
php -v

# 4. Install Composer globally
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer

# 5. Check Composer
composer --version

# 6. Run Composer in Laravel project using system PHP
cd /opt/lampp/htdocs/your-laravel-project
/usr/bin/php /usr/local/bin/composer install

🚀 You’re Ready to Use Laravel!

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x