Piwigo インストール · 3 min read · Jan 23, 2026

Debian WheezyでNginx上にPiwigoギャラリーをインストールする

Debian WheezyでNginx上にPiwigoギャラリーをインストールする

このチュートリアルでは、Debian Wheezyシステム上でvhosts用に設定されたnginxを使用してpiwigoギャラリーサイトをインストールして実行する方法を示します。Piwigoは多くのプラグインを持つギャラリーウェブサイトです。 このサンプルでは、vhost「gallery.domain.tld」を設定します。

インストール

nginx用のパッケージをインストール

apt-get install nginx php5-fpm php5 php5-mysql php5-pgsql php5-imap php-pear php5-sqlite php5-ldap php5-gd php5-imagick php5-curl php-apc
apt-get install php5-mcrypt php5-pspell php5-xmlrpc php5-xsl php5-cgi php-auth php-auth-sasl php-net-smtp

MySQLサーバーをインストール

 apt-get install mysql-server

Nginxを設定

デフォルトサイトを削除(オプション)

rm -f /etc/nginx/sites-enabled/default

vhosts用のテンプレートファイルを作成

cd /etc/nginx/sites-available/
touch template-with-ssl
touch template

sslサポートのあるvhost

ファイルに以下を挿入

nano /etc/nginx/sites-available/template-with-ssl
server {
listen        80;
# .domain.comはdomain.comとanything.domain.comの両方に一致します
server_name www.domain.tld domain.tld;
rewrite ^ https://$server_name$request_uri? permanent;

# サーバーブロックのルートはサーバーレベルに配置するのが最適であり、ロケーションレベルではありません
# すべてのロケーションブロックパスはこのルートに対して相対的になります。
root /var/www/www.domain.tld;

# ログを設定するのは常に良いことですが、エラーログをオフにすることはできません
# error_log off;を設定すると、単に'off'という名前のファイルが作成されます。
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;

# これはhttp { }レベルにも配置できます
index index.html index.htm index.php;

location / {
# wordpressを使用していて、追加のリライトを望まない場合
# その場合、@rewritesの単語を/index.phpに置き換えます
try_files $uri $uri/ @rewrites;
}

location @rewrites {
# ここに独自のリライトルールをいくつか入れることができます
# 例えばrewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# 何も一致しない場合は、単に/index.phpに送信します
rewrite ^ /index.php last;
}

# このブロックは、画像、css、jsなどの静的ファイルリクエストをキャッチします
# ?:プレフィックスは「非キャプチャ」マークであり、$1にパターンをキャプチャする必要がないことを意味します
# これによりパフォーマンスが向上します
location ~* \\.(?:ico|css|js|gif|jpe?g|png)$ {
# 静的ファイルをブラウザに送信するための基本的なキャッシュ制御
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# wordpressの仮想robots.txtを使用したい場合はロボット行を削除します
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# これは、隠しファイル(ピリオドで始まるファイル)が提供されるのを防ぎます
location ~ \\. { access_log off; log_not_found off; deny all; }

location ~ \\.php {
fastcgi_param        SCRIPT_NAME $fastcgi_script_name;
fastcgi_param        SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index        index.php;
fastcgi_pass        unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}
# ssl-vhostを使用したい場合
server {
listen        443 default ssl;
# .domain.comはdomain.comとanything.domain.comの両方に一致します
server_name www.domain.tld domain.tld;

ssl_certificate        /etc/nginx/ssl/www.domain.tld.crt;
ssl_certificate_key        /etc/nginx/ssl/www.domain.tld.key;
# サーバーブロックのルートはサーバーレベルに配置するのが最適であり、ロケーションレベルではありません
# すべてのロケーションブロックパスはこのルートに対して相対的になります。
root /var/www/www.domain.tld;

# ログを設定するのは常に良いことですが、エラーログをオフにすることはできません
# error_log off;を設定すると、単に'off'という名前のファイルが作成されます。
access_log /var/log/nginx/example.access.log;
error_log /var/log/nginx/example.error.log;

# これはhttp { }レベルにも配置できます
index index.html index.htm index.php;

location / {
# wordpressを使用していて、追加のリライトを望まない場合
# その場合、@rewritesの単語を/index.phpに置き換えます
try_files $uri $uri/ @rewrites;
}

location @rewrites {
# ここに独自のリライトルールをいくつか入れることができます
# 例えばrewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# 何も一致しない場合は、単に/index.phpに送信します
rewrite ^ /index.php last;
}

# このブロックは、画像、css、jsなどの静的ファイルリクエストをキャッチします
# ?:プレフィックスは「非キャプチャ」マークであり、$1にパターンをキャプチャする必要がないことを意味します
# これによりパフォーマンスが向上します
location ~* \\.(?:ico|css|js|gif|jpe?g|png)$ {
# 静的ファイルをブラウザに送信するための基本的なキャッシュ制御
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# wordpressの仮想robots.txtを使用したい場合はロボット行を削除します
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# これは、隠しファイル(ピリオドで始まるファイル)が提供されるのを防ぎます
location ~ \\. { access_log off; log_not_found off; deny all; }

location ~ \\.php {
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;

}
}

HTTPのみのvhost

nano /etc/nginx/sites-available/template
server {
listen        80;
# .domain.comはdomain.comとanything.domain.comの両方に一致します
server_name www.domain.tld domain.tld;
#rewrite ^ https://$server_name$request_uri? permanent;

# サーバーブロックのルートはサーバーレベルに配置するのが最適であり、ロケーションレベルではありません
# すべてのロケーションブロックパスはこのルートに対して相対的になります。
root /var/www/www.domain.tld;

# ログを設定するのは常に良いことですが、エラーログをオフにすることはできません
# error_log off;を設定すると、単に'off'という名前のファイルが作成されます。
access_log /var/log/nginx/rugia.access.log;
error_log /var/log/nginx/rugia.error.log;

# これはhttp { }レベルにも配置できます
index index.html index.htm index.php;

location / {
# wordpressを使用していて、追加のリライトを望まない場合
# その場合、@rewritesの単語を/index.phpに置き換えます
try_files $uri $uri/ @rewrites;
}
location @rewrites {
# ここに独自のリライトルールをいくつか入れることができます
# 例えばrewrite ^/~(.*)/(.*)/? /users/$1/$2 last;
# 何も一致しない場合は、単に/index.phpに送信します
rewrite ^ /index.php last;
}

# このブロックは、画像、css、jsなどの静的ファイルリクエストをキャッチします
# ?:プレフィックスは「非キャプチャ」マークであり、$1にパターンをキャプチャする必要がないことを意味します
# これによりパフォーマンスが向上します
location ~* \\.(?:ico|css|js|gif|jpe?g|png)$ {
# 静的ファイルをブラウザに送信するための基本的なキャッシュ制御
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}

# wordpressの仮想robots.txtを使用したい場合はロボット行を削除します
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }

# これは、隠しファイル(ピリオドで始まるファイル)が提供されるのを防ぎます
location ~ \\. { access_log off; log_not_found off; deny all; }

location ~ \\.php {
fastcgi_param        SCRIPT_NAME $fastcgi_script_name;
fastcgi_param        SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index        index.php;
fastcgi_pass        unix:/var/run/php5-fpm.sock;
include fastcgi_params;
}
}

最初のvhostを作成

テンプレートを使用

 cp /etc/nginx/sites-available/template /etc/nginx/sites-available/gallery.domain.tld

パス変数を編集

 nano /etc/nginx/sites-available/gallery.domain.tld
server_name gallery.domain.tld;
root /var/www/gallery.domain.tld;
access_log /var/log/nginx/gallery.access.log;
error_log /var/log/nginx/gallery.error.log;

ディレクトリ構造を作成

mkdir -p /var/www/gallery.domain.tld
chown -R www-data:www-data /var/www

vhostを有効にする

 ln -s /etc/nginx/sites-available/gallery.domain.tld /etc/nginx/sites-enabled/gallery.domain.tld

サービスを再起動します:

/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart

PHPをテスト

phpinfoを使用してテストファイルを作成:

 nano /var/www/gallery.domain.tld/test.php 

クイックテストの目的で、vhost名でhostsファイルを編集します; このサンプルでは、サーバーのIPは

192.168.1.10

です:

  192.168.1.10  gallery.domain.tld

今、ブラウザを開いて、次に移動します:

 http://gallery.domain.tld

インストールされたphpバージョンに関する情報ページが表示されれば、すべて正常です 今、テストファイルを削除できます:

 rm -f  nano /var/www/gallery.domain.tld/test.php 

Piwigoを設定

データベースとユーザーを作成

ユーザー名: gallery01
パスワード: PASSWORD

MySQLに接続:

 mysql -u root -p

create database gallery01;
grant all on gallery01.* to ‘gallery’@’localhost’ identified by ‘PASSWORD’;
flush privileges;
\q;

piwigoのnetinstallファイルをダウンロード

cd /var/www/gallery.domain.tld
wget http://piwigo.org/download/dlcounter.php?code=netinstall
mv dlcounter.php\?code\=netinstall netinstall.php
chown www-data:www-data netinstall.php

設定の微調整

 nano /etc/php5/fpm/php.ini 
upload_tmp_dir = /tmp  
upload_max_filesize = 20M  
max_file_uploads = 20
nano /etc/nginx/nginx.conf 
client_max_body_size 20M;         
client_body_buffer_size 128k;

サービスを再起動するのを忘れないでください:

/etc/init.d/php5-fpm restart
/etc/init.d/nginx restart

ウェブインストーラーを使用

ブラウザを開いて、次に移動します:

http://gallery.domain.tld/netinstall.php

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。