Ce este Composer?

Pe această pagină
  1. What is Composer?
  2. Step 1: Connect via SSH
  3. Step 2: Download Composer
  4. Step 3: Create or Manage a Project
  5. Step 4: Configure the Web Directory (Symbolic Links)
  6. How to run standard Composer commands
  7. Practical Implications for mybox Users
  8. Summary

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.

  1. Enable SSH in the mybox panel.
  2. Connect using a terminal or PuTTY.
  3. 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.

  1. Download the latest stable version:wget https://getcomposer.org/download/latest/composer.phar
  2. (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

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:

  1. If an empty public_html exists, remove it: rm -rf public_html
  2. 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.phar file outside of the public_html directory if possible, or ensure your .htaccess prevents 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.

Nu ai găsit răspunsul?

Echipa noastră de asistență este aici pentru tine 24/7 – scrie-ne și te ajutăm să rezolvi problema.