OpenEMR on OS X How-To

fred0 wrote on Sunday, February 26, 2006:

OpenEMR install on OS X 10.4.5

Last summer, the cobbled together office management software that we had been using to run our clinic finally started to break down and I began searching for a solution. Everything was way too expensive for a small clinic such as we had and I finally came across OpenEMR. The old system was a bunch of Windows machines I had built myself (per the requirements of the software at the time). I desperately wanted to trash them and move the office to Mac OS X to get away from blue screens and the hundreds of viruses and spyware I would find every couple of weeks (plus, I have been a Mac system admin for over a decade).
I bought a Mac Mini and decided to give it a shot. It worked, but only after I spent about a week trying to figure it out. I slowly pieced together from various sources all the bits of installation and troubleshooting tips and got it running. I have since made some mods to the hcfa form to match our Xerox printer better, but other than that it was pretty much a standard install.
Today, I am preparing to upgrade from the install from last year to the 2.8.1 release and decided to refresh myself by doing it from scratch on a test machine and documenting the process this time. So, here, for anyone interested in running OpenEMR on the BEST and most friendly commercial unix platform out there, I present complete instructions.

First, download the parts you need.

From here at sourceforge:
openemr-2.8.1
freeb-0.11

From mysql.com
mysql 4.1.18 (standard)
There is a 64-bit version as well. This is for G5 systems.
I haven’t tested it, but from everything I read, v5 it doesn’t work well with openemr.
It’s not too obvious how to find older versions, so, this is the url (as of today);
http://dev.mysql.com/downloads/mysql/4.1.html

The package from mysql.com is a set of binary installers that run from the OS X gui.
Just double click on the icons for each of the 3 parts to install them. When you double click on the pref pane item, choose install for all users. That way, if you have multiple accounts, you can get to the pref pane from all of them.

From here on out, I am working as root on the command line. I am going to assume that you already know how to work on the command line. You can either enable the root user (it’s not by default on OS X for security reasons) through the NetInfo Manager app found in the Utilities folder in side Applications, or just preface every unix command below with sudo. I suggest making your life easier and enabling root. Just disable it when you’re done.

Unzip and untar openemr, and place it in /Library/WebServer/Documents
gunzip openemr-2.8.1.tar.gz
tar –xvf openemr-2.8.1.tar
mv openemr-2.8.1 /Library/WebServer/Documents/

Rename it from openemr-2.8.1 (or whatever) to just “openemr”
/Library/WebServer/Documents/
mv /Library/WebServer/Documents/
openemr-2.8.1 /Library/WebServer/Documents/
openemr

Set some permissions that are wrong:
chown –R root.admin /Library/WebServer/Documents/openemr

chmod –R 777 /Library/WebServer/Documents/openemr/interface/main/calendar/modules/PostCalendar/pntemplates/cache

chmod –R 777 /Library/WebServer/Documents/openemr/interface/main/calendar/modules/PostCalendar/pntemplates/compiled

Edit /etc/httpd/httpd.conf using your fav editor (I use pico ‘cause it’s easy so: pico /etc/httpd/httpd.conf) and uncomment these lines (probably don’t need perl, but what the heck):
LoadModule perl_module        libexec/httpd/libperl.so
LoadModule php4_module        libexec/httpd/libphp4.so

and

AddModule mod_php4.c
AddModule mod_perl.c

Edit the globals.php file to define the server root:
pico /Library/WebServer/Documents/openemr/interface/ globals.php

change line 10 from:
$webserver_root = "/var/www/html/openemr";
to
$webserver_root = "/Library/WebServer/Documents/openemr";

Optional globals (there are more, you should go through and read the file):
1. The default timeout to automatically logout idle users is 60 minutes. To change this, on about line 87 in the globals.php file, change the value from 3600 (expressed in seconds) to some thing larger. I used 7200 to make it 120 minutes.

2. You can define the time of day to start and end your schedule. The defaults are 8am-5pm. You can change these on about lines 109/110.

3. You can define the time intervals for your schedule on the lines just below the time of day stuff.

Finally, 10.4.4 changed the location of mysql.sock from the one openemr needs so:
mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Now, we’ll install the billing system.

I cribbed some of this from: http://www.oemr.org/modules/wiwimod/index.php?page=FreebInstall&back=WiwiHome

First, install Xcode Tools from Tiger DVD. This provides all the developer stuff you will need to compile from source.

Unzip and untar freeb
gunzip freeb-0.11.tar.gz
tar –xvf freeb-0.11.tar

Rename it from freeb-0.11 (or whatever) to freeb
mv freeb-0.11 freeb

Move the freeb directory to /usr/share
mv freeb /usr/share

Set permissions
chmod –R root.wheel /usr/share/freeb

