drupal应用部署

Drupal是一款诞生于2000年的基于PHP语言编写的经典开源内容管理框架。

坊间传说drupal使用成本比wp高,偶然的机会看到一个基于drupal搭建的网站还不赖。兴趣使然,简单研究了一下drupal的搭建和使用。
以下简单给出搭建的关键步骤:

composer工具准备

1
2
3
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/sbin/
composer self-update
1
2
3
4
5
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/bin --filename=composer --version=1.9.0
composer config -g --unset repos.packagist
composer config -g repo.packagist composer https://packagist.phpcomposer.com

以lightning为例部署

1
2
composer create-project acquia/lightning-project drupal
chown -R nobody:nobody drupal
  • drupal/docroot为应用根目录
  • drupal默认使用sqlite数据库不需要单独配置

nginx配置

以上方式部署完成后,用nginx的默认php应用配置会导致除了首页能访问,其它所有页面全部404,
根据drupal的路由特点需要简单配置rewrite规则,nginx应用的基本配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
server {
listen *:80;
# include vhosts/vhosts.listen.addr;
# server_name localhost;

#charset koi8-r;

access_log logs/host.access.log main;

location / {
root html/drupal/docroot;
index index.php index.htm;
try_files $uri $uri/ @rewrite;
}

location ~ ^/sites/.*/private/ {
access_log off;
internal;
}

location @rewrite {
rewrite ^/(.*)$ /index.php?q=$1;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
root html/drupal/docroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

如此一来,基本上就可以用了。。。

参考