• Indonesian
  • English
  • Install Composer on Shared Hosting cPanel via Terminal —

    Kecepatan:

    Introduction

    One day I got a request from a client: “I want to install Laravel on shared hosting, but Composer isnt available.” This is actually a very common question — many developers used to VPS or dedicated servers forget that shared hosting typically doesnt come with Composer pre-installed. On a VPS, you can just run apt install composer or yum install composer. But on shared hosting, you dont have root access and need to install it manually.

    What makes this interesting is that a few years ago I actually thought installing Composer on shared hosting was impossible. Turns out its not — as long as your hosting supports cPanel Terminal, you can install Composer with a single long command run from the cPanel terminal. No SSH needed, no root access, no compiling from source. Just one command, done.

    In this article Ill show you how to install Composer on shared hosting cPanel using the terminal feature, step by step. Ill also explain what each part of the command does so you understand it, not just blindly copy-paste.

    What Is Composer?

    Before we get to the install command, its important to understand what Composer is and why you need it.

    Composer Is a Package Manager for PHP

    Composer is a dependency management tool for PHP. Simply put, Composer helps you install, update, and manage the PHP libraries and packages your project needs. Its similar to npm for JavaScript or pip for Python.

    When you install a package using Composer, it will:

    • Download the requested package along with all its dependencies
    • Install the package into the vendor/ directory in your project
    • Create a composer.json file containing the dependency list
    • Create a composer.lock file that locks the exact version of each package

    Why Is Composer Important?

    Many modern PHP frameworks and libraries require Composer to install:

    • Laravel — the most popular PHP framework, requires Composer
    • Symfony — an enterprise PHP framework
    • PHPUnit — the testing framework for PHP
    • PHPMailer — a library for sending email
    • Guzzle — an HTTP client for PHP
    • And hundreds of other PHP libraries

    Without Composer, you cant install modern frameworks or the PHP libraries that many applications require.

    Preparation: Make Sure Your Hosting Supports Terminal

    Check If Your Hosting Supports Terminal

    Before trying to install Composer, make sure your hosting provides the cPanel Terminal feature. Not all shared hosting supports this — some hosting only provides File Manager and phpMyAdmin without terminal access.

    How to check:

    1. Log into cPanel
    2. Look for the “Terminal” or “SSH Access” menu in the “Advanced” section
    3. If the menu exists and is clickable, your hosting supports terminal
    4. If it doesnt exist, contact your hosting provider to ask if the terminal feature is available

    Alternatives If Terminal Isnt Available

    If your hosting doesnt support terminal, there are some alternatives:

    • Install via File Manager — download composer.phar from the official website, upload via File Manager, then run it from a cron job
    • Ask your hosting provider to install Composer — some hosting providers will install Composer for you
    • Upgrade to a VPS — if youre serious about using Composer, consider upgrading to a VPS that gives you full root access

    How to Install Composer on cPanel

    ⚠️ SECURITY WARNING: Backup First!

    Before running the install command, make sure youve backed up any important files in your home directory. Although installing Composer doesnt delete existing files, better safe than sorry.

    # Backup important files in home directory
    # (run from cPanel File Manager or terminal before install)
    cp -r ~/public_html /tmp/backup-public_html-$(date +%Y%m%d-%H%M) 2>/dev/null
    cp ~/.bashrc /tmp/backup-bashrc-$(date +%Y%m%d-%H%M) 2>/dev/null

    Step 1: Open cPanel Terminal

    1. Log into cPanel
    2. Find the “Terminal” menu in the “Advanced” section
    3. Click the “Terminal” menu
    4. Youll see a terminal that looks like SSH — this is a web-based terminal that lets you run commands on the server

    ⚠️ IMPORTANT: The cPanel terminal runs as your user (not root). All commands you run will execute with your users permissions. This means you cant install packages system-wide, but you can install Composer in your home directory.

    Step 2: Run the Composer Install Command

    Heres the complete command to install Composer on shared hosting cPanel:

    cd ~ && curl -4sS https://getcomposer.org/installer -o composer-setup.php && php composer-setup.php --checksum=$(curl -4sS https://composer.github.io/installer.sig) && mkdir -p $HOME/bin && mv composer.phar $HOME/bin/composer && chmod +x $HOME/bin/composer && rm composer-setup.php && composer --version

    Dont just copy-paste — read the explanation of each command part below so you understand what it does.

    Command Part Breakdown

    1. cd ~ — Change to your home directory (~ is shorthand for the users home directory). This ensures all operations run in the correct directory — the one belonging to you.

    2. curl -4sS https://getcomposer.org/installer -o composer-setup.php — Download the Composer installer from the official website. Flag breakdown: -4 = use IPv4 only (avoids DNS dual-stack issues), -s = silent mode (no progress bar), -S = show errors (display errors if any). The installer file is saved as composer-setup.php.

    3. php composer-setup.php --checksum=$(curl -4sS https://composer.github.io/installer.sig) — Run the Composer installer. The --checksum flag verifies the downloaded installer isnt corrupt or modified. The checksum is downloaded from https://composer.github.io/installer.sig and compared with the installer files checksum. If they dont match, installation fails — this is a security measure to ensure you get the authentic installer.

    4. mkdir -p $HOME/bin — Create a bin directory in the home directory if it doesnt exist. The -p flag means “parents” — no error if the directory already exists. This bin directory will store executable files that can be run from the command line without needing the full path.

    5. mv composer.phar $HOME/bin/composer — Move the composer.phar file (the installed Composer executable) to the bin directory and rename it to composer. This way you can run composer from any directory without needing php composer.phar.

    6. chmod +x $HOME/bin/composer — Grant execute permission (+x) to the composer file. Without this permission, the file cant be run as an executable.

    7. rm composer-setup.php — Delete the installer file which is no longer needed. This file was only needed for the installation process — once Composer is installed, the installer can be removed.

    8. composer --version — Verify that Composer was installed successfully by displaying the installed Composer version. If this command outputs something like “Composer version 2.6.5”, the installation succeeded.

    Step 3: Configure PATH (Optional but Recommended)

    So the composer command can be run from any directory without needing the full path, make sure $HOME/bin is in your PATH:

    # Check if $HOME/bin is already in PATH
    echo $PATH | grep -q "$HOME/bin" && echo "PATH is already correct" || echo "PATH needs configuration"
    
    # Add $HOME/bin to PATH (for this session)
    export PATH=$HOME/bin:$PATH
    
    # Add to .bashrc to make it persistent
    echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc

    After this configuration, you can run composer from any directory without needing ~/bin/composer.

    Step 4: Verify Installation

    After installation, verify that Composer works correctly:

    # Check Composer version
    composer --version
    
    # Check Composer help
    composer --help
    
    # Test creating a new project (optional)
    mkdir /tmp/test-composer && cd /tmp/test-composer
    composer init --name="test/project" --no-interaction
    ls -la

    Example Verification Output

    $ composer --version
    Composer version 2.6.5 2023-10-06 10:11:52
    
    $ composer --help
    Description:
      Composer Command Line Interface
    
    Usage:
      composer [options] [command] [arguments]
    
    Options:
      --help (-h)           Display this help message
      --quiet (-q)          Do not output any message
      --verbose (-v|vv|vvv) Increase the verbosity of messages
      --version (-V)        Display this application version
      --ansi                Force ANSI output
      --no-ansi             Disable ANSI output
      ...
    

    Using Composer After Installation

    Installing Packages to a Project

    After Composer is installed, you can use it to install packages in your project:

    # Navigate to project directory
    cd ~/public_html/myproject
    
    # Install a package (e.g., PHPMailer)
    composer require phpmailer/phpmailer
    
    # Install all dependencies from composer.json
    composer install
    
    # Update all dependencies to latest versions
    composer update

    Creating a New Project with Composer

    Composer can also be used to create new projects directly from templates:

    # Create a new Laravel project
    composer create-project laravel/laravel myproject
    
    # Create a new Symfony project
    composer create-project symfony/skeleton myproject

    Check Dependency Status

    # List all installed packages
    composer show
    
    # Check packages that are outdated
    composer outdated
    
    # Run security audit on packages
    composer audit

    Troubleshooting: Installation Failed

    Problem 1: “curl: (6) Could not resolve host”

    This error appears due to DNS or connectivity issues. Solutions:

    # Try using direct IP (optional)
    curl -4sS https://151.101.2.49/installer -o composer-setup.php
    
    # Or check internet connectivity
    ping -c 3 getcomposer.org

    Problem 2: “php: command not found”

    Some shared hosting uses different PHP binary names:

    # Try php8.1, php8.2, or php-cgi
    php8.2 composer-setup.php
    # or
    /usr/bin/php-cgi composer-setup.php

    Problem 3: “Permission denied” when running composer

    Make sure the file permissions are correct:

    # Check permissions
    ls -la ~/bin/composer
    
    # If not +x, run chmod
    chmod +x ~/bin/composer

    Problem 4: “checksum mismatch” during installation

    This error appears because the checksum doesnt match — the file might be corrupt or the installer version changed. Solution:

    # Re-download the installer
    rm -f composer-setup.php
    curl -4sS https://getcomposer.org/installer -o composer-setup.php
    
    # Run install without checksum (optional, less secure)
    php composer-setup.php

    Pro Tips: Using Composer on Shared Hosting

    1. Install in the home directory, not public_html — Composer and the vendor/ directory should not be in a publicly accessible directory. Install Composer in ~/bin and run installs in the appropriate project directory.
    2. Use composer install in production — in production, use composer install (not composer update) to ensure package versions match composer.lock.
    3. Add vendor/ to .gitignore — dont commit the vendor/ directory to Git. This directory can be regenerated with composer install.
    4. Use composer audit — run composer audit periodically to check if any packages have known security vulnerabilities.
    5. Optimize the autoloader — in production, run composer install --optimize-autoloader to speed up loading times.
    6. Backup composer.lock — the composer.lock file is very important because it locks package versions. Back this file up to a safe location.
    7. Use --no-dev in production — if you dont need development packages (testing, debugging), use composer install --no-dev to reduce installation size.

    FAQ

    Can Composer be installed on all shared hosting?

    Not all. Composer requires PHP (minimum PHP 5.3.2) and the terminal feature in cPanel. If your hosting doesnt support terminal or the PHP version is too old, Composer cannot be installed. Check with your hosting provider whether the terminal feature is available.

    Will Composer affect website performance?

    Not directly. Composer is just a tool for installing packages — the installed packages run as usual. But Composer itself must not be in a public directory (public_html) because it can expose sensitive information. Make sure Composer is installed in the home directory, not in public_html.

    How do I update Composer after installation?

    Run the command composer self-update from the terminal. This will update Composer to the latest version. To update to a specific major version, use composer self-update --2 or composer self-update --1.

    Can I use Composer without cPanel terminal?

    Yes, but its more complicated. You can download composer.phar directly from the official website, upload it via File Manager, then run it via a cron job or PHP script. But this method isnt recommended because its less practical and less secure.

    Related Issues

    Conclusion

    Installing Composer on shared hosting cPanel is actually not as complicated as you might think. With one long command run from cPanel Terminal, Composer can be installed and immediately used. The key is to make sure your hosting supports terminal, run the command in the home directory (not public_html), and verify after installation.

    Most importantly, dont install Composer in the public directory (public_html) because Composer can expose sensitive information. Install it in the home directory, run composer install or composer create-project in the appropriate project directory, and make sure vendor/ isnt publicly accessible. Better to install it correctly from the start than to have to explain to a client why there are sensitive files exposed on their website — trust me, Ive been there and I dont want to go through that again.