本页内容

  • 前提条件
  • 第 1 步 - 配置防火墙
  • 第 2 步 - 安装 Nginx
  • 第 3 步 - 安装 PHP 及扩展
  • 第 4 步 - 安装并配置 MySQL Server
  • 第 5 步 - 下载 UVdesk
  • 第 6 步 - 配置 SELinux 权限
  • 第 7 步 - 安装并配置 SSL
  • 第 8 步 - 配置 Nginx 和 PHP 配置 PHP-FPM 配置 Nginx
  • 第 9 步 - 安装 UVdesk
  • 结论
  • 配置 PHP-FPM
  • 配置 Nginx

UVdesk 是一个开源的基于 Saas 的工单系统,供企业与客户互动并提供全天候支持。其功能包括工单管理、知识库支持、预设回复以及基于邮件自动生成工单。Uvdesk 的功能可以通过外部模块进行扩展。你可以基于特定触发器自动执行某些操作,以改进工作流程。

在本教程中,你将学习如何使用 Nginx、MySQL 和 PHP 在基于 Rocky Linux 8 的服务器上安装 Uvdesk。

前提条件

  • 一台运行 Rocky Linux 8 的服务器。
  • 一个指向该服务器的工单系统域名。在本教程中,我们将使用 uvdesk.example.com 域名。
  • 一个具有 sudo 权限的非 root 用户。
  • 确保所有内容都已更新。$ sudo dnf update
  • 安装基础工具包。其中一些可能已经安装。$ sudo dnf install wget curl nano unzip yum-utils -y

一台运行 Rocky Linux 8 的服务器。

一个指向该服务器的工单系统域名。在本教程中,我们将使用 uvdesk.example.com 域名。

一个具有 sudo 权限的非 root 用户。

确保所有内容都已更新。

$ sudo dnf update

安装基础工具包。其中一些可能已经安装。

$ sudo dnf install wget curl nano unzip yum-utils -y

第 1 步 - 配置防火墙

第一步是配置防火墙。Rocky Linux 使用 Firewalld Firewall。检查防火墙的状态。

$ sudo firewall-cmd --state
running

防火墙使用不同的区域,public 区域是我们将使用的默认区域。列出防火墙上所有处于活动状态的服务和端口。

$ sudo firewall-cmd --permanent --list-services

它应显示以下输出。

cockpit dhcpv6-client ssh

允许 HTTP 和 HTTPS 端口。

$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https

重新检查防火墙的状态。

$ sudo firewall-cmd --permanent --list-services

你应该会看到类似的输出。

cockpit dhcpv6-client http https ssh

重新加载防火墙以使更改生效。

$ sudo firewall-cmd --reload

第 2 步 - 安装 Nginx

Rocky Linux 自带的 Nginx 版本较旧。你需要下载官方 Nginx 仓库以安装最新版本。

创建并打开 /etc/yum.repos.d/nginx.repo 文件,用于创建官方 Nginx 仓库。

$ sudo nano /etc/yum.repos.d/nginx.repo

在其中粘贴以下代码。

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

按 Ctrl + X 并在提示时输入 Y 以保存文件。

安装 Nginx。

$ sudo dnf install nginx

验证安装。

$ nginx -v
nginx version: nginx/1.20.2

启用 Nginx 服务。

$ sudo systemctl enable nginx

第 3 步 - 安装 PHP 及扩展

在本教程中,我们需要使用 Remi 仓库安装最新版本的 PHP。第一步是获取 Epel 仓库。

$ sudo dnf install epel-release

接下来,安装 Remi 仓库。

$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

检查可用的 PHP streams。

$ dnf module list php -y
Last metadata expiration check: 0:00:12 ago on Fri 03 Dec 2021 09:39:32 AM UTC.
Rocky Linux 8 - AppStream
Name                Stream                 Profiles                                 Summary
php                 7.2 [d]                common [d], devel, minimal               PHP scripting language
php                 7.3                    common [d], devel, minimal               PHP scripting language
php                 7.4                    common [d], devel, minimal               PHP scripting language

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name                Stream                 Profiles                                 Summary
php                 remi-7.2               common [d], devel, minimal               PHP scripting language
php                 remi-7.3               common [d], devel, minimal               PHP scripting language
php                 remi-7.4               common [d], devel, minimal               PHP scripting language
php                 remi-8.0               common [d], devel, minimal               PHP scripting language
php                 remi-8.1               common [d], devel, minimal               PHP scripting language

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

