2016年4月17日 星期日

在Ubuntu上 使用 Drush 安裝 Drupal

先檢查更新
$sudo apt-get update
$sudo apt-get upgrade

安裝 Drush 及 PHP套件
$sudo apt-get install drush php-console-table

此步驟有錯誤,可以略過
$sudo pear channel-discover pear.drush.org

$sudo pear install drush/drush

重點在這裡,如果Drush有安裝成功,接下來都好處理
$sudo drush version

$sudo cd /var/www/html/

$sudo drush dl drupal

$sudo mv /var/www/html/drupal-7.xx /var/www/html/drupal

$sudo cd /drupal

這裡的重點在 --site-name 及 --account-pass,如果不指定,系統會預設帳號為admin,密碼會隨機產生
$sudo drush site-install standard --site-name='你的帳號' --clean-url=0 --account-pass='你的密碼' --db-url=mysql://root:password@localhost/drupal

安裝簡潔網址
$sudo a2enmod rewrite

修改設定
$sudo vi /etc/apache2/apache2.conf

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All  #原本是 None,請改成All
Require all granted
</Directory>

#底下這個是不存在的,請直接新增
<Directory /var/www/html>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
AllowOverride All
</Directory>

重新啟動 apache
$sudo servcie apache2 restart


這時可以開啟網頁進行設定了,一般是開啟 http://localhost
然後使用上述的 --site-name 及 --account-pass 登入
登入後,可以看到最上方有設定的頁籤,請再跟著設定

"Configuration" => "Clean URLs" 點選啟用

中文化
  1.  "Modules" => "Locale" 啟用
  2.  "Configuration" => "Languages" => "Add language" => "Chinese,Traditional" => "DEFAULT"打勾 "ENABLED"打勾
  3. "Configuration" => "Translate interface" => "IMPORT" => Language file(drupal-7.xx.zh-hant.po)
    中文化檔案請至此下載
此時就能看到中文化介面囉!!

P.S.: 
有些狀況,像是某路徑無法存取、更新模組不成功(ftp無法使用)。請先試著將相關目錄 chmod 777。
Drupal根目錄的 sites目錄,可以先 $sudo chown www-data:www-data -R sites