如何在 Rocky Linux 9 上安装 OpenEMR
OpenEMR 是一种开源电子健康记录和医疗实践管理工具。它经过国家卫生信息技术协调员办公室 (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
其中一些软件包可能已经安装在您的系统上。
第 1 步 - 配置防火墙
第一步是配置防火墙。 Rocky Linux 使用 Firewalld 防火墙。检查防火墙的状态。
$ sudo firewall-cmd --state
running
防火墙适用于不同的区域,公共区域是我们将使用的默认区域。列出防火墙上所有活动的服务和端口。
$ 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
系统将要求您安装验证密码组件。它检查 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 shell。出现提示时输入您的 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 流。
$ 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 工具库。该库无法从基础存储库中获得,但可以在 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 安装程序。它需要我们之前为 PHP 安装的 EPEL 存储库才能工作,因此我们可以跳过此步骤。
安装快照。
$ sudo dnf install -y snapd
启用并启动 Snap 服务。
$ sudo systemctl enable snapd --now
安装 Snap 核心包,并确保您的 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 -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
对该过程进行一次演练,以检查 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
授予 Nginx 用户对 Web 根目录的权限。
$ 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 =body
、;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。
在下一页上,系统将询问您是否希望安装程序创建数据库或使用预制数据库。选择选项我已经创建了数据库,然后单击按钮继续执行步骤 2。
在下一页上,填写您之前在步骤 4 中配置的数据库凭据。另外,输入您的管理员帐户凭据。确保您的用户名长度为 12 个或更多字符,否则您将收到错误消息。您可以在此处启用双因素身份验证 (2FA),但建议在安装后稍后进行配置。单击按钮创建数据库和用户帐户。
下一页将显示安装状态并显示用户名和密码。单击该按钮继续执行步骤 4。
下一页将列出 php.ini 文件中的建议值和当前值。确保当前值满足要求。由于某种原因,安装程序会显示变量 max_execution_time
的错误值,即使您已正确设置它也是如此。你可以忽略这一点。您可以使用以下命令验证当前值。
一旦您满意,请单击按钮继续执行步骤 5。
下一步列出了 Apache 服务器设置,由于我们使用的是 Nginx 服务器,因此我们将忽略这些设置。单击按钮进入下一页。
在这里,您将被要求为管理面板选择一个主题。选择保持当前选项,然后单击按钮继续。您可以稍后从管理面板更改主题,但您将无法看到它们的外观。如果您从安装程序页面进行选择,您还可以在选择之前检查它们的外观。我们将坚持使用默认主题。
最后一页列出了有关软件和帐户凭据的一些最终说明。单击开始按钮打开登录页面。
您将看到一个 OpenEMR 注册弹出窗口,以从其网站获取公告。您可以忽略并输入您的凭据,然后单击登录按钮访问仪表板。
如果您在安装过程中未配置双因素身份验证,请单击右上角的头像图标并选择MFA 管理选项来配置。
在下一页上,从下拉菜单中选择身份验证方法并开始配置。
您可以从现在开始使用 OpenEMR 来管理您的健康业务。
结论
关于在 Rocky Linux 9 服务器上安装 OpenEMR 的教程到此结束。如果您有任何疑问,请在下面的评论中发表。