ispconfig install Composer

  • Using command line and root login
  • Confirm which user needs to install composer.
  • For example user is ‘web66’
  • Modify /etc/passwd, search web66, change /bin/false to /bin/bash
web66:x:1048:1014::/var/www/clients/client26/web66:/bin/false
{change to}
web66:x:1048:1014::/var/www/clients/client26/web66:/bin/bash
  • chattr -i <Web Directory>
chattr -i /var/www/clients/client26/web66
  • change folder permission
chown web66 /var/www/clients/client26/web66
  • login to web66
su - web66
cd web
  • Download composer-setup.php and install
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  • Check the download file
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  • Install
php composer-setup.php
  • Delete install file
php -r "unlink('composer-setup.php');"
  • composer version check
composer -V
  • composer package install test
composer require monolog/monolog
  • composer update
composer update
  • Exit to root user
exit
  • chattr +i <Web Directory>
chattr +i /var/www/clients/client26/web66
  • Complete

自建了 php autoload ,並同時使用 composer 的 autoload,應該注意什麼?

不知道大家有沒有看過下面的 php autoload 教學?

Eric G. Huang 不像樣工程師
PHP系列 – Autoload 自動載入
http://justericgg.logdown.com/posts/196891-php-series-autoload

跟據這個教學,我解決了很多 class include require 檔案引入的困難,而且用了很長時間。

下面提供一些參考資料,讓大家可以分享。

Composer Basic usage: autoloading
https://getcomposer.org/doc/01-basic-usage.md#autoloading

PHP PSR-4 Autoloader 機制
http://blog.tonycube.com/2016/09/php-psr-4-autoloader.html

什麼是 PHP Standards Recommendations(PSR)(PHP標準建議)?
https://www.php-fig.org/psr/

PHP PSR-4 Autoloader 機制
http://blog.tonycube.com/2016/09/php-psr-4-autoloader.html

Composer Basic usage: autoloading
https://getcomposer.org/doc/01-basic-usage.md#autoloading

運用Composer Autoloader

1. 準備自建的 namespace 和 目錄位置

e.g. 
namespace1 = application\control\, 目錄位置 = {user_directory}/application/control 
namespace2 = application\module\, 目錄位置 = {user_directory}/application/module 
namespace3 = application\mouule\sql\, 目錄位置 = {user_directory}/application/module/sql
Class 例子:

<?php
//application/module/config.php

namespace application\module;

class config
{


    function __construct() {
        ...
    }
}

2. 在 composer.json 加入自建的 namespace 和 目錄位置

{
    "autoload": {
        "psr-4": {
            "application\\control\\": "application/control/",
            "application\\module\\": "application/module/",
            "application\\module\\sql\\": "application/module/sql/"
        }
    }
}

3. 進入 console mode,使用用戶權限及用戶的root目錄,執行下面的程式

composer dump-autoload

4. 在需要的php 程式中,頂部加入(因為我的 composer 是放在 /vendor中,請自行改進)

require __DIR__ . '/vendor/autoload.php';