「Grav」の版間の差分
Kusanaginoturugi (トーク | 投稿記録) (→Prerequisites: 飜訳) |
Kusanaginoturugi (トーク | 投稿記録) (→前提条件: 校正) |
||
32行目: | 32行目: | ||
* Apache(mod_proxy_fcgi を使用)→ FPM |
* Apache(mod_proxy_fcgi を使用)→ FPM |
||
− | Grav のインストールは、Arch Linux の [[ |
+ | Grav のインストールは、Arch Linux の [[ウェブアプリケーションパッケージガイドライン]] に準拠しています。これは、他の詳細とともに、Grav は独自のシステムユーザー (''grav'') で実行する必要があることを意味します。したがって、{{pkg|php-apache}} を使用して Apache プロセスで PHP コードを直接実行することはもうできません。 |
== Installation == |
== Installation == |
2023年4月11日 (火) 18:44時点における版
関連記事
Wikipedia より:
- Grav は、PHP プログラミング言語と Symfony Web アプリケーションフレームワークをベースして書かれたフリーソフトウェアでセルフホスト型のコンテンツ管理システム(CMS)です。バックエンドとフロントエンドの両方でフラットファイルデータベースを使用します。
- Grav は学習曲線が浅く、セットアップが簡単であるように設計されています。Grav の焦点は、複雑さを犠牲にした豊富な組み込み機能よりも、スピードとシンプルさです。
目次
前提条件
Grav は驚くほど少ない前提条件で提供されています。もちろん PHP で書かれたウェブアプリケーションなので PHP が必要です。必要な PHP モジュールは php-gd のみです。他にもいくつか必要ですが、それらはすでに PHP インストール時に含まれています。次の PHP モジュールはオプションですが、パフォーマンス向上のために強くお勧めします。
Grav は独自の機能でコンテンツを提供できますが、この記事ではフル機能のウェブサーバを前提としたセットアップを説明します。したがって、必要なものは以下の通りです。
- ウェブサーバ:Apache HTTP Server または nginx など
- アプリケーションサーバ:uWSGI(uwsgi-plugin-php と一緒に)または FPM
以下の組み合わせをカバーしています:
- nginx → uWSGI(プラス uwsgi-plugin-php)
- nginx → FPM
- Apache(mod_proxy_uwsgi を使用)→ uWSGI(プラス uwsgi-plugin-php)
- Apache(mod_proxy_fcgi を使用)→ FPM
Grav のインストールは、Arch Linux の ウェブアプリケーションパッケージガイドライン に準拠しています。これは、他の詳細とともに、Grav は独自のシステムユーザー (grav) で実行する必要があることを意味します。したがって、php-apache を使用して Apache プロセスで PHP コードを直接実行することはもうできません。
Installation
Install the gravAUR package. This automatically takes care of installing the two requires dependencies php and php-gd. Also install php-apcu and php-yamlAUR - preferrably as a dependency (--asdeps
). Comment the only line in /etc/php/conf.d/yaml.ini
. Do not modify /etc/php/conf.d/apcu.ini
, i.e. leave the only line commented. Activating these two extensions for Grav will be taken care of in other places (see below).
Application server
There are two prevalent application servers that can be used to process PHP code: uWSGI or FPM. FPM as the name suggests is specialized on PHP. The protocol used between the web server and FPM is fastcgi. The tool is has been part of the PHP distribution since many years and is actively maintained. The downside being that the official documentation leaves much room for improvement. uWSGI on the other hand can serve code written in a handful of languages by means of language specific plugins. The protocol used is uwsgi (lowercase). The tool is extensively documented - albeit the sheer amount of documentation can become confusing and unwieldy. Maintainance has slowed down significantly - this applies especially for the PHP plugin.
uWSGI
uWSGI has its own article. A lot of useful information can be found there. Install uwsgi and the plugin uwsgi-plugin-php - preferrably as dependencies, i.e. with --asdeps
. Setup of your Grav application requires only copying one file and defining one systemd service.
grav.ini
Copy the Grav specific uWSGI setup file to the appropriate location.
# cp /usr/share/webapps/grav/webserver-configs/uwsgi-grav.ini /etc/uwsgi/grav.ini
Make sure grav.ini
is owned and only writeable by root, i.e. -rw-r--r-- 1 root root ... grav.ini
. This configuration is functional but feel free to adapt it to your liking. E.g. you might like to change php-set = date.timezone=
to your preferred timezone.
Systemd service
The package uwsgi provides a template unit file (uwsgi@.service
). The instance ID (here grav) is used to pick up the right configuration file. So we start/enable uwsgi@grav.service
.
In case you have more than a few (e.g. 2) services started like this and get the impression this is a waste of resource you might consider using emperor mode.
FPM
In case you opt to use FPM as your application server install php-fpm - preferrably as a dependent package (--asdeps
).
You have to tweak its configuration a little bit.
php-fpm.ini
It is a good practice to run FPM with its own version of php.ini
. You thus avoid cluttering the standard INI file (/etc/php/php.ini
) with stuff only needed by FPM. There is a copy of a functional INI file in /usr/share/webapps/grav/webserver-configs
. Copy it to /etc/php
.
# cp /usr/share/webapps/grav/webserver-configs/php-fpm.ini /etc/php
Make sure it is owned and only writeable by root. Something along -rw-r--r-- 1 root root ... php-fpm.ini
. Feel free to customize the configuration as you see fit.
grav.conf
You have to create a so called pool file for FPM. It is responsible for spawning a dedicated FPM process for the Grav application. Copy the version provided by the gravAUR package.
# cp /usr/share/webapps/grav/webserver-configs/php-fpm.d/grav.conf /etc/php/php-fpm.d
Again make sure this pool file is owned and only writeable by root (i.e. -rw-r--r-- 1 root root ... grav.conf
). You may tweak some settings (especially pm...
and php_admin_value[date.timezone]
to your liking.
Systemd service
FPM is run as a systemd service. You have to modify the service configuration to be able to run Grav. This is best achieved by means of a drop-in file.
/etc/systemd/system/php-fpm.service.d/override.conf
[Service] ExecStart= ExecStart=/usr/bin/php-fpm --nodaemonize --fpm-config /etc/php/php-fpm.conf --php-ini /etc/php/php-fpm.ini ReadWritePaths=/etc/webapps/grav/config PrivateTmp=false
The drop-in file has three purposes.
- It replaces the
ExecStart
line by a start command that uses thephp-fpm.ini
covered in the previous section. - It explicitly enables read/write access on
/etc/webapps/grav/config
that would otherwise be inhibited byProtectSystem=full
in/usr/lib/systemd/system/php-fpm.service
. - It disables the
PrivateTmp
option set in/usr/lib/systemd/system/php-fpm.service
as this doesn't work together withphp_admin_value[open_basedir] = …:/var/tmp/$pool:…
in/etc/php/php-fpm.d/grav.conf
.
Do not forget to start/enable php-fpm.service
.
Web server
There is an abundance of web servers you can choose from. Whatever option you finally choose you have to keep in mind that the Grav application needs to be run with its own system user grav. So you probably need to forward your requests to one of the above mentioned application servers.
nginx
Configuration of nginx is way beyond the scope of this article. See the relevant article for further information. The package gravAUR comes with a sample configuration file /usr/share/webapps/grav/webserver-configs/nginx.conf
. This file is not functional as is. Use it as a starting point for your own configuration. Most likely you will have to copy it into /etc/nginx/sites-available
with an appropriate name and create the corresponding symbolic link in /etc/nginx/sites-enabled
.
The sample file assumes you are using SSL/TLS and some ACME client (e.g. Certbot) to get your certificates. OCSP stapling is not configured.
Things you might have to adapt (not exhaustive):
- Your server name (
server_name
clauses 2x), i.e. the server part of the URL your Grav installation will be reachable with. - The name of the certificate and key you use for SSL / TLS.
- If and where you want an access log written to.
- The location where Certbot (or any other ACME client) will put the domain verification challenges.
- The path under which your Grav installation will be reachable. (The part right to the server name & port section in the URL.)
- What application server (uWSGI or FPM) you are using, i.e. how and where nginx will pass requests that need to trigger some PHP code.
There is no need to install any additional modules since nginx natively supports both protocols FastCGI and uwsgi.
Grav's documentation also covers setting up Grav with nginx. But be aware that the instructions are Ubuntu / Debian centric and do not mention uWSGI.
Apache HTTP Server
Unfortunately upstream Grav does not provide a sample configuration file for Apache HTTP Server. At least there is a section in this wiki about how to integrate Apache with PHP by means of FPM and mod_proxy_fcgi. uWSGI's documentation has some information about how to integrate Apache with PHP by means of uWSGI and mod_proxy_uwsgi. Mind that the apache package comes with both modules mod_proxy_fcgi and mod_proxy_uwsgi. They need to be loaded as required.
Plugins
A lot of Grav's power comes from the large set of plugins that can be installed. Just follow the instructions on Grav's documentation how to install plugins.
Currently there are no grav-plugin-... packages that allow installing plugins via pacman
(or some AUR wrapper). This will probably not change in the foreseeable future.
Content
See the extensive documentation on Grav's website on how to create content with this CMS.
Skeletons
Chances are the big empty board named Grav appears too intimidating to you. In this case you may want to use one of the many skeletons as a starting point. Skeletons are prefabricated bundles of Grav itself, some plugins, a theme and some sample content that give you some bits and pieces to play around with. Skeletons are supposed to be installed instead of a bare Grav installation. Unfortunately this makes it impossible to use a skeleton together with the gravAUR package.
With a bit of fiddling you can import the content of an arbitrary skeleton into your existing Grav installation.
- Download the desired skeleton.
- Extract the
user
directory:# bsdtar -xf grav-skeleton-blahblah.zip user
- Replace the directories
pages
,plugins
andthemes
in/var/lib/grav/user
with the corresponding directories from the extracteduser
directory. - Fix ownership and permissions
# chown -R grav:http /var/lib/grav/user/{pages,plugins,themes}
# chmod -R 640 /var/lib/grav/user/{pages,plugins,themes}
# find /var/lib/grav/user/{pages,plugins,themes} -type d -exec chmod 750 {} \; - Replace the configuration files
site.yaml
system.yaml
in/etc/webapps/grav/config
with the corresponding files from the extracteduser/config
. - Fix ownership and permissions
# chown grav:grav /etc/webapps/grav/config/{site,system}.yaml
# chmod 644 /etc/webapps/grav/config/{site,system}.yaml
Migrating from v1.6 to v1.7
Migrating from earlier package versions (< 1.7) will most likely require manual intervention. Errors may happen. So backup your data before trying an upgrade from earlier version! This comprises at least the /usr/share/webapps/grav/user
directory.
The upgrade will probably fail right away with lots of error messages complaining about files already existing under /usr/share/webapps/grav/vendor
. Just delete this directory.
Since the last package of version 1.6 (v1.6.28, 2020-11-18) php has been upgraded from version 7 to 8. This may render some of your plugins non-functional.
Grav v1.7 has become stricter in many ways. See Grav's migration guide about details.
Do not try to tweak your setup to use system user http as used to be. For good reasons Arch Linux' web application package guidelines dictates to use a dedicated system user (here grav) to run the application.
Probably the best migration strategy is to backup the /usr/share/webapps/grav/user
directory, uninstall Grav and all dependent packages, remove all remnants of the Grav installation (including all Grav specific configurations with your web server and application server), update your system (including PHP) and then install Grav from scratch. When everything is set up and your server successfully presents Grav's default page you can start to restore your previous content.
Upgrade
Upgrading Grav itself must exclusively be done by pacman (or some AUR wrapper)!
Unlike upgrading Grav itself, upgrading plugins and themes must be done with gpm update
or via the admin plugin.
Also not recommended is to download Grav releases as ZIP archives directly from Grav's GitHub project site and copy around stuff in the filesystem. Only do so when you know exactly what you are doing.