我使用的作業環境ubuntu 16.04 + php5.6

一、 安裝composer

  • 更新來源包的資料

             sudo apt-get update

  • 安裝預備套件

   sudo apt-get install curl php-cli php-mbstring git unzip

  • 下載與安裝Composer

  curl -sS https://getcomposer.org/installer -o composer-setup.php

  • 配置Composer全域環境設定

     sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

           p.s : 安裝的composer的指令composer,預設安裝在 /usr/local/bin 。 

  • 產生composer.phar

             php composer-setup.php

二、 安裝CI與Composer之間需要的擴充套件

       安裝CI的時候如果出現此問題表示有很多相依套件沒裝

Problem 1
 - Installation request for magento/product-enterprise-edition 2.0.2 -> satisfiable by magento/product-enterprise-edition[2.0.2].
 - magento/product-enterprise-edition 2.0.2 requires ext-gd * -> the requested PHP extension gd is missing from your system.

 To enable extensions, verify that they are enabled in those .ini files:
 - /etc/php5/cli/php.ini
 - /etc/php5/cli/conf.d/05-opcache.ini
 - /etc/php5/cli/conf.d/10-pdo.ini
 - /etc/php5/cli/conf.d/20-curl.ini
 - /etc/php5/cli/conf.d/20-imap.ini
 - /etc/php5/cli/conf.d/20-json.ini
 - /etc/php5/cli/conf.d/20-mcrypt.ini
 - /etc/php5/cli/conf.d/20-pdo_pgsql.ini
 - /etc/php5/cli/conf.d/20-pgsql.ini
 - /etc/php5/cli/conf.d/20-pspell.ini
 - /etc/php5/cli/conf.d/20-readline.ini
 You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
sudo apt-get update
sudo apt-get install mcrypt php5.6-mcrypt
sudo apt-get upgrade
sudo apt-get install php-mbstring
sudo apt-get install phpunit
sudo apt-get install php5-gd
sudo apt-get install php5-intl
sudo apt-get install php5-xsl 
sudo apt-get install php5.6-xml 
sudo service apache2 restart

 

三、在Codeigniter操作Composer自動載入套件

  • 建立CI專案

composer create-project codeigniter/framework test

  • 下載套件
  • composer.json 是設定檔,打開如下

在 require 添加我們想要下載的套件,例如 monolog/monolog

接著 update 套件

可以看到路徑 vendor/monolog 已經下載下來,而且還會看到依賴套件。

打開自動載入

修改 application/config/config.php

注意!若將 FALSE 改成 TRUE,代表你的路徑在 application/vendor/autoload.php。但我們的 vendor 在專案目錄,所以要自行填入路徑。當然官方預設是將 vendor 放在 application 內也是不錯的方法,要搬移或升級的時候也是比較明確。

測試是否如期的自動加載,打開 application/controllers/Welcome.php

寫寫看安裝的 Monolog (這是一個功能多的 log 工具) 能否觸發。

瀏覽網址,執行後就會看到專案底下有個 app.log 裡面內容如

參考資料 : 

1. Composer安裝

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-composer-on-ubuntu-16-04

2. 相依套件安裝

https://stackoverflow.com/questions/30868608/laravel-production-issue-updating-composer-with-laravel-4-1-x

https://laracasts.com/discuss/channels/forge/error-while-updating-to-php-70-on-forge

https://community.magento.com/t5/Installing-Magento-2-x/To-enable-extensions-verify-that-they-are-enabled-in-those-ini/td-p/31252

arrow
arrow
    全站熱搜

    忽倫 發表在 痞客邦 留言(0) 人氣()