默认版本是 7.2。启用 Remi 的 PHP 8.0 仓库。

$ sudo dnf module reset php
$ sudo dnf module enable php:remi-8.0

接下来,安装 UVDesk 所需的 PHP 及其扩展。

$ sudo dnf install php-fpm php-mbstring php-xml php-curl php-mysqlnd php-zip php-cli php-intl php-bcmath php-gd php-tokenizer php-imap php-pear php-mailparse

验证安装。

$ php --version
PHP 8.0.16 (cli) (built: Feb 15 2022 21:34:32) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.16, Copyright (c) Zend Technologies

第 4 步 - 安装并配置 MySQL Server

我们将使用 MySQL 数据库来存储数据。Rocky Linux 的 Appstream 仓库自带最新版本的 MySQL。

安装 MySQL。

$ sudo dnf install mysql-server

启用并启动 MySQL 服务。

$ sudo systemctl enable mysqld --now

加固 MySQL 安装。

$ sudo mysql_secure_installation

第一步,系统会询问你是否要设置 Validate Password Plugin,该插件可用于测试 MySQL 密码的强度。选择 Y 继续。下一步系统会要求你选择密码验证级别。选择 2,这是最强的级别,要求密码至少八个字符长,并包含大写字母、小写字母、数字和特殊字符的组合。

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

下一步系统会要求你设置 root 密码。选择一个满足密码验证插件要求的强密码。再下一步,系统会询问是否继续使用所选密码。按 y 继续。

Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

对于以下所有提示,按 Y 然后按 ENTER 键,以移除匿名用户和测试数据库、禁用 root 登录并加载新设置的规则。

...
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
...
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
...
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
...
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!

进入 MySQL shell。输入你的 root 密码以继续。

$ mysql -u root -p

创建 uvdesk 用户。确保密码满足之前设置的要求。

mysql> CREATE USER 'uvdesk'@'localhost' IDENTIFIED BY 'Your_password2';

创建 uvdeskdb 数据库。

mysql> CREATE DATABASE uvdeskdb;

授予该用户对 uvdeskdb 数据库的权限。

mysql> GRANT ALL PRIVILEGES ON uvdeskdb.* TO 'uvdesk'@'localhost';

退出 Shell。

mysql> exit

第 5 步 - 下载 UVdesk

下载 UVdesk 的最新稳定版本。

$ wget https://cdn.uvdesk.com/uvdesk/downloads/opensource/uvdesk-community-current-stable.zip

解压下载的文件。

$ unzip uvdesk-*.zip

将解压后的目录移动到 /var/www/uvdesk 位置。

$ sudo mv uvdesk-community-v1.0.18 /var/www/uvdesk

切换到 UVdesk 的目录。

$ cd /var/www/uvdesk

打开环境文件(.env)进行编辑。

$ sudo nano .env

找到 APP_ENV=dev 这一行并将其改为以下内容。

APP_ENV=prod

按 Ctrl + X 并在提示时输入 Y 以保存文件。

将根目录的所有权更改为 Nginx 用户。

$ sudo chown -R nginx:nginx /var/www/uvdesk

第 6 步 - 配置 SELinux 权限

使用 SELinux 的 chcon 命令,为从 /var/www/uvdesk 目录提供的 Web 内容更改文件安全上下文。

$ sudo chcon -t httpd_sys_content_t /var/www/uvdesk -R
$ sudo chcon -t httpd_sys_rw_content_t /var/www/uvdesk -R

配置 SELinux 以允许 UVDesk 的网络连接。

$ sudo setsebool -P httpd_can_network_connect on

第 7 步 - 安装并配置 SSL

要使用 Let's Encrypt 安装 SSL 证书,我们需要下载 Certbot 工具。安装 Certbot 需要 Epel 仓库,但由于我们在本教程前面已经安装过,因此可以跳过这一步。

安装 Certbot。

$ sudo dnf install certbot

生成 SSL 证书。

$ sudo certbot certonly --standalone --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m 
[email protected]
 -d uvdesk.example.com

上述命令会将证书下载到服务器上的 /etc/letsencrypt/live/uvdesk.example.com 目录。

生成 Diffie-Hellman 组证书。

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

为 Let's Encrypt 自动续期创建一个 challenge web 根目录。