Download expat from http://sourceforge.net/projects/expat/
Untar it and compile:
gunzip expat-2.0.0.tar.gz
tar –xvf expat-2.0.0.tar
cd expat-2.0.0
./configure
make
make install

Next, run cpan, choose defaults for all questions by hitting enter until you get to the part which asks for your geographical location, when asked for a list of servers, choose several. I chose the first 9.)
When that’s done, you will get the cpan command prompt that looks like:
cpan>

While we’re here, we’ll upgrade cpan first (this part is not necessary so, you could skip it if you’re impatient). This will take a while and you should just accept the defaults hit enter anytime it asks you anything:
cpan> install Bundle::CPAN
cpan> reload cpan

Now install the modules for freeb, hit enter to accept defaults for any questions asked:
cpan> install XML::Parser
cpan> install HTML::Tagset
cpan> install HTTP::Daemon
cpan> install PDF::Create
cpan> install ConfigFile
cpan> install Date::Calc
cpan> quit

Test that you don’t get any errors with:
/usr/share/bin/ FreeB_Server.pl

It should simply return:
before server setup

Hit ctrl-c to cancel and get back to the command line.

Now, create startup daemon for freeb:
pico /Library/LaunchDaemons/com.freeb.Freeb.plist

paste this into the window and then ctrl-x to exit and save:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.freeb.Freeb</string>
        <key>OnDemand</key>
        <false/>
        <key>Program</key>
        <string>/usr/share/freeb/bin/FreeB_Server.pl</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/share/freeb/bin/FreeB_Server.pl</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>ServiceDescription</key>
        <string>Freeb Server</string>
        <key>UserName</key>
        <string>root</string>
        <key>WorkingDirectory</key>
        <string>/usr/share/freeb</string>
</dict>
</plist>

Now set permissions on the daemon:
chown admin.staff /Library/LaunchDaemons/com.freeb.Freeb.plist
chmod 666 /Library/LaunchDaemons/com.freeb.Freeb.plist

Reboot and freeb is started automagically.

In order to print claims, you will need to edit the config.php file

pico /Library/WebServer/Documents/openemr/includes/config.php

and add your printer name in place of where it says “HP_LaserJet4L”.
This is tricky because you need the unix name for the printer. You can find it by opening http://127.0.0.1:631 and then clicking on Manage Printers. The unix name will be the one at the far left of the title bar. Alternately, open the Printer Setup Utility, highlight your printer and click Show Info. Under the section called Queue Name is the proper unix name you need.

Now, to simplify processing of bills, I created a little program to trigger the process_bills.php action by simply clicking on it. That way, my users don’t have to muck around on the command line. Using Apple’s Automator program, I added the Run Shell Script action with the following command:

php -q /Library/WebServer/Documents/openemr/library/freeb/process_bills.php bill

and then saved it as an Application and named it Process Bills.

That’s it!

fred0 wrote on Sunday, February 26, 2006:

Minor fix. The line breaks on the rename openemr section in my first post got borked so:

Rename it from openemr-2.8.1 (or whatever) to just “openemr”:
mv /Library/WebServer/Documents/ openemr-2.8.1 /Library/WebServer/Documents/openemr

drbowen wrote on Sunday, February 26, 2006:

Thanks Fred0!

I would like to add this to our collection of howtos at oemr.org.

This looks like a straight forward install of OpenEMR that is identical to how I do things in Slackware.  The main differences being the path differences and the owner of the Apache process (root.admin) and later (admin.staff) for the freeB process.

I am curious,  did you have to do anything to OS X to get the MySQL 4.1.18 or the PHP 4+ to work in OS X.  There had been earlier posts in these forums about users having MySQL installation issues with the 4+ series.  I was wandering whether this was a speciific OS X issue or an individual installation issue with that particular user.

I had seen other forums, unrelated to OpenEMR, that had this happen in certain releases of OS X. IE  sometimes the specific collection of packages released with subversions of OS X would break the MySQL thereby causing permission problems when trying to install OpenEMR.

Thanks,

Sam Bowen

drbowen wrote on Sunday, February 26, 2006:

I found the thread (it came in on my private e-mail) and am posting it here:

How can I get help on installing openemr on OS X (10.4.4)?  I believe that I have followed the install Instructions carefully.  However, when I get to Step 3 the setup program fails and gives the following message:

OpenEMR Setup

Step 3

