2 //required for normal operation because of recent changes in PHP:
5 //turn off PHP compatibility warnings
6 ini_set("session.bug_compat_warn","off");
9 $dumpfile = "sql/database.sql";
10 $icd9 = "sql/icd9.sql";
11 $conffile = "library/sqlconf.php";
13 $defhost = 'localhost';
14 $state = $_POST["state"];
15 $gaclConfigFile1 = "gacl/gacl.ini.php";
16 $gaclConfigFile2 = "gacl/gacl.class.php";
17 $gaclWritableDirectory = "gacl/admin/templates_c";
18 $gaclSetupScript1 = "./gacl/setup.php";
19 $gaclSetupScript2 = "./acl_setup.php";
20 $requiredDirectory1 = "interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
21 $requiredDirectory2 = "interface/main/calendar/modules/PostCalendar/pntemplates/cache";
22 $writableFileList = array($conffile, $gaclConfigFile1, $gaclConfigFile2);
23 $writableDirList = array($gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
25 include_once($conffile);
29 <TITLE
>OpenEMR Setup Tool
</TITLE
>
30 <LINK REL
=STYLESHEET HREF
="interface/themes/style_blue.css">
34 <span
class="title">OpenEMR Setup
</span
>
39 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
40 echo "It appears that you have register_globals enabled in your php.ini\n" .
41 "configuration file. This causes unacceptable security risks. You must\n" .
42 "turn it off before continuing with installation.\n";
51 <p
>Congratulations
! OpenEMR is now successfully installed
.
54 <li
>Please Edit the
'interface/globals.php' file now to specify the correct
55 URL paths
, and to select a theme
.</li
>
56 <li
>Please restore secure permissions on the configuration files
: /openemr
/library
/sqlconf
.php
, /openemr
/gacl
/gacl
.ini
.php
, and /openemr
/gacl
/gacl
.class.php files
.</li
>
59 In order to take full advantage of the documents capability you
60 must give your web server permissions on the document storage
61 directory
. Try "chown apache:apache -R openemrwebroot/documents"
62 and then
"chmod g+w openemrwebroot/documents".
63 You must also make sure your PHP
installation (normally set in
64 your php
.ini file
) has
"file_uploads enabled", that
65 "upload_max_filesize" is appropriate
for your
use and that
66 "upload_tmp_dir" is set to a correct value
if the
default of
67 "/tmp" won
't work on your system.
70 Access controls (php-GACL) are installed for fine-grained security,
71 and can be administered in OpenEMR's admin
->acl menu
.
74 There
's much information and many extra tools bundled within the OpenEMR
75 installation directory. Please refer to openemr/Documentation.
76 <br>Many forms and other useful scripts can be found at openemr/contrib.
79 Reading openemr/includes/config.php and openemr/interface/globals.php is a good
83 To ensure a consistent look and feel through out the application
84 using <a href='http
://www.mozilla.org/products/firefox/'>Firefox</a>
88 <b
>The initial OpenEMR user is
"<?php echo $iuser; ?>" and the password is
"pass".</b
>
89 You should change this password
!
92 <a href
='./'>Click here to start using OpenEMR
. </a
>
102 $server = $_POST["server"];
103 $port = $_POST["port"];
104 $dbname = $_POST["dbname"];
105 $root = $_POST["root"];
106 $login = $_POST["login"];
107 $pass = $_POST["pass"];
108 $loginhost = $_POST["loginhost"];
109 $rootpass = $_POST["rootpass"];
113 echo "OpenEMR is already configured. If you wish to re-configure the SQL server, edit $conffile, or change the 'config' variable to 0, and re-run this script.<br>\n";
119 echo "<b>Step $state</b><br><br>\n";
120 echo "Now I need to know whether you want me to create the databases on my own or if you have already created the database for me to use. If you are upgrading, you will want to select the latter function. For me to create the databases, you will need to supply the MySQL root password.\n
121 <span class='title'> <br />NOTE: clicking on \"Continue\" may delete or cause damage to data on your system. Before you continue please backup your data.</span>
123 <FORM METHOD='POST'>\n
124 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
125 <INPUT TYPE='RADIO' NAME='inst' VALUE='1' checked>Have setup create the databases<br>\n
126 <INPUT TYPE='RADIO' NAME='inst' VALUE='2'>I have already created the databases<br>\n
128 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
132 echo "<b>Step $state</b><br><br>\n";
133 echo "Now you need to supply the MySQL server information.
136 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
137 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
139 <TR><TD><font color='red'>SERVER:</font></TD></TR>
140 <TR><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='server' SIZE='30'><span class='text'>(This is the IP address of the machine running MySQL)</span><br></TD></TR>
141 <TR><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'><span class='text'>(The default port for MySQL is 3306)</span><br></TD></TR>
142 <TR><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'><span class='text'>(This is the name of the OpenEMR database - 'openemr' is the recommended)</span><br></TD></TR>
143 <TR><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'><span class='text'>(This is the name of the OpenEMR login name - 'openemr' is the recommended)</span><br></TD></TR>
144 <TR><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'><span class='text'>(This is the Login Password for when PHP accesses MySQL - it should be at least 8 characters long and composed of both numbers and letters)</span><br></TD></TR>\n";
146 echo "<TR><TD><font color='red'>CLIENT:</font></TD></TR>";
147 echo "<TR><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='$defhost' NAME='loginhost' SIZE='30'><span class='text'>(This is the IP address of the server machine running Apache and PHP - if you are setting up one computer, this is the same as the Server Host above)</span><br></TD></TR>
148 <TR><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
149 <TR><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
151 echo "<TR><TD><font color='red'>USER:</font></TD></TR>";
152 echo "<TR><TD COLSPAN=2></TD></TR>
153 <TR><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'><span class='text'>(This is the user that will be created for you. It will be an authorized user, so it should be for a Doctor or other Practitioner)</span></TD></TR>
154 <TR><TD><span class='text'>Initial User's Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'><span class='text'>(This is the real name of the initial user.)</span></TD></TR>
155 <TR><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'><span class='text'>(This is the group that will be created for your users. This should be the name of your practice.)</span></TD></TR>
159 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
167 echo "<b>Step $state</b><br><br>\n";
168 if ($pass == "" ||
$login == "" ||
!isset($login) ||
!isset($pass)) {
169 echo "ERROR. Please pick a proper username and/or password.<br>\n";
174 echo "Connecting to MySQL Server...\n";
176 if ($server == "localhost")
177 $dbh = mysql_connect("$server","$root","$rootpass");
179 $dbh = mysql_connect("$server:$port","$root","$rootpass");
181 echo "ERROR. Check your login credentials.\n";
182 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
187 echo "Creating database...\n";
189 if (mysql_query("create database $dbname",$dbh) == FALSE) {
190 echo "ERROR. Check your login credentials.\n";
191 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
196 echo "Creating user with permissions for database...\n";
198 if (mysql_query("GRANT ALL PRIVILEGES ON $dbname.* TO '$login'@'$loginhost' IDENTIFIED BY '$pass'",$dbh) == FALSE) {
199 echo "ERROR when granting privileges to the specified user.\n";
200 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
206 echo "Reconnecting as new user...\n";
210 echo "Connecting to MySQL Server...\n";
212 if ($server == "localhost")
213 $dbh = mysql_connect("$server","$login","$pass");
215 $dbh = mysql_connect("$server:$port","$login","$pass");
218 echo "ERROR. Check your login credentials.\n";
219 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
224 echo "Opening database...";
226 if (mysql_select_db("$dbname",$dbh) == FALSE) {
227 echo "ERROR. Check your login credentials.\n";
228 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
235 echo "Creating initial tables...\n";
236 mysql_query("USE $dbname",$dbh);
238 $fd = fopen($dumpfile, 'r');
240 echo "ERROR. Could not open dumpfile '$dumpfile'.\n";
247 $line = fgets($fd,1024);
248 $line = rtrim($line);
249 if (substr($line,0,2) == "--") // Kill comments
251 if (substr($line,0,1) == "#") // Kill comments
255 $query = $query.$line; // Check for full query
256 $chr = substr($query,strlen($query)-1,1);
257 if ($chr == ";") { // valid query, execute
258 $query = rtrim($query,";");
259 mysql_query("$query",$dbh);
266 echo "Adding Initial User...\n";
268 $iuser = $_POST["iuser"];
269 $iuname = $_POST["iuname"];
270 $igroup = $_POST["igroup"];
271 //echo "INSERT INTO groups VALUES (1,'$igroup','$iuser')<br>\n";
272 if (mysql_query("INSERT INTO groups (id, name, user) VALUES (1,'$igroup','$iuser')") == FALSE) {
273 echo "ERROR. Could not run queries.\n";
274 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
278 if (mysql_query("INSERT INTO users (id, username, password, authorized, lname,fname) VALUES (1,'$iuser','1a1dc91c907325c69271ddf0c944bc72',1,'$iuname','')") == FALSE) {
279 echo "ERROR. Could not run queries.\n";
280 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
286 /* echo "Inserting ICD-9-CM Codes into Database...\n";
288 $fd = fopen($icd9, 'r');
290 echo "ERROR. Could not open dumpfile.\n";
291 echo "<p>".mysql_error()." (#".mysql_errno().")\n";
298 $line = fgets($fd,1024);
299 $line = rtrim($line);
300 if (substr($line,0,2) == "--") // Kill comments
302 if (substr($line,0,1) == "#") // Kill comments
306 $query = $query.$line; // Check for full query
307 $chr = substr($query,strlen($query)-1,1);
308 if ($chr == ";") { // valid query, execute
309 $query = rtrim($query,";");
310 mysql_query("$query",$dbh);
318 echo "\n<br>Next step will finalize SQL setup and install/configure access controls (php-GACL).<br>\n";
321 <FORM METHOD='POST'>\n
322 <INPUT TYPE='HIDDEN' NAME='state' VALUE='4'>
323 <INPUT TYPE='HIDDEN' NAME='host' VALUE='$server'>
324 <INPUT TYPE='HIDDEN' NAME='dbname' VALUE='$dbname'>
325 <INPUT TYPE='HIDDEN' NAME='port' VALUE='$port'>
326 <INPUT TYPE='HIDDEN' NAME='login' VALUE='$login'>
327 <INPUT TYPE='HIDDEN' NAME='pass' VALUE='$pass'>
328 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>
329 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$iuname'>
331 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
337 echo "<b>Step $state</b><br><br>\n";
338 echo "Writing SQL configuration file and setting up access controls(php-GACL)...<br><br>";
340 echo "Writing SQL Configuration...<br>";
341 @touch
($conffile); // php bug
342 $fd = @fopen
($conffile, 'w');
346 // Referenced from sql.inc
350 $it_died = 0; //fmg: variable keeps running track of any errors
352 fwrite($fd,$string) or $it_died++
;
353 fwrite($fd,"\$host\t= '$host';\n") or $it_died++
;
354 fwrite($fd,"\$port\t= '$port';\n") or $it_died++
;
355 fwrite($fd,"\$login\t= '$login';\n") or $it_died++
;
356 fwrite($fd,"\$pass\t= '$pass';\n") or $it_died++
;
357 fwrite($fd,"\$dbase\t= '$dbname';\n") or $it_died++
;
363 $sqlconf["host"]= $host;
364 $sqlconf["port"] = $port;
365 $sqlconf["login"] = $login;
366 $sqlconf["pass"] = $pass;
367 $sqlconf["dbase"] = $dbase;
368 //////////////////////////
369 //////////////////////////
370 //////////////////////////
371 //////DO NOT TOUCH THIS///
372 $config = 1; /////////////
373 //////////////////////////
374 //////////////////////////
375 //////////////////////////
378 ?
><?
// done just for coloring
380 fwrite($fd,$string) or $it_died++
;
382 //it's rather irresponsible to not report errors when writing this file.
384 echo "ERROR. Couldn't write $it_died lines to config file '$conffile'.\n";
390 echo "Successfully wrote SQL configuration.<BR><br>";
392 echo "Installing and Configuring Access Controls (php-GACL)<br>";
394 //first, edit two gacl config files
396 $data = file($gaclConfigFile1) or die("Could not read ".$gaclConfigFile1." file.");
398 foreach ($data as $line) {
400 if ((strpos($line,"db_host")) === false) {
404 $finalData .= "db_host = \"${host}\"\n";
406 if ((strpos($line,"db_user")) === false) {
410 $finalData .= "db_user = \"${login}\"\n";
412 if ((strpos($line,"db_password")) === false) {
416 $finalData .= "db_password = \"${pass}\"\n";
418 if ((strpos($line,"db_name")) === false) {
422 $finalData .= "db_name = \"${dbname}\"\n";
428 $fd = @fopen
($gaclConfigFile1, 'w') or die("Could not open ".$gaclConfigFile1." file.");
429 fwrite($fd, $finalData);
432 // edit gacl.class.php
433 $data = file($gaclConfigFile2) or die("Could not read ".$gaclConfigFile2." file.");
435 foreach ($data as $line) {
437 if ((strpos($line,"var \$_db_host = ")) === false) {
441 $finalData .= "var \$_db_host = '$host';\n";
443 if ((strpos($line,"var \$_db_user = ")) === false) {
447 $finalData .= "var \$_db_user = '$login';\n";
449 if ((strpos($line,"var \$_db_password = ")) === false) {
453 $finalData .= "var \$_db_password = '$pass';\n";
455 if ((strpos($line,"var \$_db_name = ")) === false) {
459 $finalData .= "var \$_db_name = '$dbname';\n";
465 $fd = @fopen
($gaclConfigFile2, 'w') or die("Could not open ".$gaclConfigFile2." file.");
466 fwrite($fd, $finalData);
469 //second, run gacl config scripts
470 require $gaclSetupScript1;
471 require $gaclSetupScript2;
474 //third, give the administrator user admin priviledges
475 $groupArray = array("Administrators");
476 set_user_aro($groupArray,$iuser,$iuname,"","");
477 echo "Gave the '$iuser' user (password is 'pass') administrator access.<br>";
479 echo "<br><FORM METHOD='POST'>\n
480 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
481 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$iuser'>\n
483 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
489 echo "Welcome to OpenEMR. This utility will step you through the configuration of OpenEMR for your practice. Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.<br><br>\n";
491 Echo "<p>If you are upgrading from a previous version, please read the README file.<br><br>";
493 echo "We will now ensure correct file permissions and directories before starting installation:<br><br>\n";
494 echo "<FONT COLOR='blue'>Ensuring following files are world-writable...</FONT><br>\n";
496 foreach ($writableFileList as $tempFile) {
497 if (is_writable($tempFile)) {
498 echo "'openemr/$tempFile' file is <FONT COLOR='blue'>ready</FONT>.<br>";
501 echo "<br><FONT COLOR='red'>UNABLE</FONT> to open file 'openemr/$tempFile' for writing.<br>";
502 echo "(ensure 'openemr/$tempFile' file is world-writeable)<br>";
506 if ($errorWritable) {
507 echo "<br><FONT COLOR='red'>You can't proceed until all above files are ready.</FONT><br>";
508 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>";
509 echo "In linux, recommend changing file permissions temporarily with the 'chmod 666 filename' command.<br>";
510 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'><br></FORM><br>\n";
514 echo "<br><FONT COLOR='blue'>Ensuring following directories exist...</FONT><br>\n";
516 foreach ($writableDirList as $tempDir) {
517 if (file_exists($tempDir)) {
518 echo "'openemr/$tempDir' directory <FONT COLOR='blue'>exists</FONT>.<br>";
521 echo "<br><FONT COLOR='red'>UNABLE</FONT> to find directory 'openemr/$tempDir'.<br>";
522 echo "(please create 'openemr/$tempDir' directory)<br>";
526 if ($errorWritable) {
527 echo "<br><FONT COLOR='red'>You can't proceed until all above directories exist.</FONT><br>";
528 echo "Add above marked directories and then click the 'Check Again' button to re-check for directories.<br>";
529 echo "In linux, recommend using the 'mkdir directory_name' command<br><br>\n";
530 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'><br></FORM><br>\n";
534 echo "<br><FONT COLOR='blue'>Ensuring following directories have proper permissions...</FONT><br>\n";
536 foreach ($writableDirList as $tempDir) {
537 if (is_writable($tempDir)) {
538 echo "'openemr/$tempDir' directory is <FONT COLOR='blue'>ready</FONT>.<br>";
541 echo "<br><FONT COLOR='red'>UNABLE</FONT> to open directory 'openemr/$tempDir' for writing.<br>";
542 echo "(ensure 'openemr/$tempDir' directory is world-writeable)<br>";
546 if ($errorWritable) {
547 echo "<br><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>";
548 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>";
549 echo "In linux, recommend changing owners of directories permanently to the web server. For example, in many linux OS's the web server user is 'apache', 'nobody', or 'www-data'. So if 'apache' were the web server user name, could use the command 'chown -R apache:apache directory_name' command.<br><br>\n";
550 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'><br></FORM><br>\n";
554 echo "<br><br>All required files and directories have been verified. Click to continue installation.<br>\n";
555 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'><INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";