$ sudo mkdir -p /var/lib/letsencrypt

创建一个用于续期 SSL 的 Cron Job。它将每天运行以检查证书并在需要时续期。为此,首先创建文件 /etc/cron.daily/certbot-renew 并打开进行编辑。

$ sudo nano /etc/cron.daily/certbot-renew

粘贴以下代码。

#!/bin/sh
certbot renew --cert-name uvdesk.example.com --webroot -w /var/lib/letsencrypt/ --post-hook "systemctl reload nginx"

按 Ctrl + X 并在提示时输入 Y 以保存文件。

更改任务文件的权限使其可执行。

$ sudo chmod +x /etc/cron.daily/certbot-renew

第 8 步 - 配置 Nginx 和 PHP

配置 PHP-FPM

打开文件 /etc/php-fpm.d/www.conf。

$ sudo nano /etc/php-fpm.d/www.conf

我们需要将 PHP 进程的 Unix 用户/组设置为 nginx。在文件中找到 user=www-data 和 group=www-data 这两行,并将它们改为 nginx。

...
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache user chosen to provide access to the same directories as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
...

按 Ctrl + X 并在提示时输入 Y 以保存文件。

启用并启动 PHP 服务。

$ sudo systemctl enable php-fpm --now

将 PHP sessions 目录的组更改为 Nginx。

$ sudo chgrp -R nginx /var/lib/php/session

配置 Nginx

创建并打开文件 /etc/nginx/conf.d/uvdesk.conf 进行编辑。

$ sudo nano /etc/nginx/conf.d/uvdesk.conf

在其中粘贴以下代码。

server {
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;
    server_name  uvdesk.example.com;

    access_log  /var/log/nginx/uvdesk.access.log;
    error_log   /var/log/nginx/uvdesk.error.log;
    
	# SSL
    ssl_certificate      /etc/letsencrypt/live/uvdesk.example.com/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/uvdesk.example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/uvdesk.example.com/chain.pem;
    ssl_session_timeout  5m;
    ssl_session_cache shared:MozSSL:10m;
    ssl_session_tickets off;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    resolver 8.8.8.8;

    root /var/www/uvdesk/public;
    index index.php;
    
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # Pass PHP Scripts To FastCGI Server
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass unix:/run/php-fpm/www.sock; # Depends On The PHP Version
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
        try_files $uri =404;
    }    
}

# enforce HTTPS
server {
    listen       80;
    listen       [::]:80;
    server_name  uvdesk.example.com;
    return 301   https://$host$request_uri;
}

注意 Nginx 配置中使用的根目录是 /var/www/uvdesk/public/,而不是 /var/www/uvdesk/。

完成后按 Ctrl + X 并在提示时输入 Y 以保存文件。

打开文件 /etc/nginx/nginx.conf 进行编辑。

$ sudo nano /etc/nginx/nginx.conf

在 include /etc/nginx/conf.d/*.conf; 这一行之前添加以下行。

server_names_hash_bucket_size  64;

按 Ctrl + X 并在提示时输入 Y 以保存文件。

验证 Nginx 配置文件的语法。

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

启动 Nginx 服务。

$ sudo systemctl start nginx

第 9 步 - 安装 UVdesk

在浏览器中打开 URL https://uvdesk.example.com,你将看到以下界面。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

点击 Let's Begin 按钮开始安装过程。安装程序将在下一页检查 PHP 设置和文件权限。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

点击 Proceed 继续。下一页将要求你填写数据库详细信息。按照第 4 步中的配置输入数据。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

点击 Proceed 继续。接下来,系统会要求你创建一个超级管理员账户。填写你的信息。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

点击 Proceed 继续。接下来,系统会要求你通过为 Member 和 Customer Panel 前缀命名来配置网站。这些前缀会用在网站 URL 中。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

点击 Proceed 继续。你将进入最终安装页面。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

点击 Install Now 开始安装。完成后,你将看到以下界面。

在 Rocky Linux 8 上安装部署 UVdesk 工单系统完整教程

你可以通过给出的链接访问管理后台和前端网站。你的 UVDesk 安装已可以使用。

结论

你已经使用 Nginx、MySQL 和 PHP 在基于 Rocky Linux 8 的服务器上安装了 UVdesk Helpdesk 系统。如果有任何问题,请在下方评论中留言。