Connecting to MySQL Server…
Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2) in /Library/WebServer/Documents/openemr/setup.php on line 159
ERROR. Check your login credentials.
Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2) (#2002)
__________________________________________

My First response:

Warning: mysql_connect(): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’ (2)

This is an error message that usually is generated by MySQL and is not related to OpenEMR per se. It likely means that the MySQL server is not running.

Check that MySQL has been installed correctly and that the server has actually been started.

On a command prompt you shoulde be able to connect with

shell#  mysql  -u  root  -p

This will work only if the user root password has already been set.

If you have not set the MySQL root password, running:

shell#  mysql -u root

Should result in you connecting to the MySQL command interpreter it should look like this:

mysql>

The OpenEMR setup routine won’t work if you can’t connect like this.

______________________________________

WOW!  Thanks very much for the quick reply!!.

I had already tried your suggestion and it appears that mysql is up and running (see below).  It appears to me that somewhere in the mysql_connect software, it what’s to connect to a mysql UNIX socket located in ‘/var/mysql/mysql.sock’.  However, you can see that mysql thinks that the socket is located in ‘/tmp/mysql.sock’ (see “UNIX socket” line below).  To do not now how to reconcile  this difference!!  Any suggestions??

Again, thanks very much for your quick reply.

Peter Cartwright

root# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 17 to server version: 4.1.10

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> status
--------------
mysql  Ver 14.7 Distrib 4.1.10, for apple-darwin8.1.0 (powerpc)

Connection id:          17
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ‘’
Using delimiter:        ;
Server version:         4.1.10
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:            /tmp/mysql.sock
Uptime:                 9 hours 9 min 45 sec

Threads: 1  Questions: 21  Slow queries: 0  Opens: 12  Flush tables: 1  Open tables: 1  Queries per second avg: 0.001
--------------

mysql> exit
Bye

_______________________________________________

The proposed solution:

There is a thread that others have had this problem with certain verssons of OS X.  Look at :

http://www.macosxhints.com/article.php?story=20060111113313511&lsrc=osxh

The suggested fix is:

$ sudo mkdir /var/mysql
$ sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

But take a look at the whole thread.

____________________________________________

I take it from your desciption above the OS X version 10.4.5 has fixed the problem and it just didn’t occur for you?

Thanks again,

Sam Bowen

fred0 wrote on Sunday, February 26, 2006:

Sam,

First, you’re welcome. Please do add this to the collection of how-tos, just make sure to fix the one section that got messedup and I corrected in my 2nd post.
Second, you are correct that 10.4.4 messes up the mysql.sock location. 10.4.5 does not corrrect this. If you look right in the middle of my instructions (just after optional globals), you’ll find the step that fixes mysql which is exactly the suggestion from macosxhints.com that you posted. I know that that thread had several possible solutions, but the one that worked is the one I included. In fact, since this is only for 10.4.4 and up, you might want to note that at that step. On 10.4.3 and below, that step is not required.

When I did my original install last year, I had tried various other systems and had done many odd things to get stuff working. Most of it I knew was likely unnecessary so, that is why I did the install from scratch yesterday on a clean machine.

fred0 wrote on Sunday, February 26, 2006:

Oh, one other MAJOR thing to note here:

If you already have OpenEMR and mysql installed and running and you run an OS X mysql binary updater, it wipes out your data folder. I discovered this (and lost a day’s worth of data… thankfully, I had just implemented a daily backup solution the week before) while trying to fix the mysql.sock error on the office machine when we did the 10.4.4 update a couple weeks ago. So, before running the mysql updater (on a previous install of mysql, not a new install) make sure to back up your data first. The easiest way to do this is with tar. So, from the system preferences, choose your mysql pane and stop the server.
Then, as root:
cd /usr/local/mysql
tar -cvf databackup.tar data

Now you have a clone of the data folder. Run the updater binary and go back to the mysql directory. Make sure the server is still stopped from the pref pane again (in case the installer started it). Rather than deleting anything (far safety), just rename the new data folder and untar your original data:
cd /usr/local/mysql
mv data data.bak
tar -xvf databackup.tar

Then, restart your mysql server from the pref pane.

fred0 wrote on Sunday, February 26, 2006:

Arg…
In the freeb install section there is another error.

Where it says:
Set permissions
chmod –R root.wheel /usr/share/freeb

It should say:
Set permissions
chown –R root.wheel /usr/share/freeb

andres_paglayan wrote on Monday, February 27, 2006:

this process is already documented at
upgrade how to:
http://www.oemr.org/modules/cjaycontent/index.php?id=28
it’s written for 2.8.0 the only differnce is that you’ll need to run 2.8.0-to-2.8.1_upgrade.sql too.

drbowen wrote on Thursday, March 02, 2006:

Dear Fred0,

Please look at:

http://www.oemr.org/modules/wiwimod/index.php?page=InstallOs

and tell me if you approve.  I added some red ink for the back up section.  This is such an easy and dire error to make I thought this type of font was warranted.  I also fixed the other small problems.

A small moment of thoughtlessness could easily wipe out a very large database.

Sam Bowen, Md