前言
最近手痕買咗報 HX400V,加上之前啲自拍,希望可以有個地方放自己相片而又公開。但,現有平臺並非好選擇,畢竟唔少平臺有其限制,例如500px就試過改規則只可以用佢嘅lincense去共享、又或者幫你賣相事件,反映而家有啲網絡平臺爲咗錢,真係……所以self-host保平安。
Piwigo
而Piwigo係一個PHP寫嘅相簿網站程式,雖然我單機用不過該程式係可以支持多用戶管理嘅功能,將整個team add入嚟都係冇問題嘅。而Piwigo係用PHP寫,並配以mysql運行,並以GPL License釋出源代碼。除咗相簿功能外,仲可以提供RSS訂閱、電郵接收變更通知、上傳影片、權限控制甚至YouTube及GoogleMaps支援等。
官網:https://piwigo.org/
GitHub:(https://github.com/Piwigo/Piwigo
安裝Nginx 及 php
係首先安裝之前,請緊記安裝nginx及php。
首先安裝nginx:sudo apt update && sudo apt install nginx
之後啓用nginx嘅service:
sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
加入php 嘅 repo:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
更新:
sudo apt update
安裝piwigo要用嘅php plugin:
sudo apt install php7.2-fpm php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2 php7.2-ldap php7.2-zip php7.2-curl
修改PHP設定:
sudo nano /etc/php/7.2/fpm/php.ini
修改以下部分嘅設定:
file_uploads = On
allow_url_fopen = On
memory_limit = 256M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M // if you upload raw, you can set it to be higher
date.timezone = Aisa/Hong_Kong
儲存離開。
安裝及設定DB
鍵入,安裝:
sudo apt-get install mariadb-server mariadb-client
啓動service:
sudo systemctl stop mariadb.service
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
進行init:
sudo mysql_secure_installation
設定成功後重啓db:
sudo systemctl restart mysql.service
登入database:
sudo mysql -u root -p
創建database及piwigo用:
CREATE DATABASE piwigo;
創建用戶:
CREATE USER 'piwigouser'@'localhost' IDENTIFIED BY '新密碼';
給予該用戶piwigo databse嘅完整權限:
GRANT ALL ON piwigo.* TO 'piwigouser'@'localhost' IDENTIFIED BY '新密碼' WITH GRANT OPTION;
重新整理然後離開:
FLUSH PRIVILEGES;
EXIT;
安裝Piwigo
首先下載piwigo並複製到指定位置:
cd /tmp && curl -o piwigo.zip http://piwigo.org/download/dlcounter.php?code=latest
unzip piwigo.zip
sudo mv piwigo /var/www/piwigo
修改持有用戶並修改存取權限:
sudo chown -R www-data:www-data /var/www/piwigo/
sudo chmod -R 755 /var/www/piwigo/
創建piwigo 嘅 nginx設定檔:
sudo nano /etc/nginx/sites-available/piwigo
格式如下:
server {
listen 80;
listen [::]:80;
listen 443;
listen [::]:443;
root /var/www/piwigo;
index index.php index.html index.htm;
server_name piwigo.example.com;
client_max_body_size 100M;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
啓用該設定檔:
sudo ln -s /etc/nginx/sites-available/sentrifugo /etc/nginx/sites-enabled/
重開nginx:
sudo systemctl restart nginx.service
之後進入你嘅網站首頁(例如 https://piwigo.example.com ),就會出現初始設定畫面: