, ,

How to Use XAMPP’s PHP and Composer on Linux

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

XAMPP is a popular all-in-one package that ships with Apache, MySQL, PHP, and other tools. On Linux, XAMPP installs its own copy of PHP inside /opt/lampp/bin/. If you want to develop PHP projects using this bundled version instead of your system’s PHP, you also need Composer (the PHP dependency manager) configured to use the same binary.

This guide explains how to set up your environment so both PHP and Composer point to XAMPP, step by step.


1. Locate XAMPP PHP

After installing XAMPP, PHP is available in:

/opt/lampp/bin/php

You can test it directly:

/opt/lampp/bin/php -v

This will show the PHP version bundled with XAMPP.


2. Update Your PATH

By default, your shell still points to the system PHP. To override it, edit your shell configuration file:

nano ~/.bashrc

(or ~/.zshrc if you use zsh). Add this line at the end:

export PATH=/opt/lampp/bin:$PATH

Save the file and reload:

source ~/.bashrc

Now check:

which php
php -v

It should show /opt/lampp/bin/php.


3. Install Composer with XAMPP PHP

XAMPP does not ship Composer by default. To install Composer globally but force it to use XAMPP’s PHP:

cd ~
/opt/lampp/bin/php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
/opt/lampp/bin/php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php

This downloads Composer using XAMPP’s PHP and places it in /usr/local/bin/composer, making it available system-wide.


4. Verify Installation

Run the following to confirm everything is working:

which php
php -v

which composer
composer -V

Expected results:

  • php should point to /opt/lampp/bin/php
  • composer should show the installed version and run on the same PHP

5. Optional: Wrapper Inside XAMPP

If you prefer keeping everything inside the XAMPP folder, you can create a small wrapper script:

sudo nano /opt/lampp/bin/composer

Paste:

#!/bin/bash
/opt/lampp/bin/php /usr/local/bin/composer "$@"

Save, then make it executable:

sudo chmod +x /opt/lampp/bin/composer

Now you can also call Composer directly from /opt/lampp/bin/composer.


6. Summary

  • XAMPP’s PHP lives in /opt/lampp/bin/php.
  • Adjust your PATH so the shell uses this version.
  • Install Composer globally using XAMPP’s PHP binary.
  • Optionally, add a wrapper script inside /opt/lampp/bin/ for convenience.

With this setup, both PHP and Composer will consistently use the same XAMPP environment, avoiding mismatches between system PHP and your development stack

Leave a Reply

Your email address will not be published. Required fields are marked *

0
Would love your thoughts, please comment.x
()
x