在Fedora 28上安装 Fork CMS
圣地学子
・10 分钟阅读
使用不同的系统?
Fork是一个用PHP编写的开源CMS。fork的源代码托管于GitHub ,本指南会向你展示如何在新的Fedora28实例上安装fork CMS。
要求
- PHP 7.1或更高,
- MySQL 5.0或更高,
- 启用了.htaccess,mod rewrite,mod expires (可选,但是推荐)和mod deflate (可选)的Nginx或Apache 2.0,
开始之前
检查Fedora版本。
cat /etc/fedora-release
# Fedora release 28 (Twenty Eight)
使用sudo访问权限创建一个新的非root用户帐户,并且切换到该帐户。用你的用户名替换johndoe
。
useradd -c"John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoe
设置时区。
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'
确保你的系统是最新的。
sudo dnf check-upgrade || sudo dnf upgrade -y
安装必需的和有用的软件包。
sudo dnf install -y wget vim unzip bash-completion
为简便起见,请禁用SELinux和防火墙。
sudo setenforce 0
sudo systemctl stop firewalld
sudo systemctl disable firewalld
步骤1安装PHP所需的PHP扩展nginx和MySQL
下载并安装PHP和所需的PHP扩展。
sudo dnf install -y php-cli php-fpm php-common php-mbstring php-gd php-intl php-mysqlnd php-xml php-json
检查PHP版本。
php --version
# PHP 7.2.6 (cli) (built: May 22 2018 16:22:08) ( NTS )
# Copyright (c) 1997-2018 The PHP Group
# Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
安装Nginx 。
sudo dnf install -y nginx
检查Nginx版本。
nginx -v
# nginx version: nginx/1.12.1
启动并启用Nginx 。
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
安装MariaDB 。
sudo dnf install -y mariadb-server
检查MariaDB版本。
mysql --version
# mysql Ver 15.1 Distrib 10.2.15-MariaDB, for Linux (x86_64) using readline 5.1
启动并启用MariaDB 。
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
运行mysql_secure_installation
脚本以提高MariaDB安装的安全性。
sudo mysql_secure_installation
以root用户身份登录到MariaDB 。
mysql -u root -p
# Enter password:
创建新的MariaDB数据库和用户,并记住凭据。
create database dbname;
grant all on dbname.* to 'username' identified by 'password';
退出MySQL 。
exit
步骤2配置nginx
运行 sudo vi /etc/nginx/conf.d/fork.conf
然后用下面的方法填充。
server {
listen 80;
root /var/www/fork;
index index.php index.html;
server_name example.com;
location / {
# Checks whether the requested url exists as a file $uri or directory $uri/ in the root, else redirect to /index.php.
try_files $uri $uri/ @redirects;
}
location @redirects {
rewrite ^ /index.php;
}
location ~ .php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock; # Make sure to doublecheck this!
fastcgi_index index.php;
fastcgi_read_timeout 60;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# Don't pollute the logs with common requests
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
# As Fork CMS has the app_root as doc_root, we need to restrict access to a few things for security purposes!
location ~* ^/(composer..*|vendor/.*|Procfile$|.git/.*|src/Console.*|.*.gitignore|.editorconfig|.travis.yml|autoload.php|bower.json|phpunit.xml.dist|.*.md|app/logs/.*|app/config/.*|src/Frontend/Cache/CompiledTemplates.*|src/Frontend/Cache/Locale/.*.php|src/Frontend/Cache/Navigation/.*.php|src/Frontend/Cache/Search/.*|src/Backend/Cache/CompiledTemplates/.*|src/Backend/Cache/Locale/.*.php)$ {
deny all;
access_log off;
log_not_found off;
}
# Deny access to dot-files.
location ~ /. {
deny all;
access_log off;
log_not_found off;
}
}
你将要进行的更改的总结如下。
- 更改
root
的值以指向网站的正确位置,如/var/www/fork
, - 更改
server_name
的值以指向你的域名或IP地址, - 确保检查
fastcgi_pass
是否正确设置,
测试Nginx配置。
sudo nginx -t
重新加载Nginx 。
sudo systemctl reload nginx.service
步骤3下载并安装Composer
下载composer依赖项。
sudo dnf install -y curl git unzip
下载并安装Composer,PHP的依赖项管理器。
php -r"copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r"if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r"unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer
检查composer版本。
composer --version
# Composer version 1.6.5 2018-05-04 11:44:59
步骤4通过Composer下载并安装fork CMS
创建文档root目录。
sudo mkdir -p /var/www/fork
将/var/www/fork目录的所有权更改为johndoe 。
sudo chown -R johndoe:johndoe /var/www/fork
从命令行下载最新的fork CMS稳定版本。
cd /var/www/fork
composer create-project forkcms/forkcms .
将/var/www/fork目录的所有权更改为nginx。
sudo chown -R nginx:nginx /var/www/fork
运行sudo vim/etc/php-fpm.d/www.conf
,并且会用户和组设置为nginx
。
sudo vim /etc/php-fpm.d/www.conf
# user = nginx
# group = nginx
重新启动php-fpm.service
。
sudo systemctl restart php-fpm.service
编辑app/config/parameters.yml.dist
文件,并且设置数据库信息。
sudo vim /var/www/fork/app/config/parameters_install.yml
创建/var/lib/php/session
目录并将它所有权更改为用户nginx
。
sudo mkdir -p /var/lib/php/session
sudo chown -R nginx:nginx /var/lib/php/session
最后,使用首选的浏览器,打开站点,并且遵循Fork CMS
安装程序,之后,你会有一个fork实例启动和运行,访问fork管理区域只需将/private
附加到站点URL 。