本页内容
- 先决条件
- 第 1 步 - 配置防火墙
- 第 2 步 - 安装 Nginx
- 第 3 步 - 安装 MySQL
- 第 4 步 - 配置 MySQL
- 第 5 步 - 安装 PHP 及其扩展
- 第 6 步 - 安装 SSL
- 第 7 步 - 下载 OpenEMR
- 第 8 步 - 配置 SELinux
- 第 8 步 - 配置 PHP-FPM
- 第 9 步 - 配置 Nginx
- 第 10 步 - 安装 OpenEMR
- 总结
OpenEMR 是一款开源的电子健康档案(EHR)与医疗诊所管理工具。它通过了美国卫生信息技术协调办公室(ONC)认证,具备集成健康档案、诊所管理、排程、电子账单、国际化、免费支持等功能。它可以记录患者人口统计信息、为患者排程、维护包含化验报告、用药和医疗程序的详尽健康档案、跟踪处方、协助医疗账单处理、生成详细报告,并支持多语言。
在本教程中,你将学习如何在运行 Rocky Linux 9 的服务器上安装 OpenEMR 软件。
先决条件
- 一台运行 Rocky Linux 9 的服务器。
- 一个非 root 的 sudo 用户。
- 一个完全限定域名(FQDN),例如 openemr.example.com。
- 确保所有软件包均已更新。$ sudo dnf update
- 系统需要以下几个软件包。$ sudo dnf install wget curl nano unzip yum-utils policycoreutils-python-utils -y 其中部分软件包可能已安装在你的系统中。
一台运行 Rocky Linux 9 的服务器。
一个非 root 的 sudo 用户。
一个完全限定域名(FQDN),例如 openemr.example.com。
确保所有软件包均已更新。
$ sudo dnf update
系统需要以下几个软件包。
$ sudo dnf install wget curl nano unzip yum-utils policycoreutils-python-utils -y
其中部分软件包可能已安装在你的系统中。
第 1 步 - 配置防火墙
第一步是配置防火墙。Rocky Linux 使用 Firewalld 防火墙。请检查防火墙的状态。
$ sudo firewall-cmd --state
running
防火墙通过不同的区域(zone)工作,public 区域是我们将使用的默认区域。列出防火墙当前激活的所有服务和端口。
$ sudo firewall-cmd --permanent --list-services
它应显示如下输出。
cockpit dhcpv6-client ssh
OpenEMR 需要 HTTP 和 HTTPS 端口才能正常工作。请将它们开放。
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
重新加载防火墙以使更改生效。
$ sudo firewall-cmd --reload
再次列出所有服务。
$ sudo firewall-cmd --permanent --list-services
你应该得到如下输出。
cockpit dhcpv6-client http https ssh
第 2 步 - 安装 Nginx
Rocky Linux 9 自带较旧版本的 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 -y nginx
验证安装。
$ nginx -v
nginx version: nginx/1.24.0
启用并启动 Nginx 服务器。
$ sudo systemctl enable nginx --now
检查服务器的状态。
$ sudo systemctl status nginx
? nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
Active: active (running) since Thu 2023-06-15 10:20:00 UTC; 1s ago
Docs: http://nginx.org/en/docs/
Process: 1411 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 1412 (nginx)
Tasks: 2 (limit: 5922)
Memory: 1.9M
CPU: 7ms
CGroup: /system.slice/nginx.service
??1412 "nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf"
??1413 "nginx: worker process"
第 3 步 - 安装 MySQL
Rocky Linux 9 自带最新版本的 MySQL。你可以用一条命令安装它。
$ sudo dnf install mysql-server
检查 MySQL 的版本。
$ mysql --version
mysql Ver 8.0.32 for Linux on x86_64 (Source distribution)
启用并启动 MySQL 服务。
$ sudo systemctl enable mysqld --now
运行 MySQL 安全安装脚本。
$ sudo mysql_secure_installation
系统会询问你是否安装密码验证组件(Validate Password Component),它会检查 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 密码。请根据上面指定的要求输入密码。当提示继续使用该 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 以删除匿名用户、禁止 root 远程登录、删除测试数据库并重新加载权限表。
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
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!
第 4 步 - 配置 MySQL
登录到 MySQL 命令行。在提示时输入你的 root 密码。
$ sudo mysql -u root -p
创建一个示例数据库。
mysql> CREATE DATABASE openemr;
创建一个 SQL 用户账户。
mysql> CREATE USER 'openemruser'@'localhost' IDENTIFIED BY 'Your_password2';
将该数据库的所有权限授予该用户。
mysql> GRANT ALL PRIVILEGES ON openemr.* TO 'openemruser'@'localhost';
刷新用户权限。
mysql> FLUSH PRIVILEGES;
退出命令行。
mysql> exit
第 5 步 - 安装 PHP 及其扩展
我们需要安装 PHP 8.2 才能使 OpenEMR 正常工作。第一步是获取 Epel 仓库。
$ sudo dnf install epel-release -y
接下来,安装 Remi 仓库。
$ sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
检查可用的 PHP 版本流(stream)。
$ dnf module list php -y
Name Stream Profiles Summary
php 8.1 common [d], devel, minimal PHP scripting language
Remi's Modular repository for Enterprise Linux 9 - x86_64
Name Stream Profiles Summary
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
php remi-8.2 common [d], devel, minimal PHP scripting language
Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
默认版本是 8.1。请启用 Remi 的 PHP 8.2 仓库。
$ sudo dnf module reset php -y
$ sudo dnf module enable php:remi-8.2
安装 PHP 以及 OpenEMR 所需的扩展。
$ sudo dnf install php-fpm php-mysql php-bcmath php-xml php-zip php-curl php-mbstring php-gd php-tidy php-intl php-cli php-soap ImageMagick php-ldap
安装 TIFF Tools 库。该库在基础仓库中不可用,但可以在 CRB(原 Powertools)仓库中找到。
$ sudo dnf install libtiff-tools --enablerepo=crb
验证安装。
$ php --version
PHP 8.2.7 (cli) (built: Jun 6 2023 21:28:56) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.7, Copyright (c) Zend Technologies
启用并启动 PHP-FPM 服务。
$ sudo systemctl enable php-fpm --now
第 6 步 - 安装 SSL
我们需要安装 Certbot 来生成 SSL 证书。为此我们将使用 Snapd 软件包安装器。由于 Rocky Linux 没有自带它,请安装 Snapd 安装器。它需要 EPEL 仓库才能工作,而我们在前面为 PHP 已经安装过,因此可以跳过该步骤。
安装 Snapd。
$ sudo dnf install -y snapd
启用并启动 Snap 服务。
$ sudo systemctl enable snapd --now
安装 Snap core 软件包,并确保你的 Snapd 版本是最新的。
$ sudo snap install core && sudo snap refresh core
为 Snapd 创建必要的链接以使其正常工作。
$ sudo ln -s /var/lib/snapd/snap /snap
$ echo 'export PATH=$PATH:/var/lib/snapd/snap/bin' | sudo tee -a /etc/profile.d/snapd.sh
执行以下命令以安装 Certbot。
$ sudo snap install --classic certbot
使用以下命令,通过创建指向 /usr/bin 目录的符号链接,确保可以运行 Certbot 命令。
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
验证安装。
$ certbot --version
certbot 2.6.0
运行以下命令以生成 SSL 证书。
$ sudo certbot certonly --nginx --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m
[email protected]
-d openemr.example.com
上述命令会将证书下载到服务器上的 /etc/letsencrypt/live/openemr.example.com 目录。
生成 Diffie-Hellman 组证书。
$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
检查 Certbot 续期调度服务。
$ sudo systemctl list-timers
你会发现 snap.certbot.renew.service 是被调度运行的服务之一。
NEXT LEFT LAST PASSED UNIT ACTIVATES
-----------------------------------------------------------------------------------------------------------------------------------------
Thu 2023-06-15 12:29:25 UTC 54min left Thu 2023-06-15 11:18:44 UTC 16min ago dnf-makecache.timer dnf-makecache.service
Thu 2023-06-15 12:51:00 UTC 1h 15min left - - snap.certbot.renew.timer snap.certbot.renew.service
对该过程进行一次空运行(dry run),以检查 SSL 续期是否正常工作。
$ sudo certbot renew --dry-run
如果没有看到任何错误,说明一切就绪。你的证书将自动续期。
第 7 步 - 下载 OpenEMR
访问 OpenEMR 下载页面,获取最新版本 OpenEMR 的链接。将 OpenEMR 下载到服务器。
$ wget https://sourceforge.net/projects/openemr/files/OpenEMR%20Current/7.0.1/openemr-7.0.1.tar.gz
解压文件。
$ tar -pxzf openemr-7.0.1.tar.gz
将解压后的文件移动到 Web 根目录。
$ sudo mv openemr-7.0.1 /var/www/html/openemr
将 Web 根目录的权限赋予 Nginx 用户。
$ sudo chown -R nginx:nginx /var/www/html/openemr
第 8 步 - 配置 SELinux
更改 OpenEMR 的文件安全上下文。
$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/openemr(/.*)?"
应用该策略。
$ sudo restorecon -Rv /var/www/html/openemr/
应用策略以允许 Nginx 访问 MySQL。
$ sudo setsebool -P httpd_can_network_connect_db 1
应用策略以允许连接到外部主机。发送邮件需要此设置。
$ sudo setsebool -P httpd_can_network_connect 1
第 8 步 - 配置 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
...
在文件中找到 ;listen.owner = nobody、;listen.group = nobody 和 ;listen.mode=0660 这几行,并按如下方式修改它们。
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
接下来,如下所示在该行前面加上分号将其注释掉。
;listen.acl_users = apache,nginx
按 Ctrl + X 保存文件,并在提示时输入 Y。
将 PHP-FPM 和 PHP-CLI 的执行时间增加到 60 秒。
$ sudo sed -i 's/max_execution_time = 30/max_execution_time = 60/' /etc/php.ini
将变量 max_input_time 的值设置为 1。
$ sudo sed -i 's/max_input_time = 60/max_input_time = -1/' /etc/php.ini
将 PHP-FPM 的内存限制从 128MB 提高到 512MB。
$ sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/' /etc/php.ini
将文件上传大小提高到 30MB。
$ sudo sed -i 's/post_max_size = 8M/post_max_size = 30M/' /etc/php.ini
$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 30M/' /etc/php.ini
将最大输入变量数提高到 3000。
$ sudo sed -i 's/;max_input_vars = 1000/max_input_vars = 3000/g' /etc/php.ini
允许从 PHP 的角度,通过 LOAD DATA 语句访问本地文件。
$ sudo sed -i 's/;mysqli.allow_local_infile = On/mysqli.allow_local_infile = On/g' /etc/php.ini
重启 PHP-FPM 服务。
$ sudo systemctl restart php-fpm
将 PHP 会话目录的所属组更改为 Nginx。
$ sudo chgrp -R nginx /var/lib/php/session
第 9 步 - 配置 Nginx
创建并打开文件 /etc/nginx/conf.d/openemr.conf 进行编辑。
$ sudo nano /etc/nginx/conf.d/openemr.conf
在其中粘贴以下代码。
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name openemr.example.com;
access_log /var/log/nginx/openemr.access.log;
error_log /var/log/nginx/openemr.error.log;
# SSL
ssl_certificate /etc/letsencrypt/live/openemr.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/openemr.example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/openemr.example.com/chain.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
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;
# use https://blog.cloudflare.com/announcing-1111 Cloudfare+Apnic labs, It is free and secure
resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] valid=300s;
root /var/www/html/openemr;
index index.php;
location / {
try_files $uri $uri/ /index.php;
}
# Pass PHP Scripts To FastCGI Server
location ~* \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass unix:/run/php-fpm/www.sock; # Depends On The PHP Version
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
include fastcgi_params;
}
# deny access to writable files/directories
location ~* ^/sites/*/(documents|edi|era) {
deny all;
return 404;
}
# deny access to certain directories
location ~* ^/(contrib|tests) {
deny all;
return 404;
}
# Alternatively all access to these files can be denied
location ~* ^/(admin|setup|acl_setup|acl_upgrade|sl_convert|sql_upgrade|gacl/setup|ippf_upgrade|sql_patch)\.php {
deny all;
return 404;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
}
# enforce HTTPS
server {
listen 80;
listen [::]:80;
server_name openemr.example.com;
return 301 https://$host$request_uri;
}
请注意,Nginx 配置中将使用的根目录为 /var/www/html/openemr。
完成后按 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 restart nginx
第 10 步 - 安装 OpenEMR
在浏览器中打开 URL https://openemr.example.com,你将看到如下设置界面。

此处会检查文件权限,并确认你是否可以进入第 1 步。如果你看到绿色的 ready 字样,说明可以继续。点击蓝色按钮进入第 1 步。

在下一页,系统会询问你希望由安装程序创建数据库还是使用已创建的数据库。选择「I have already created the database(我已创建数据库)」选项,然后点击按钮进入第 2 步。

在下一页,填写你在第 4 步中配置的数据库凭据。同时输入你的管理员账户凭据。请确保用户名长度为 12 个或更多字符,否则会报错。你可以在此处启用双因素认证(2FA),但建议在安装完成后再进行配置。点击按钮创建数据库和用户账户。

下一页将显示安装状态,并给出用户名和密码。点击按钮进入第 4 步。

下一页会列出 php.ini 文件中的推荐值和当前值。请确保当前值满足要求。出于某种原因,即使你已经正确设置,安装程序对变量 max_execution_time 也会显示错误的值。你可以忽略它。你可以使用以下命令验证当前值。

确认无误后,点击按钮进入第 5 步。

下一步列出了 Apache 服务器的设置,由于我们使用的是 Nginx 服务器,因此忽略它。点击按钮进入下一页。

此处系统会要求你为管理面板选择主题。选择「Keep Current(保持当前)」选项并点击按钮继续。你可以稍后从管理面板更改主题,但那样你将无法预览它们的外观。如果你在安装程序页面中选择,则可以在选定前先查看外观效果。我们将保持默认主题不变。

最后一页列出了一些关于软件和账户凭据的结束语。点击 Start 按钮打开登录页面。

你将看到一个 OpenEMR 注册弹窗,用于接收其站点的公告。你可以忽略它,直接输入凭据并点击 Login 按钮进入仪表盘。

如果你在安装过程中没有配置双因素认证,请点击右上角的头像图标并选择 MFA Management 选项来进行配置。

在下一页,从下拉菜单中选择认证方式并开始配置。

从此处起,你就可以开始使用 OpenEMR 来管理你的医疗业务了。
总结
至此,关于在 Rocky Linux 9 服务器上安装 OpenEMR 的教程就结束了。如果你有任何问题,请在下方评论中留言。