Ubuntu下安装Piwigo
Page content
首先,通过apt在终端中运行以下命令来确保所有系统软件包都是最新的。
sudo apt update
sudo apt upgrade
然后,安装LAMP堆栈。
安装PHP及扩展
sudo apt-get install php php-xml php-mbstring php-gd
sudo apt-get install php-mysql
php -v
PHP 7.4.3 (cli) (built: Jul 5 2021 15:13:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
下载安装Piwigo
使用以下命令从其官方网站下载最新版本的Piwigo:
curl -o piwigo.zip http://piwigo.org/download/dlcounter.php?code=latest
接下来,使用以下命令解压缩下载的文件:
unzip piwigo.zip
mv piwigo /var/www/html/piwigo
chown -R www-data:www-data /var/www/html/piwigo/
chmod -R 755 /var/www/html/piwigo/
准备数据库
登录到MySQL数据库并执行以下命令以创建将用于管理数据库的Piwigo数据库和用户。
# sudo mysql -u root -p
create database piwigo_db;
create user [email protected] identified by 'your-strong-passwd';
grant all privileges on piwigo_db.* to [email protected];
flush privileges;
为Piwigo配置服务器
常见的有Apache和Nginx两种Web Server。
Apache2
安装Apache
sudo apt-get purge apache2
sudo apt-get install apache2
Enable php7.4
sudo a2dismod mpm_event
sudo systemctl restart apache2
sudo a2enmod mpm_prefork
sudo systemctl restart apache2
sudo a2enmod php7.4
sudo systemctl restart apache2
配置文件
在Apache中创建一个新的虚拟主机指令。例如,在您的虚拟服务器上创建一个名为piwigo.conf
的新Apache配置文件:
touch /etc/apache2/sites-available/piwigo.conf
ln -s /etc/apache2/sites-available/piwigo.conf /etc/apache2/sites-enabled/piwigo.conf
vim /etc/apache2/sites-available/piwigo.conf
<VirtualHost *:8888>
ServerAdmin [email protected]
DocumentRoot /var/www/html/piwigo
ServerName piwigo.binjian.net
<Directory /var/www/html/piwigo/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
重新启动Apache
重新启动Apache Web服务器,以便进行更改:
sudo a2enmod rewrite
sudo a2ensite piwigo.conf
sudo systemctl restart apache2.service
检查apache是否在监听8888端口
~ sudo netstat -tlpn| grep apache
tcp6 0 0 :::8080 :::* LISTEN 1735780/apache2
tcp6 0 0 :::8888 :::* LISTEN 1735780/apache2
Nginx
启动fpm
sudo systemctl restart php7.4-fpm
安装nginx
sudo apt-get install nginx
sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-08-31 10:18:18 UTC; 34min ago
Docs: man:nginx(8)
Process: 1814266 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1814273 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1814520 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Main PID: 1814276 (nginx)
Tasks: 2 (limit: 1074)
Memory: 8.4M
CGroup: /system.slice/nginx.service
├─1814276 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─1814521 nginx: worker process
新增配置
新建 /etc/nginx/sites-enabled/piwigo.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html/piwigo;
index index.php index.html index.htm index.nginx-debian.html;
server_name piwigo.binjian.net;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
检查并重新加载配置
nginx -t
sudo systemctl reload nginx
sudo netstat -tlpn| grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1814276/nginx: mast
tcp6 0 0 :::80 :::* LISTEN 1814276/nginx: mast
Nginx配置文件的结构和最佳做法
- 所有Nginx配置文件都位于/etc/nginx目录中。
- 主要的Nginx配置文件为/etc/nginx/nginx.conf。
- 为使Nginx配置更易于维护,建议为每个域创建一个单独的配置文件。您可以根据需要拥有任意数量的服务器块文件。
- Nginx服务器块文件存储在/etc/nginx/sites-available目录中。除非它们链接到/etc/nginx/sites-enabled目录,否则Nginx不会使用此目录中找到的配置文件。
- 要激活服务器块,您需要从以下目录中的配置文件站点创建符号链接(指针)将sites-available目录移到sites-enabled目录。
- 建议遵循标准命名约定,例如,如果您的域名是mydomain.com,则您的配置文件应命名为/etc/nginx/sites-available/mydomain.com.conf ]
- /etc/nginx/snippets目录包含可包含在服务器块文件中的配置片段。如果使用可重复的配置段,则可以将这些段重构为片段,并将片段文件包括到服务器块中。
- Nginx日志文件(access.log和error.log)位于/var/log/nginx目录中。建议每个服务器块使用不同的access和error日志文件。
- 您可以将域文档根目录设置为所需的任何位置。 Webroot的最常见位置包括:
- /home/<user_name>/<site_name>
- /var/www/<site_name>
- /var/www/html/<site_name>
- /opt/<site_name>
浏览器访问
打开浏览器,在端口8888/80上导航至服务器IP地址或域名,以检查新网络端口是否可以在您的网络中访问。
Piwigo默认页面应显示在浏览器中: http://server_ip:port
本文由 络壳 原创或整理,转载请注明出处