
Setting up OpenEMR on an Ubuntu 24.04 Server requires careful steps to ensure a smooth and secure installation. This guide walks you through the process, covering dependencies, configuration, and initial setup.
First, it is crucial to update your system to ensure you have the latest packages and security patches. Open your terminal and run:
sudo apt update
sudo apt upgrade -y
Next, you need a LAMP (Linux, Apache, MariaDB, PHP) stack. OpenEMR relies on these components to function. Install them by executing:
sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql php-curl php-xml php-gd php-imagick php-mbstring php-intl php-zip php-common php-soap -y
Secure your MariaDB installation after it’s installed. Run the security script:
sudo mysqlsecureinstallation
Follow the prompts. It’s recommended to set a root password, remove anonymous users, disallow remote root login, and remove the test database.
Now, create a database and a user for OpenEMR in MariaDB. Log in as the root user:
sudo mysql -u root -p
Enter the root password you just set. Inside the MariaDB shell, run these commands. Remember to replace yourdbname, yourdbuser, and yourpassword with your desired values:
CREATE DATABASE yourdbname;
CREATE USER ‘yourdbuser’@’localhost’ IDENTIFIED BY ‘yourpassword’;
GRANT ALL PRIVILEGES ON yourdbname.* TO ‘yourdbuser’@’localhost’;
FLUSH PRIVILEGES;
EXIT;
Download the latest stable version of OpenEMR. You can usually find the download link on the official OpenEMR website. Use wget to download it to a temporary directory like /tmp.
cd /tmp
wget https://www.open-emr.org/sourceforge/703/openemr-7.0.3.zip (Note: Replace with the actual latest version URL)
Extract the downloaded archive. We will extract it to the default Apache web directory, /var/www/html.
sudo unzip openemr-7.0.3.zip -d /var/www/html/ (Note: Adjust filename if needed)
This will likely create a directory like /var/www/html/openemr-7.0.3. It’s good practice to rename it to something simpler, like openemr:
sudo mv /var/www/html/openemr-7.0.3 /var/www/html/openemr
Set the correct permissions for the OpenEMR directory so the web server can write to necessary files. The web server user is typically www-data on Ubuntu.
sudo chown -R www-data:www-data /var/www/html/openemr
sudo chmod -R 755 /var/www/html/openemr
Some specific directories within openemr might need more relaxed permissions during installation, like documents, gacl, library, sites, and secure. Set write permissions for the web server user on these:
sudo chmod -R 775 /var/www/html/openemr/documents
sudo chmod -R 775 /var/www/html/openemr/gacl
sudo chmod -R 775 /var/www/html/openemr/library
sudo chmod -R 775 /var/www/html/openemr/sites
sudo chmod -R 775 /var/www/html/openemr/secure
Configure Apache to serve OpenEMR. You can either configure the default site or create a new virtual host. For a simple setup where OpenEMR is the primary site, edit the default configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Change the DocumentRoot
line to point to the OpenEMR directory:
DocumentRoot /var/www/html/openemr
Save and close the file (Ctrl+X, Y, Enter).
Enable the Apache rewrite module, which is required by OpenEMR:
sudo a2enmod rewrite
Restart Apache for the changes to take effect:
sudo systemctl restart apache2
Adjust PHP settings to meet OpenEMR’s requirements. Edit the main PHP configuration file for Apache:
sudo nano /etc/php/8.3/apache2/php.ini (Note: PHP version might differ)
Look for the following directives and ensure they meet or exceed these values:
memorylimit = 256M
uploadmaxfilesize = 64M
postmaxsize = 64M
maxexecutiontime = 60
maxinput_time = 60
date.timezone = Your/Timezone (e.g., date.timezone = America/New_York
. Find your timezone string on the PHP manual website.)
Save and close the file. Restart Apache again after changing php.ini:
sudo systemctl restart apache2
Now, proceed with the web-based installation. Open a web browser and navigate to your server’s IP address or domain name. If you followed the default site configuration, simply enter:
http://yourserveripordomain/
You should see the OpenEMR setup page. Follow the instructions provided by the web installer. You will need the database credentials you created earlier (database name, user, and password). The installer will guide you through creating necessary tables and setting up initial administrative users.
After the web installation is complete, it is highly recommended to secure the setup.php
file to prevent unauthorized access to the installer:
sudo mv /var/www/html/openemr/setup.php /var/www/html/openemr/setup.php.bak (or simply delete it if preferred)
Finally, configure a cron job for OpenEMR to handle scheduled tasks like reminders and reports. Edit the crontab for the web server user:
sudo crontab -u www-data -e
Add the following line at the end of the file. This runs the cron script every 10 minutes:
/10 * * * * /usr/bin/php /var/www/html/openemr/library/aclupgradenrepair/aclcrons.php > /dev/null 2>&1**
Save and close the crontab. Your OpenEMR installation on Ubuntu 24.04 should now be complete and functional. Remember to keep your system and OpenEMR updated for security and new features.
Source: https://www.howtoforge.com/how-to-install-openemr-on-ubuntu-24-04-server/