How to Install PHP Composer on Rocky Linux 8 or Alma Linux 8
If you’re juggling a PHP project on one of those RHEL‑based distros and the only thing that’s missing is Composer, read on. This guide gets you up and running with the latest Composer version in under ten minutes—no “sudo” gymnastics required.
Installing Composer via the Official Installer
1. Download the installer
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
The installer validates its checksum automatically, so you avoid a rogue script that could hijack your system.
2. Give it executable permissions
chmod +x /usr/local/bin/composer
Without chmod, the binary won’t run at all—just a silent “permission denied” and you’ll be wondering why nothing happened.
3. Verify the install
composer --version
If you see something like Composer version 2.6.5 …, you’re good to go. If it says “command not found,” double‑check that /usr/local/bin is in your $PATH. On Rocky and Alma, it usually is, but a misconfigured shell can hide it.
Using DNF to Keep Composer Updated
Rocky 8 and Alma Linux 8 ship with the dnf package manager, which can keep Composer at the latest patch level:
1. Add the EPEL repository (if you haven’t already)
dnf install epel-release -y
EPEL contains a pre‑built Composer rpm that’s easier to upgrade via dnf update.
2. Install Composer from EPEL
dnf install composer -y
This pulls in the system‑wide Composer binary and automatically updates it whenever you run dnf update.
3. Pin or remove the rpm if you prefer the installer method
If you installed via the script earlier, the rpm version is redundant. You can either keep both (the script stays in /usr/local/bin) or delete the rpm with dnf erase composer to avoid confusion.
Common Pitfalls and How I’ve Seen Them Play Out
- Permission errors when running composer install – I once had a CI job that failed because the worker user didn’t have write access to the vendor directory. The fix was simply adding sudo chown -R $USER:$USER /path/to/project/vendor.
- Missing PHP extensions – Composer will complain if you’re missing common extensions like ctype or json. Run yum install php-{ctype,json} (or the equivalent packages for your PHP version) to satisfy those checks.
- Out‑of‑date PHP on Alma Linux 8 – Some users think the default PHP in the base repo is fine, but it’s often a couple of minor releases behind. For stability with Composer, install php80 or newer from Remi’s RPM repository.
Final Thoughts
Composer isn’t just another dependency manager; it’s the backbone of almost every modern PHP workflow. Once you have it installed, the rest of your stack will thank you—whether that’s Laravel, Symfony, or a handful of custom scripts.
Hope this gets Composer up and humming on your Rocky or Alma machine without any headaches.