Install Composer under client/user (not admin) in DirectAdmin

Setting up Composer to work properly
within a non-root DirectAdmin user account
on shared hosting.

This requires some specific configuration
since you won't have system-wide installation privileges.

 

INSTALL COMPOSER LOCALLY IN YOUR USER ACCOUNT

Download Composer into your home directory:
bash
cd ~
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=$HOME/bin --filename=composer
rm composer-setup.php
This installs Composer as ~/bin/composer instead of requiring system-wide installation.

Make it executable and add to your PATH:
bash
chmod +x ~/bin/composer

Then add this line to your ~/.bashrc or ~/.bash_profile:
bash
export PATH="$HOME/bin:$PATH"

Apply the changes:
bash
source ~/.bashrc


ENSURE PHP CLI IS ACCESSIBLE

Verify which PHP version is available (DirectAdmin typically has multiple PHP versions):
bash
php -v

If the default PHP is incorrect, specify the version explicitly (check what's available in DirectAdmin):
bash
/usr/local/php80/bin/php ~/bin/composer.phar require package/name

You can create a wrapper script in ~/bin/composer to always use the correct PHP version:
bash
#!/bin/bash
/usr/local/php80/bin/php $HOME/bin/composer.phar "$@"


CONFIGURE COMPOSER FOR LIMITED MEMORY
Shared hosting often has low memory limits. Set this before running Composer:
bash
php -d memory_limit=-1 ~/bin/composer install

Or create a composer.json config to increase memory in your project:
bash
COMPOSER_MEMORY_LIMIT=-1 composer install


HANDLE VENDOR DIRECTORY PERMISSIONS

Ensure proper permissions for the vendor directory:
bash
chmod -R 755 vendor/

In production, if your web server can't access files, add this to your .htaccess or ensure your public_html has proper permissions:
bash
chmod 755 public_html
chmod 644 public_html/*
The actual web server user (typically nobody, nobody, or a DirectAdmin-specific user) needs read permission, not write permission, on vendor files.


RUN COMPOSER AS YOUR DIRECTADMIN USER

Always execute Composer commands directly as your user:
bash
composer install
composer update
composer require vendor/package
Never run with sudo or try to switch users — the whole point is working within your own account.


PROJECT STRUCTURE BEST PRACTICE

Keep your directory structure like this:
~/public_html/ (web root)
index.php
.htaccess
~/myproject/ (outside public root if possible)
composer.json
vendor/
src/
public_html -> ../public_html (symlink, optional)

Or if everything must be in public_html:
~/public_html/
index.php
composer.json
vendor/
src/


COMMON TROUBLESHOOTING

If you get "Permission denied" errors:
Make sure ~/bin/composer is executable: chmod +x ~/bin/composer
Run as your own user, not root or another user

If Composer runs out of memory:
Use COMPOSER_MEMORY_LIMIT=-1 composer install
Check shared hosting memory limits with DirectAdmin or contact support

If PHP CLI isn't found:
Use the full path to PHP: /usr/local/php80/bin/php ~/bin/composer ...
Ask your host which PHP CLI versions are available

  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?