How do I install Composer on a shared hosting?

How do I install Composer on a shared hosting?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Installing Composer on Shared Hosting Without SSH Access

When you are locked out of SSH access, the standard curl -sS https://getcomposer.org/installer | php approach fails immediately because you cannot execute that temporary installer script in your user context to generate a local binary. However, this constraint does not prevent you from using Composer; it simply shifts the installation strategy from generating a local executable to leveraging a global PHAR file or relying on the hosting provider's tools.

Your environment lists FTP access and cPanel alongside a specific set of system capabilities: PHP, Perl, CGI-BIN, Python, Curl, and Cron jobs running on FreeBSD. This combination is actually quite powerful for executing one-off PHP scripts without needing root-level SSH. The core challenge is getting the Composer autoloader logic into your project directory while bypassing the need to run php composer.phar directly from your home folder if you lack write access there, or simply using the global binary if available.

Leveraging cPanel's Built-in Composer

Most modern shared hosting environments that provide cPanel also ship with a globally installed Composer binary located at /usr/local/bin/composer. Before attempting to download a PHAR file manually, check your root home directory or the public_html folder for an existing installation. If you have shell access via cPanel's Terminal (SSH session provided by the host), you can simply run:

composer --version

If this returns a version number, you do not need to install anything. You can proceed directly to creating your composer.json in your project root and running composer require luracast/restler. This is the most efficient path as it avoids downloading large PHAR files that might hit upload limits.

The Manual PHAR Installation Strategy

If cPanel does not provide a terminal or the global binary is missing, you must rely on FTP to transfer the Composer installer and run it via PHP. Since you have curl available in your environment, you can download the latest version of the composer.phar file directly to your server using an HTTP client or by utilizing a script that runs within your web root.

A common pitfall on shared hosting is attempting to install the PHAR into your public_html folder. Many hosts restrict write access in this directory for security reasons, and running a script there might result in a "Permission Denied" error when Composer tries to cache dependencies in vendor/. Instead, create a temporary folder in a location where you have write permissions, or better yet, use the global PHP executable if it exists system-wide.

If you must download the file via FTP from the source provided (like http://api.odtu.lu/composer.phar), transfer it to your home directory (e.g., /home/username/) via FTP. Once there, verify that PHP can execute it:

php /home/username/composer.phar --version

If this command works, you have effectively "installed" Composer in your user space. You can now run composer require luracast/restler from any project folder within your home directory. The vendor folder will be created locally, avoiding the permission issues associated with the public web root.

Automating Restler Installation via Cron

Your requirement to install Luracast/Restler suggests you might need a long-running service or a scheduled task to generate API documentation or handle webhook events. Since you have Cron jobs on FreeBSD, you can automate the installation of dependencies for specific projects.

Create a shell script in your home directory that initializes the project and installs Restler:

#!/bin/sh
cd /home/username/public_html/my_restler_project
php /home/username/composer.phar require luracast/restler
# Run any subsequent build commands here

Make sure the script is executable. Then, add a cron job to run this script daily or whenever needed. Remember that cron jobs on shared hosting often share the same PHP-FPM pool as your website, so ensure your composer.phar path is absolute and points to a location with read permissions for the web server user.

Trade-offs and Limitations

The primary limitation of this approach is version control. The PHAR file contains a snapshot of Composer's dependencies at the time of download. If you are building a production application, relying on the global cPanel binary (if available) or keeping your PHAR updated manually is preferable. Additionally, be cautious with the vendor/ directory size; some hosts enforce strict disk quotas per user. Installing massive libraries like Restler with all its dependencies could quickly fill up your allocated space if you are not careful about cleanup strategies.

Finally, while this method allows you to bypass SSH restrictions, it is inherently less secure than a managed environment because the global PHP-FPM process might be running as the same user for everyone on that server. Always ensure your composer.json includes strict dependency management to prevent accidental overwrites of system files during the installation process.

Our network