Introduction
If you manage a CloudLinux + LiteSpeed + WHM/cPanel hosting server, you’ve probably faced the struggle of getting Composer (the PHP dependency manager) to work globally for every cPanel user.
On a normal Linux server, installing Composer is easy — but with CloudLinux’s CageFS isolation, users often see:
-bash: composer: command not found
In this post, we’ll walk through how PrenHost fixed this and made Composer available for all clients — safely, globally, and cleanly.
Step 1 – Install Composer Globally for root
First, SSH into your WHM server as root and run:
cd /usr/local/bin
curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
Now confirm installation:
composer --version
Expected output:
Composer version 2.x.x
Step 2 – Fix allow_url_fopen Error
During installation you may see:
The allow_url_fopen setting is incorrect.
Fix it by editing /opt/cpanel/ea-php81/root/etc/php.ini
(Adjust version if you’re using a different PHP build):
allow_url_fopen = On
Then rerun the installer command — installation should complete successfully.
Step 3 – Expose Composer to CageFS Users
CloudLinux uses CageFS to isolate user environments, so global binaries must be explicitly added.
Run these commands:
mkdir -p /usr/share/cagefs-skeleton/usr/local/bin
ln -sf /usr/local/bin/composer /usr/share/cagefs-skeleton/usr/local/bin/composer
Then create a configuration file:
cat <<'EOF' > /etc/cagefs/conf.d/composer.cfg
[paths]
path=/usr/local/bin
EOF
Rebuild CageFS:
cagefsctl --force-update
cagefsctl --enable-all
Step 4 – Fix Common CloudLinux Errors
“File contains no section headers”
That means the /etc/cagefs/conf.d/composer.cfg
file was missing the [paths]
header.
Use the correct format shown above.
“Command not found” even after CageFS update
Some servers don’t expose /usr/local/bin
inside CageFS.
To fix it permanently, copy Composer to /bin
inside the skeleton:
mkdir -p /usr/share/cagefs-skeleton/bin
cp /usr/local/bin/composer /usr/share/cagefs-skeleton/bin/composer
chmod 755 /usr/share/cagefs-skeleton/bin/composer
cagefsctl --force-update
Step 5 – Verify from a cPanel User
SSH into any cPanel account (e.g. test
) and run:
composer --version
You should see:
Composer version 2.8.12 2025-09-19 13:41:59
PHP version 8.1.32 (/opt/alt/php81/usr/bin/php)
Success — Composer is now globally available for all users!
Bonus Tips from PrenHost
- Avoid “root warning” message:
echo 'COMPOSER_ALLOW_SUPERUSER=1' >> /root/.bashrc
- Increase PHP CLI memory limit (optional):
Edit/opt/alt/php81/etc/php.ini
:memory_limit = 512M max_execution_time = 300
- Rebuild CageFS after major updates:
cagefsctl --force-update
Final Thoughts
Setting up Composer globally on CloudLinux can be tricky due to CageFS isolation, but once configured correctly, it’s fully stable and safe for every user.
At PrenHost Ltd, we faced every possible error — from allow_url_fopen
issues to CageFS misconfigurations — and turned them into a clear, repeatable setup process.
Now, all cPanel users on our servers can run Composer effortlessly for Laravel, Symfony, WordPress CLI, and more — without manual installs.
Need Help?
PrenHost offers managed CloudLinux + LiteSpeed hosting with PHP Composer pre-enabled and optimized for developers. Visit www.prenhost.com to learn more.