如何在CentOS 7上安装Koel
月月
・11 分钟阅读
使用不同的系统?
Koel是一个简单的基于Web的个人音频流应用程序,在客户端使用Vue编写,在服务器端使用Laravel编写。Koel源代码托管在github上 ,本指南将向你展示如何使用PHP ,MariaDB ,nginx ,Node.js ,yarn和Composer,在新的Centos7实例上安装Koel 。
要求
- PHP版本5.6.4或更高版本,有以下扩展名:
- OpenSSL
- PDO
- Mbstring
- Tokenizer
- XML
- MariaDB
- Node.js的最新稳定版本带有
yarn
- Composer
- Nginx
开始之前
检查CentOS版本。
cat /etc/centos-release
# CentOS Linux release 7.5.1804 (Core)
使用sudo
访问创建一个新的非root用户帐户,并且切换到它。
useradd -c"John Doe" johndoe && passwd johndoe
usermod -aG wheel johndoe
su - johndoe
注:将johndoe
替换为你的用户名。
设置时区。
timedatectl list-timezones
sudo timedatectl set-timezone 'Region/City'
确保你的系统是最新的。
sudo yum update -y
安装必要的软件包。
sudo yum install -y wget curl vim git && sudo yum groupinstall -y"Development Tools"
为简便起见,请禁用SELinux和防火墙。
sudo setenforce 0
sudo systemctl stop firewalld
sudo systemctl disable firewalld
安装PHP
设置Webstatic YUM repo 。
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装PHP和所需的PHP扩展。
sudo yum install -y php72w php72w-cli php72w-fpm php72w-common php72w-mysql php72w-curl php72w-json php72w-zip php72w-xml php72w-mbstring
检查版本。
php --version
# PHP 7.2.7 (cli) (built: Jul 1 2018 08:22:47) ( NTS )
启动并启用php服务。
sudo systemctl start php-fpm.service
sudo systemctl enable php-fpm.service
安装MariaDB并设置数据库
为MariaDB创建repo ,打开"%s" sudo vi /etc/yum.repos.d/MariaDB.repo
然后用下面的方法填充。
[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
保存并退出,然后安装MariaDB 。
sudo yum install -y MariaDB-server MariaDB-client
检查版本。
mysql --version
# mysql Ver 15.1 Distrib 10.2.16-MariaDB, for Linux (x86_64) using readline 5.1
启动并启用MariaDB服务。
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
运行mysql_secure_installation
以提高安全性,并为MariaDB root
用户设置密码。
sudo mysql_secure_installation
作为root
用户连接到MariaDB 。
mysql -u root -p
# Enter password:
为Koel创建一个空的Mariadb数据库和用户,并记住凭据。
CREATE DATABASE dbname;
GRANT ALL ON dbname.* TO 'username' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT
安装和配置Nginx
安装Nginx 。
sudo yum install -y nginx
检查版本。
sudo nginx -v
# nginx version: nginx/1.12.2
启动并启用Nginx 。
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
配置Nginx ,运行 sudo vim /etc/nginx/conf.d/koel.conf
并使用以下配置填充文件。
server {
listen 80;
server_name example.com;
root /var/www/koel;
index index.php;
# Whitelist only index.php, robots.txt, and those start with public/ or api/ or remote
if ($request_uri !~ ^/$|index.php|robots.txt|api/|public/|remote) {
return 404;
}
location /media/ {
internal;
# A 'X-Media-Root' should be set to media_path settings from upstream
alias $upstream_http_x_media_root;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
try_files $uri $uri/ /index.php?$args;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_intercept_errors on;
include fastcgi_params;
}
}
测试Nginx配置。
sudo nginx -t
重新加载Nginx 。
sudo systemctl reload nginx.service
安装Node.js
安装node.js 。
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
sudo yum -y install nodejs
检查版本。
node --version
# v8.11.3
安装Yarn
安装Yarn软件包管理器。
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
sudo yum install -y yarn
检查版本。
yarn --version
# 1.9.2
安装Composer
安装Composer。
php -r"copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r"if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { 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 --version
# Composer version 1.6.5 2018-05-04 11:44:59
安装Koel
创建一个空文档根目录,其中将安装Koel 。
sudo mkdir -p /var/www/koel
导航到文档根目录。
cd/var/www/koel
将/var/www/koel
文件夹的所有权更改为用户johndoe
。
sudo chown -R johndoe:johndoe /var/www/koel
将Koel存储库克隆到它,签出最新的标记版本,并且安装它依赖项。
git clone https://github.com/phanan/koel.git .
git checkout v3.7.2
composer install
运行php artisan koel:init
命令来设置数据库和管理员帐户。
php artisan koel:init
运行vim .env
并将APP_URL
设置为你的URL 。
APP_URL=http://example.com
运行yarn install
来编译和安装前端依赖项。
yarn install
注:如果内存不足,将收到错误消息,如果要避免这种情况,可以暂时停止MariaDB,Nginx和php fpm服务,或者配置交换内存。
将/var/www/koel
目录的所有权更改为nginx
。
sudo chown -R nginx:nginx /var/www/koel
运行sudo vim/etc/php-fpm.d/www.conf
并将用户和组设置为nginx
,最初,它将被设置为apache
。
sudo vim /etc/php-fpm.d/www.conf
# user = nginx
# group = nginx
重新启动php fpm 。
sudo systemctl restart php-fpm.service
设置已完成,要继续,在网络浏览器中打开域名,你将看到登录页面,然后,输入你以前创建的管理员帐户凭据登录。