在Ubuntu 16.04上安装fork CMS
Tianye
・8 分钟阅读
使用不同的系统?
fork是一个用PHP编写的开源CMS ,fork的源代码托管于GitHub ,本指南会向你展示如何在Ubuntu 16.04实例上安装fork CMS 。
要求
- PHP 7.1或更高,
- MySQL 5.0或更高,
- 启用了.htaccess,mod rewrite,mod expires (可选,但是推荐)和mod deflate (可选)的Nginx或Apache 2.0,
开始之前
检查Ubuntu版本。
lsb_release -ds
# Ubuntu 16.04.3 LTS
使用sudo
访问创建一个新的non-root
用户帐户,并且切换到它。
adduser johndoe --gecos"John Doe"
usermod -aG sudo johndoe
su - johndoe
注:将johndoe替换为你的用户名。
设置时区。
sudo dpkg-reconfigure tzdata
确保你的系统是最新的。
sudo apt update && sudo apt upgrade -y
步骤1安装PHP和所需的PHP扩展MySQL和nginx
Ubuntu不在它默认软件存储库中提供最新的PHP版本。我们需要添加社区维护的个人包存档(PPA)。
下载并安装PHP 7.1和所需的PHP扩展。
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install -y php7.1 php7.1-cli php7.1-fpm php7.1-curl php7.1-mbstring php7.1-gd php7.1-intl php7.1-mysql php7.1-xml
检查PHP版本。
php --version
# PHP 7.1.11-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Oct 27 2017 13:49:56) ( NTS )
# Copyright (c) 1997-2017 The PHP Group
# Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
# with Zend OPcache v7.1.11-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
因为有许多现有文档详细描述了MySQL和Nginx的安装,所以,本文仅介绍Nginx的配置。
步骤2配置nginx
运行 sudo vim /etc/nginx/sites-available/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:/var/run/php/php7.1-fpm.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
是否正确设置,
通过将文件链接到sites-enabled
目录来激活新的fork.conf
配置。
sudo ln -s /etc/nginx/sites-available/fork.conf /etc/nginx/sites-enabled/
测试Nginx配置。
sudo nginx -t
重新加载Nginx,并且重新启动
sudo systemctl reload nginx.service
sudo systemctl restart php7.1-fpm.service
步骤3下载并安装Composer
下载composer依赖项。
sudo apt 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.5.2 2017-09-11 16:59:25
步骤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目录的所有权更改为www-data 。
sudo chown -R www-data:www-data /var/www/fork
编辑app/config/parameters.yml.dist
文件,并且设置数据库信息。
sudo vim /var/www/fork/app/config/parameters_install.yml
使用你首选的浏览器,打开你的站点,并且遵循Fork CMS
安装程序,访问fork管理区域只需将/private
附加到站点URL 。