Table of Contents
What is Composer?
Composer is the industry-standard dependency manager for PHP. It allows you to declare the libraries your project depends on and manages (installs/updates) them for you. Instead of manually downloading ZIP files for every library, Composer automates the process and ensures all components are compatible with each other.
In the mybox environment, you use a local version of Composer (composer.phar). This gives you the flexibility to use different Composer versions for different projects while maintaining full control over your PHP environment.
Step 1: Connect via SSH
To use Composer, you must be connected to your server’s command line.
- Enable SSH in the mybox panel.
- Connect using a terminal or PuTTY.
- Navigate to your domain’s directory:
cd yourdomain.com
Step 2: Download Composer
Since you will run Composer locally, you need to download the executable archive into your folder.
- Download the latest stable version:
wget https://getcomposer.org/download/latest/composer.phar - (Optional) Grant execute permissions to the file:
chmod +x composer.phar
Step 3: Create or Manage a Project
When running Composer commands at mybox, you must specify which PHP version you want to use. This ensures your libraries are compatible with your site’s settings.
Example: Creating a new Laravel project using PHP 8.2
php82 composer.phar create-project --prefer-dist laravel/laravel my_new_app
Example: Requiring a new package (e.g., PHPMailer)
php82 composer.phar require phpmailer/phpmailer
Step 4: Configure the Web Directory (Symbolic Links)
Modern PHP frameworks like Laravel or Symfony keep their entry point in a /public subfolder for security. However, the mybox server looks for your website in the public_html directory.
To bridge this, you can create a symbolic link:
- If an empty
public_htmlexists, remove it:rm -rf public_html - Link your project’s public folder to
public_html:ln -s my_new_app/public public_html
Now, when a visitor accesses your domain, the server will correctly serve the files from your Composer-managed project.
How to run standard Composer commands
Simply replace the word composer with phpXX composer.phar.
| Standard Command | mybox Equivalent (using PHP 8.2) |
composer install | php82 composer.phar install |
composer update | php82 composer.phar update |
composer require [package] | php82 composer.phar require [package] |
Practical Implications for mybox Users
- PHP Version Matching: Always use the same PHP version in the command line (e.g.,
php82) that you have selected for your domain in the mybox panel. This prevents “version mismatch” errors where Composer installs a library that your website cannot actually run. - Memory Limits: Large Composer operations (like
update) can be memory-intensive. If a process stops unexpectedly, check your mybox panel resource logs to see if a temporary Boost Pack is needed for the installation. - Security: Keep your
composer.pharfile outside of thepublic_htmldirectory if possible, or ensure your.htaccessprevents it from being downloaded by visitors.
Summary
Using Composer at mybox is a straightforward process that enables you to build professional, modern PHP applications. By utilizing the composer.phar file and specifying your PHP version, you maintain a clean, isolated, and highly manageable development environment.