How to install the OpenEMR medical software on Ubuntu Server

If you need server software for the medical practice you administer, look no further than the open source OpenEMR.

How to install the OpenEMR medical software on Ubuntu Server

Medical practices require a special kind of software in order to schedule patients, manage their records, and comply with standards. It should also be reliable and user-friendly.  

Software that offers all of the features required to help run a medical practice abound. In fact, there are plenty of proprietary solutions that meet these needs. But what about open source solutions that you can get up and running on standard off-the-shelf hardware?

One such solution is OpenEMR, a medical practice software that includes patient demographics, scheduling, electronic medical records, prescriptions, billing, clinical decision rules, patient portal, reports, multi language support, security, and plenty of documentation.

The only caveat to OpenEMR is that it's not an easy installation. But fear not, any IT admin with a bit of Linux experience can get this up and runing. In fact, I'm going to walk you through the process of installing OpenEMR on Ubuntu Server 18.04

SEE: Hiring kit: Database administrator (TechRepublic Premium)

What you'll need

How to update and upgrade your server

Before you dive into the OpenEMR installation, it's always best to update and upgrade your server. One thing to remember is if the kernel is upgraded, you'll need to restart the computer for the updates to take effect.

To update and upgrade Ubuntu, log in to your system and issue the following two commands:

sudo apt-get update
sudo apt-get upgrade -y

Once those two commands complete, reboot the system (if required), and get ready to install OpenERM. 

How to install dependencies

The first thing to do after the upgrade is install the necessary dependencies. To do that, log in to your Ubuntu Server and issue the following command:

sudo apt-get install mysql-server php php-xml php-mbstring php-mysql apache2 wget -y

After the dependencies install, you need to configure the MySQL database server. Do this with the command:

sudo mysql_secure_installation

You'll be asked to set up the VALIDATE PASSWORD plugin, set an admin password, remove anonymous user, disallow root login remotely, remove test database and access to it, and reload privilege tables.

When asked, answer Y for all of the questions.  

Next we need to create a database. Log in to the MySQL prompt with the command:

sudo mysql -u root -p

Enter the password you created for the MySQL admin user. At the MySQL prompt, create the database with the command:


Next, create a user and give the user permission to use the new database with the command:

CREATE USER 'openemruser'@'localhost' IDENTIFIED BY 'PASSWORD';

Where PASSWORD is a strong/unique password.

Note: Thanks to TechRepublic reader, Mohammad Alsharabi, for pointing out that, when installing OpenEMR on Ubuntu 19.04 (with MySQL 8), the CREATE USER command would be:

CREATE USER 'openemruser'@'localhost' IDENTIFIED WITH mysql_native_password BY 'PASSWORD';

Where PASSWORD is a strong, unique password.

Next, grant the user permission to access the new database with the command:

GRANT ALL PRIVILEGES ON openemr.* TO 'openemruser'@'localhost';

Finalize this with the commands:


How to configure the PHP for OpenEMR

It is also necessary to configure PHP properly for OpenEMR. To do this, issue the command:

sudo nano /etc/php/7.2/apache2/php.ini

In that file, you'll want to change the following PHP options:

short_open_tag = Off
max_execution_time = 60
max_input_time = -1
max_input_vars = 3000
memory_limit = 512M
display_errors = Off
log_errors = On
post_max_size = 30M
file_uploads = On
upload_max_filesize = 30M
error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT
mysqli.allow_local_infile = On

Once you've taken care of that, save and close the file.

How to download and unpack OpenEMR

Next we need to download and unpack the necessary file for OpenEMR. To do this, issue the command:


When the file download completes, unpack it with the command:

tar xvzf openemr*.tar.gz

You should now have a new directory named openemr-5.0.2.

Relocating and ownership

The next step is to relocate and rename the openemr-5.0.2 directory and give it the necessary permissions. First, rename the directory with the command:

mv openemr-5.0.2 openemr

Now you can move the directory with the command:

sudo mv openemr /var/www/html/

With the directory in place, give it the proper ownership with the command:

sudo chown -R www-data:www-data /var/www/html/openemr

There's also one particular file that requires a specific permission. Take care of this step with the command:

sudo chmod 666 /var/www/html/openemr/sites/default/sqlconf.php

How to install OpenEMR

We've taken care of the preflight steps, now it's time to install OpenEMR. Open a web browser and point it to http://SERVER_IP/openemr (where SERVER_IP is the IP address of the Ubuntu server). You should be greeted by the first screen of the installation (Figure A).

Figure A


We're prepared for installation.

Click Next to continue. In the resulting window (Figure B), make sure to check I Have Already Created The Database and then click Next.

Figure B


You've already created the database.

Click Proceed To Step 2. 

In the resulting window (Figure C) fill out the necessary information. Here's how:

  • Server Host: localhost

  • Server Port: 3306

  • Database Name: openemr

  • Login Name: openemr

  • Password: Password you created for the openemr database user

  • Initial User Login Name: New username but must be no less than 12 characters

  • Initial User Password: A new password for the initial user login

  • Initial User's First Name: Your first name

  • Initial User's Last Name: Your last name

  • Initial Group: Default

Figure C


Configuring the database for OpenEMR

Once you've filled out that information, click Create DB And User. In the next window (Figure D), click Proceed To Step 4. 

Figure D


Everything checks out.

In the resulting window (Figure E), click Proceed To Step 5.

Figure E


The next step will configure Access Controls and PHP.

Since we've already taken care of the PHP configuration, click Proceed To Step 6 (Figure F).

Figure F


PHP is taken care of.

The next window (Figure G) will display the contents you need to paste in the Apache configuration file for OpenEMR. Create that new file with the command:

sudo nano /etc/apache2/sites-available/openemr.conf

Past the following contents into that new file:

<Directory "/var/www/html/openemr">
      AllowOverride FileInfo
      Require all granted
  <Directory "/var/www/html/openemr/sites">
      AllowOverride None
  <Directory "/var/www/html/openemr/sites/*/documents">
      Require all denied

Save and close the file. 

Figure G


The Apache configuration file information.

You then need to enable the site with the command:

sudo a2ensite openemr

Finally, reload the Apache config files with the command:

sudo systemctl reload apache2

Once you've taken care that click Proceed To Select A Theme. In the resulting window (Figure H) either keep the current theme or click Show More Themes. 

Figure H


Selecting your theme.

Once you've selected a theme, click Proceed To Final Step.

The final screen will display your login information and give you a link to click that takes you to the login screen. You'll be shown a registration pop-up. You can either take the time to register, or not. Either way, you'll be given the login screen where you can log in with the user credentials you created during the installation.

Congratulations, you've installed your own medical software that can help you run your own practice from within your on-premises data center. 

Also see

Professional programmer working at developing programming and website working in a software develop company office, writing codes and typing data code

Image: Getty Images/iStockphoto