How do i run 'composer' command via SSH?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# How Do I Run 'composer' Command via SSH on Shared Hosting? A Developer's Guide As developers, we often encounter friction when moving from a local development environment to remote servers, especially shared hosting environments. The scenario you’ve described—needing to run essential dependency management commands like `composer dump-autoload` but hitting the dreaded `-bash: composer: command not found` error via SSH—is incredibly common. This post will walk you through why this happens and provide robust solutions for executing Composer commands remotely, ensuring your Laravel project dependencies remain pristine, regardless of the hosting environment. ## Understanding the "Command Not Found" Error When you run a command like `composer` locally, your operating system (Linux/macOS) knows exactly where the executable file resides because it is typically added to your system's `$PATH` environment variable. However, on many shared hosting environments, the execution context is highly restricted. The error `-bash: composer: command not found` means that while PHP might be installed, the Composer binary itself is either not installed globally or, more commonly in shared hosting setups, it is installed in a location that your SSH session cannot automatically discover through the standard PATH lookup. The core issue isn't with Composer itself; it’s how the remote shell finds the executable file. ## Solution 1: Locating and Executing Composer Directly The most reliable solution when dealing with restricted environments is to bypass the reliance on the system `$PATH` and explicitly tell the shell exactly where the command lives. ### Step 1: Finding the Composer Binary First, you need to locate where Composer is installed on the server. Since shared hosting setups vary significantly, you might need to search common locations or check the root directory of your project if you previously ran an installation there. If you can find the executable (e.g., in `/usr/local/bin/composer` or within your project's `vendor` directory structure), use its absolute path. ### Step 2: Executing with the Full Path Instead of running `composer dump-autoload`, run it using the full path you discovered. For example, if Composer is located at `/usr/local/bin/composer`: ```bash /usr/local/bin/composer dump-autoload ``` This method bypasses any PATH issues and forces the shell to execute the exact file you specify, making it highly portable across different remote servers. ## Solution 2: Leveraging PHP for Execution (The Alternative Approach) In some environments, especially those centered around PHP, Composer is often executed indirectly through the PHP interpreter itself. This method can sometimes work if the `php` executable is accessible and configured correctly. You can attempt to run Composer via the `php` executable to execute a script or command that relies on it: ```bash php /path/to/composer.phar dump-autoload ``` Or, if you are dealing with standard package management within a Laravel context, ensure your project environment is set up correctly. For managing dependencies in modern PHP projects, understanding the underlying structure that powers tools like those discussed at **[laravelcompany.com](https://laravelcompany.com)** is crucial. ## Best Practice: Project-Specific Execution Since you are working on a specific Laravel project, ensure you navigate to the root directory of that project before attempting any command. This keeps your execution context clean and ensures that relative paths (if used) resolve correctly. ```bash cd /path/to/your/laravel/project # Now execute using the full path method: /usr/local/bin/composer dump-autoload ``` ## Conclusion Running system commands via SSH on remote servers, particularly shared hosting, demands a shift from relying on assumed global paths to explicit execution. By understanding the environment constraints and opting for absolute paths, you can reliably execute essential tools like Composer, ensuring your Laravel project's autoloading is correctly managed every time, regardless of the server configuration. Always prioritize clarity and explicit instruction when dealing with remote shell environments.