Installing Drupal with Composer
With a Plesk site I can use SSH to navigate to the web folder where I want Drupal, or a module, to be installed and then use composer.phar with a command line like...
# /opt/plesk/php/8.3/bin/php /usr/lib64/plesk-9.0/composer.phar require 'drupal/[module name]'
How can I tell if composer is installed in my cPanel install? Please can you point me a some instructions to install composer. Can you help with the cPanel command string to run from the Drupal root. Thanks.
-
Hey there! We have a guide on how to install Composer in modern versions of cPanel here:
so you'll likely need to do that first in order to get things working.
There are additional details at https://docs.cpanel.net/knowledge-base/web-services/how-to-set-up-php-composer/ about setting up the tool. Let me know if that helps!
0 -
Thanks.
From the links you provided I've run the following...
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"php -r "copy('https://composer.github.io/installer.sig', 'composer.sig');"php -r "if (hash_file('sha384', 'composer-setup.php') === trim(file_get_contents('composer.sig'))) { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"The first two command strings run with no error. As the post says, one of the options to the last command is Installer Corrupt and that's the response I get.I found this post, https://github.com/composer/composer/issues/9659, which encounters the same error message.
The solution offered is to runphp -r "copy('https://getcomposer.org/composer-stable.phar', 'composer.phar');"and then verify with
php composer.phar diagnoseThe first command runs without error or any other message. The second gives an error "Cannot open composer.phar.
What am I doing wrong? Thanks.
0 -
In the local directory where you're running the commands, what does "ls -lah composer.phar" show?
0 -
Thanks. I'm running from a sub-folder under public_html. When I run your command I see...
ls: cannot access 'composer.phar': No such file or directory
0 -
Thanks for that - that would indicate the previous "php -r" command never properly copied the file. Can you try running that one again and see if that gives any errors?
0 -
php -r "copy('https://composer.github.io/installer.sig', 'composer.sig');"... run from a sub-directory off public_html gives no error, simply redisplaying the command prompt. Re-running ls -lah composer.phar unfortunately gives the same error.
0 -
I'm not sure what would be leading to that, so it might be best to create a ticket so your specific machine can be checked.
0 -
How do I do that? What does that cost?
0 -
Support is always free, but who you would contact depends on where you license was purchased.
If you go to WHM >> Create a Support Ticket it should tell you right on that screen who you can contact.
0 -
Thanks. Will do.
0 -
You’re close — “Installer corrupt” usually means the downloaded
composer-setup.phpdidn’t match the expected hash (often because PHP couldn’t fetch over HTTPS or a proxy/CDN returned HTML instead of the installer).Quick fix (works on cPanel shells):
-
Use
curlto fetch the installer and the expected hash
cd /home/USER/public_html/path/to/drupal curl -sS https://getcomposer.org/installer -o composer-setup.php curl -sS https://composer.github.io/installer.sig -o composer.sig-
Verify the installer
php -r "if (hash_file('sha384','composer-setup.php')===trim(file_get_contents('composer.sig'))) { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"-
Install Composer locally in the project
php composer-setup.php --install-dir=. --filename=composer.phar php -d detect_unicode=0 composer.phar --version # sanity check-
Run your Composer command from the Drupal root
php composer.phar require 'drupal/MODULE_NAME'If
composer.pharstill doesn’t appear:-
Your CLI PHP may not be allowed to fetch HTTPS. Check:
php -r "echo 'allow_url_fopen='.(int)ini_get('allow_url_fopen').PHP_EOL; echo 'openssl='.(int)extension_loaded('openssl').PHP_EOL;"-
If
allow_url_fopen=0oropenssl=0, thephp -r "copy(...)"method won’t work — stick withcurl/wgetas above. -
Also ensure the download followed redirects:
curl -L -o composer.phar https://getcomposer.org/composer-stable.phar ls -lah composer.phar php composer.phar diagnoseTip (cPanel specifics):
-
Use the same PHP binary your site uses, e.g.
/opt/cpanel/ea-php82/root/usr/bin/php:
/opt/cpanel/ea-php82/root/usr/bin/php composer.phar --versionThat should get Composer installed and let you require Drupal modules from the project root. If anything still errors, post the output of:
php -v which php ls -lah composer* head -n1 composer-setup.phpand we can spot what’s blocking the download.
0 -
-
You can install easily and in minutes using Softaculous
0 -
Thanks so much for this.
I believe I have Composer correctly installed by running composer diagnose Here is the output
[root@127518 /]# composer diagnose
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Checking platform settings: OK
Checking git settings: OK git version 2.48.2
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0 87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B 0C708369 153E328C AD90147D AFE50952
OK
Checking Composer version: OK
Checking Composer and its dependencies for vulnerabilities: OK
Composer version: 2.8.11
PHP version: 8.3.21
PHP binary path: /opt/cpanel/ea-php83/root/usr/bin/php
OpenSSL version: OpenSSL 3.0.7 1 Nov 2022
curl version: 7.76.1 libz 1.2.11 brotli 1.0.9 zstd missing ssl OpenSSL/3.2.2
zip: extension present, unzip present, 7-Zip not availableHowever when I run the command you specify in Drupal root (public_html/d112) I get an error
[root@127518 d112]# php composer.phar require 'drupal/eca:^3.0'
Could not open input file: composer.phar
[root@127518 d112]#When I run the command you specify to pick up any errors, all seems good...
[root@127518 d112]# php -v which php ls -lah composer* head -n1 composer-setup.php
PHP 8.3.21 (cli) (built: May 8 2025 00:00:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.21, Copyright (c) Zend Technologies
with Zend OPcache v8.3.21, Copyright (c), by Zend Technologies
[root@127518 d112]#As Composer seems now to be correctly installed and the last command reveals no errors, I suspect I'm doing something silly which is stopping the module install. Perhaps you can spot what. Thanks again for your continued help on this.
0 -
You’re almost there. The error
Could not open input file: composer.pharjust means there is no
composer.pharin the current directory. You have two valid ways to run Composer:Option A — Use the global Composer you already have
Since
composer diagnoseworked, you likely have Composer installed globally (e.g./usr/local/bin/composer). So, from the Drupal project root:cd /home/USER/public_html/d112 composer --version composer require drupal/eca:^3.0Tip: run Composer as the cPanel user, not root, to avoid root-owned files:
su - USER cd ~/public_html/d112 composer require drupal/eca:^3.0If you hit memory issues:
COMPOSER_MEMORY_LIMIT=-1 composer require drupal/eca:^3.0Option B — Use a local
composer.pharin the projectIf you prefer the
.pharin that directory:cd /home/USER/public_html/d112
curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php --install-dir=. --filename=composer.phar
php composer.phar --version
php composer.phar require drupal/eca:^3.0Double-check the basics
Run each command separately (earlier you pasted multiple commands on one line, so only
php -vactually ran).pwd
ls -lah composer* # do you see composer.phar here?
command -v composer # path to global composer, if any
[ -f composer.json ] || echo "Not a Composer project here"After installing the module
Enable it via UI (Extend → Install), or with Drush if present:
php vendor/bin/drush en eca -y
php vendor/bin/drush crIf anything still misbehaves, paste the output of:
pwd
ls -lah composer*
command -v composer
whoami
stat -c '%U:%G' composer.jsonand we’ll pinpoint the last missing step.
0 -
Apparently find / -name "composer.phar" 2>/dev/null should scan the server and find the location of composer.phar. Running it returns command prompt with no location which I suppose means that it isn't installled. Stranger, since composer diagnose appears to say all is well. I hope this helps to find what I'm doing wrong.
0 -
Hello we have updated the commands, please try again and post output please
0 -
Thank you for taking so much trouble over this. Here is the output for the various commands you have supplied...
[root@127518 d112]# composer --version composer require drupal/eca:^3.0
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Composer version 2.8.11 2025-08-21 11:29:39
PHP version 8.3.21 (/opt/cpanel/ea-php83/root/usr/bin/php)
Run the "diagnose" command to get more detailed diagnostics output.
[root@127518 d112]# curl -sS https://getcomposer.org/installer -o composer-setup.php
[root@127518 d112]# php composer-setup.php --install-dir=. --filename=composer.phar
All settings correct for using Composer
Downloading...Composer (version 2.8.11) successfully installed to: /home/moorlandtoday/public_html/d112/composer.phar
Use it: php ./composer.phar[root@127518 d112]# php composer.phar --version
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Composer version 2.8.11 2025-08-21 11:29:39
PHP version 8.3.21 (/opt/cpanel/ea-php83/root/usr/bin/php)
Run the "diagnose" command to get more detailed diagnostics output.
[root@127518 d112]# php composer.phar require drupal/eca:^3.0
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
The "composer/installers" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
The "drupal/core-composer-scaffold" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
The "drupal/core-project-message" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
The "drupal/core-recipe-unpack" plugin was not loaded as it is not listed in allow-plugins and is not required by the rootpackage anymore.
The "drupal/core-vendor-hardening" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
./composer.json has been created
The "composer/installers" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
The "drupal/core-composer-scaffold" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
The "drupal/core-project-message" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
The "drupal/core-recipe-unpack" plugin was not loaded as it is not listed in allow-plugins and is not required by the rootpackage anymore.
The "drupal/core-vendor-hardening" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.
Running composer update drupal/eca
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.Problem 1
- Root composer.json requires drupal/eca, it could not be found in any version, there may be a typo in the package name.Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
- It's a private package and you forgot to add a custom repository to find itRead <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Installation failed, deleting ./composer.json.
[root@127518 d112]# ls -lah composer*
-rwxr-xr-x 1 root root 3.0M Aug 30 14:59 composer.phar
-rw-r--r-- 1 root root 58K Aug 30 14:59 composer-setup.php
[root@127518 d112]# command -v composer
/usr/local/bin/composer
[root@127518 d112]# [ -f composer.json ] || echo "Not a Composer project here"
Not a Composer project here
[root@127518 d112]#0 -
Here is the output for the commands you requested under "if anything goes wrong". The problem seems to be in the last command - missing composer.json.
How do I fix that?
[root@127518 d112]# ls -lah composer*
-rwxr-xr-x 1 root root 3.0M Aug 30 14:59 composer.phar
-rw-r--r-- 1 root root 58K Aug 30 14:59 composer-setup.php
[root@127518 d112]# command -v composer
/usr/local/bin/composer
[root@127518 d112]# [ -f composer.json ] || echo "Not a Composer project here"
Not a Composer project here
[root@127518 d112]# pwd
/home/moorlandtoday/public_html/d112
[root@127518 d112]# ls -lah composer*
-rwxr-xr-x 1 root root 3.0M Aug 30 14:59 composer.phar
-rw-r--r-- 1 root root 58K Aug 30 14:59 composer-setup.php
[root@127518 d112]# command -v composer
/usr/local/bin/composer
[root@127518 d112]# whoami
root
[root@127518 d112]# stat -c '%U:%G' composer.json
stat: cannot statx 'composer.json': No such file or directory
[root@127518 d112]#0 -
You did all the right checks — the remaining issue is simply path & project type.
This line says it all:
Not a Composer project here
You’re inside /home/moorlandtoday/public_html/d112, but there is no composer.json there. That means you’re not in a Composer-managed Drupal project, so composer require drupal/eca can’t work (and it also can’t find drupal/eca because the Drupal packages repo isn’t configured unless a proper Drupal composer.json is present).You have two clean ways forward — pick ONE:
Option A — Use a proper Composer-based Drupal (recommended)
If this is a new site or you can redeploy:
# As the cPanel user (not root)
su - moorlandtoday# Create a Composer-based Drupal project
composer create-project drupal/recommended-project:10.x ~/d112# The web root becomes: ~/d112/web
# In cPanel, point the domain/subdomain DocRoot to /home/moorlandtoday/d112/web
# (or install in a subdir and access that path)
cd ~/d112
composer require drupal/eca:^3.0# Then install/enable ECA (UI or Drush if you use it)
Why this works: drupal/recommended-project includes a correct composer.json with the Drupal repository (packages.drupal.org), so composer require drupal/eca resolves immediately.Tip: avoid running Composer as root. Stay as the cPanel user to keep file ownership sane.
Option B — Keep your current install, but manage modules without Composer
If your current /public_html/d112 was created from a zip/Softaculous (no Composer), install modules the “classic” way (download the module release and place it under sites/default/modules/contrib, then enable it).
BUT many modern modules (including ECA) expect Composer because they pull PHP library dependencies. If you need those dependencies, Option A is the safer long-term path.Quick sanity checks you can run now
# Where is composer.json?
find /home/moorlandtoday -maxdepth 3 -name composer.json# If you chose Option A, you should see it under /home/moorlandtoday/d112/composer.json
# and your web root should be /home/moorlandtoday/d112/web
If you’d like to convert the existing site to Composer instead of redeploying, the safest workflow is:Create a new ~/d112 with drupal/recommended-project (as above).
Copy sites/default/files and settings.php (plus salts/DB creds) into ~/d112/web/sites/default/.
Import your DB, point the domain to ~/d112/web, and test.
Post back the output of:
ls -lah /home/moorlandtoday/public_html/d112
ls -lah /home/moorlandtoday/d112 | head
and we can confirm which path is best in your case.0 -
Thank you for your extensive response and explanation which showed me I didn't really understand the ways Composer works with Drupal. I see now your Option A is the way to go in future and I'll create a new Drupal project following this Option. I'll post again, hopefully to confirm success!
0 -
I have followed your instructions with a clean domain, tmqp.org
su - tmqp
# Create a Composer-based Drupal project
composer create-project drupal/recommended-project:11.x ~/d112fThe job ran without error.
When in inspect what is created, this is what I see
[root@127518 ~]# cd /
[root@127518 /]# dir
afs boot etc lib64 mnt proc run srv usr
backup dev home license-cpanel.cgi notify-cpanel-done.cgi requirements.txt sbin sys var
bin error_log lib media opt root scripts tmp
[root@127518 /]# cd home
[root@127518 home]# dir
0_README_BEFORE_DELETING_VIRTFS endhills marionkayecom moorlandtoday ransomedhealed thecornishvicars virtfs
cPanelInstall lesleykaye moorlandteam peterand tcvd tmqp
[root@127518 home]# cd tmqp
[root@127518 tmqp]# dir
access-logs ~d112f etc logs mail perl5 public_ftp public_html ssl tmp www
[root@127518 tmqp]# cd ~d112f
[root@127518 ~d112f]# dir
composer.json composer.lock recipes vendor web
[root@127518 ~d112f]# cd web
[root@127518 web]# dir
autoload.php example.gitignore INSTALL.txt profiles robots.txt themes
core index.php modules README.md sites update.phpSo /home/tmqp/~d112f/web has the sort of files I'd expect e.g. sites, modules. Interesting vendors is up one level. Core has install.php which I need to run to install the site. Things are looking good!
(But none of these files are under public_html which is where they would be if I installed drupal manually.)
Where I'm struggling is with the instruction "In cPanel, point the domain/subdomain DocRoot to home/tmqp/~d112f/web."
In the cPanel UI domain/tools I see the home directory for timqp as /home/tmqp . I guess this must be changed to home/tmqp/~d112f/web if I'm to install the Drupal files I've created. But where in cPanel do I edit the home directory?
And does this means that the public url to access the site is tmqp.org/~d112f? And, if I want to install drupal in the domain root, would I run the composer install as composer create-project drupal/recommended-project:11.x ?
I sense, with your help, I'm nearly there on this. Apologies if these last questions are a bit simplistic! Thanks again for continuing to help with this.
0 -
Interestingly in cPanel UI, I see the folder ~d112f above public_html.
If I copy the folder to below public_html and then run the url tmqp.org/~d112f/web, I get the Drupal install page. And before doing the copy, in the ~d112f folder, if I run composer require drupal/eca:^3.0, the installed version of Drupal contains the Eca module! But surely this can't be the right way to do things!
0 -
Out of interest, I tried running the module install code inside the folder that I copied under public_html. And it works! Which means that a site built by a Composer install and then moved to a folder inside public_html, either domain root or a sub-domain, can have additional modules installed with composer - composer require 'drupal/[module name and version]' Just what I wanted.
0
Please sign in to leave a comment.
Comments
23 comments