Here is the updated integration of the DDI, take 2
[openemr.git] / setup.php
blob0b3641877de70f2bca7c1bd3b766e058be7531f8
1 <?php
2 /**
3 * Installation script.
5 * Copyright (C) 2016 Roberto Vasquez <robertogagliotta@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be usefull,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OF FITNESS FOR A PARTICULAR PURPOSE, See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the CNU General Public License
16 * along with this program. If not, see <http://opensource.org/Licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Roberto Vasquez <robertogagliotta@gmail.com>
20 * @author Scott Wakefield <scott@npclinics.com.au>
21 * @link http://www.open-emr.org
23 **/
25 // Warning. If you set $allow_multisite_setup to true, this is a potential security vulnerability.
26 // Recommend setting it back to false (or removing this setup.php script entirely) after you
27 // are done with the multisite procedure.
28 $allow_multisite_setup = false;
30 // Warning. If you set $allow_cloning_setup to true, this is a potential security vulnerability.
31 // Recommend setting it back to false (or removing this setup.php script entirely) after you
32 // are done with the cloning setup procedure.
33 $allow_cloning_setup = false;
34 if (!$allow_cloning_setup && !empty($_REQUEST['clone_database'])) {
35 die("To turn on support for cloning setup, need to edit this script and change \$allow_cloning_setup to true. After you are done setting up the cloning, ensure you change \$allow_cloning_setup back to false or remove this script altogether");
38 // Checks if the server's PHP version is compatible with OpenEMR:
39 require_once(dirname(__FILE__) . "/common/compatibility/Checker.php");
41 use OpenEMR\Common\Checker;
43 $response = Checker::checkPhpVersion();
44 if ($response !== true) {
45 die($response);
48 $COMMAND_LINE = php_sapi_name() == 'cli';
49 require_once(dirname(__FILE__) . '/library/authentication/password_hashing.php');
50 require_once dirname(__FILE__) . '/library/classes/Installer.class.php';
52 //turn off PHP compatibility warnings
53 ini_set("session.bug_compat_warn", "off");
55 $state = isset($_POST["state"]) ? ($_POST["state"]) : '';
57 // Make this true for IPPF.
58 $ippf_specific = false;
60 // If this script was invoked with no site ID, then ask for one.
61 if (!$COMMAND_LINE && empty($_REQUEST['site'])) {
62 echo "<html>\n";
63 echo "<head>\n";
64 echo "<title>OpenEMR Setup Tool</title>\n";
65 echo "<link rel='stylesheet' href='interface/themes/style_blue.css'>\n";
66 echo "</head>\n";
67 echo "<body>\n";
68 echo "<p><b>Optional Site ID Selection</b></p>\n";
69 echo "<p>Most OpenEMR installations support only one site. If that is " .
70 "true for you then ignore the rest of this text and just click Continue.</p>\n";
71 echo "<p>Otherwise please enter a unique Site ID here.</p>\n";
72 echo "<p>A Site ID is a short identifier with no spaces or special " .
73 "characters other than periods or dashes. It is case-sensitive and we " .
74 "suggest sticking to lower case letters for ease of use.</p>\n";
75 echo "<p>If each site will have its own host/domain name, then use that " .
76 "name as the Site ID (e.g. www.example.com).</p>\n";
77 echo "<p>The site ID is used to identify which site you will log in to. " .
78 "If it is a hostname then it is taken from the hostname in the URL. " .
79 "Otherwise you must append \"?site=<i>siteid</i>\" to the URL used for " .
80 "logging in.</p>\n";
81 echo "<p>It is OK for one of the sites to have \"default\" as its ID. This " .
82 "is the ID that will be used if it cannot otherwise be determined.</p>\n";
83 echo "<form method='post'><input type='hidden' name='state' value='0'>" .
84 "Site ID: <input type='text' name='site' value='default'>&nbsp;" .
85 "<input type='submit' value='Continue'><br></form><br>\n";
86 echo "</body></html>\n";
87 exit();
90 // Support "?site=siteid" in the URL, otherwise assume "default".
91 $site_id = 'default';
92 if (!$COMMAND_LINE && !empty($_REQUEST['site'])) {
93 $site_id = trim($_REQUEST['site']);
96 // Die if site ID is empty or has invalid characters.
97 if (empty($site_id) || preg_match('/[^A-Za-z0-9\\-.]/', $site_id)) {
98 die("Site ID '".htmlspecialchars($site_id, ENT_NOQUOTES)."' contains invalid characters.");
101 // If multisite is turned off, then only allow default for site.
102 if (!$allow_multisite_setup && $site_id != 'default') {
103 die("To turn on support for multisite setup, need to edit this script and change \$allow_multisite_setup to true. After you are done setting up the cloning, ensure you change \$allow_multisite_setup back to false or remove this script altogether");
106 //If having problems with file and directory permission
107 // checking, then can be manually disabled here.
108 $checkPermissions = true;
110 $installer = new Installer($_REQUEST);
111 global $OE_SITE_DIR; // The Installer sets this
113 $docsDirectory = "$OE_SITE_DIR/documents";
114 $billingDirectory = "$OE_SITE_DIR/edi";
115 $billingDirectory2 = "$OE_SITE_DIR/era";
116 $lettersDirectory = "$OE_SITE_DIR/letter_templates";
117 $gaclWritableDirectory = dirname(__FILE__)."/gacl/admin/templates_c";
118 $requiredDirectory1 = dirname(__FILE__)."/interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
119 $requiredDirectory2 = dirname(__FILE__)."/interface/main/calendar/modules/PostCalendar/pntemplates/cache";
121 $zendModuleConfigFile = dirname(__FILE__)."/interface/modules/zend_modules/config/application.config.php";
123 //These are files and dir checked before install for
124 // correct permissions.
125 if (is_dir($OE_SITE_DIR)) {
126 $writableFileList = array($installer->conffile,$zendModuleConfigFile);
127 $writableDirList = array($docsDirectory, $billingDirectory, $billingDirectory2, $lettersDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
128 } else {
129 $writableFileList = array();
130 $writableDirList = array($OE_SITES_BASE, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
133 // Include the sqlconf file if it exists yet.
134 $config = 0;
135 if (file_exists($OE_SITE_DIR)) {
136 include_once($installer->conffile);
137 } else if ($state > 3) {
138 // State 3 should have created the site directory if it is missing.
139 die("Internal error, site directory is missing.");
143 <HTML>
144 <HEAD>
145 <TITLE>OpenEMR Setup Tool</TITLE>
146 <LINK REL=STYLESHEET HREF="interface/themes/style_blue.css">
147 <link rel="shortcut icon" href="public/images/favicon.ico" />
149 <style>
150 .noclone { }
151 table.phpset { border-collapse:collapse; }
152 table.phpset td, table.phpset th { font-size:9pt; border:1px solid gray; padding:2px; }
153 </style>
155 <script type="text/javascript" src="public/assets/jquery/dist/jquery.min.js"></script>
156 <script language="javascript">
157 // onclick handler for "clone database" checkbox
158 function cloneClicked() {
159 var cb = document.forms[0].clone_database;
160 $('.noclone').css('display', cb.checked ? 'none' : 'block');
162 </script>
164 </HEAD>
165 <BODY>
167 <span class="title">OpenEMR Setup</span>
168 <br><br>
169 <span class="text">
170 <?php
171 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
172 echo "It appears that you have register_globals enabled in your php.ini\n" .
173 "configuration file. This causes unacceptable security risks. You must\n" .
174 "turn it off before continuing with installation.\n";
175 exit(1);
178 if (!extension_loaded("xml")) {
179 echo "Error: PHP XML extension missing. To continue, install PHP XML extension, then restart web server.";
180 exit(1);
183 if (!(extension_loaded("mysql") || extension_loaded("mysqlnd") || extension_loaded("mysqli"))) {
184 echo "Error: PHP MySQL extension missing. To continue, install and enable MySQL extension, then restart web server.";
185 exit(1);
188 if (!(extension_loaded("mbstring") )) {
189 echo "Error: PHP mb_string extension missing. To continue, install and enable mb_string extension, then restart web server.";
190 exit(1);
194 <?php
195 if ($state == 7) {
198 <p>Congratulations! OpenEMR is now installed.</p>
200 <ul>
201 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
202 OpenEMR's admin->acl menu.</li>
203 <li>Reviewing <?php echo $OE_SITE_DIR; ?>/config.php is a good idea. This file
204 contains some settings that you may want to change.</li>
205 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
206 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
207 <li>To ensure a consistent look and feel throughout the application,
208 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> and <a href="https://www.google.com/chrome/browser/desktop/index.html">Chrome</a> are recommended. The OpenEMR development team exclusively tests with modern versions of these browsers.</li>
209 <li>The OpenEMR project home page, documentation, and forums can be found at <a href = "http://www.open-emr.org" target="_blank">http://www.open-emr.org</a></li>
210 <li>We pursue grants to help fund the future development of OpenEMR. To apply for these grants, we need to estimate how many times this program is installed and how many practices are evaluating or using this software. It would be awesome if you would email us at <a href="mailto:president@oemr.org">president@oemr.org</a> if you have installed this software. The more details about your plans with this software, the better, but even just sending us an email stating you just installed it is very helpful.</li>
211 </ul>
213 We recommend you print these instructions for future reference.
214 </p>
215 <?php if (empty($installer->clone_database)) {
216 echo "<p><b>The initial OpenEMR user is '".$installer->iuser."' and the password is '".$installer->iuserpass."'</b></p>";
217 echo "<p>If you edited the PHP or Apache configuration files during this installation process, then we recommend you restart your Apache server before following below OpenEMR link.</p>";
218 } ?>
220 <a href='./?site=<?php echo $site_id; ?>'>Click here to start using OpenEMR. </a>
221 </p>
223 <?php
224 exit();
228 <?php
230 $inst = isset($_POST["inst"]) ? ($_POST["inst"]) : '';
233 if (($config == 1) && ($state < 4)) {
234 echo "OpenEMR has already been installed. If you wish to force re-installation, then edit $installer->conffile (change the 'config' variable to 0), and re-run this script.<br>\n";
235 } else {
236 switch ($state) {
237 case 1:
238 echo "<b>Step $state</b><br><br>\n";
239 echo "Now I need to know whether you want me to create the database on my own or if you have already created the database for me to use. For me to create the database, you will need to supply the MySQL root password.\n
240 <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>
241 <br><br>\n
242 <FORM METHOD='POST'>\n
243 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
244 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
245 <LABEL FOR='inst1'><INPUT TYPE='RADIO' ID='inst1' NAME='inst' VALUE='1' checked>Have setup create the database</label><br>\n
246 <LABEL FOR='inst2'><INPUT TYPE='RADIO' ID='inst2' NAME='inst' VALUE='2'>I have already created the database</label><br>\n
247 <br>\n
248 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
249 break;
251 case 2:
252 echo "<b>Step $state</b><br><br>\n";
253 echo "Now you need to supply the MySQL server information and path information. Detailed instructions on each item can be found in the <a href='Documentation/INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.
254 <br><br>\n
255 <FORM METHOD='POST'>
256 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
257 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
258 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
259 <TABLE>\n
260 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
261 <TR VALIGN='TOP'><TD><span class='text'>Server Host: </span></TD><TD><INPUT TYPE='TEXT' VALUE='localhost' NAME='server' SIZE='30'></TD><TD><span class='text'>(If you run MySQL and Apache/PHP on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running MySQL.)</span><br></TD></TR>
262 <TR VALIGN='TOP'><TD><span class='text'>Server Port: </span></TD><TD><INPUT TYPE='TEXT' VALUE='3306' NAME='port' SIZE='30'></TD><TD><span class='text'>(This is the MySQL port. The default port for MySQL is 3306.)</span><br></TD></TR>
263 <TR VALIGN='TOP'><TD><span class='text'>Database Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='dbname' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR database in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
264 <TR VALIGN='TOP'><TD><span class='text'>Login Name: </span></TD><TD><INPUT TYPE='TEXT' VALUE='openemr' NAME='login' SIZE='30'></TD><TD><span class='text'>(This is the name of the OpenEMR login name in MySQL - 'openemr' is the recommended)</span><br></TD></TR>
265 <TR VALIGN='TOP'><TD><span class='text'>Password: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='pass' SIZE='30'></TD><TD><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";
266 if ($inst != 2) {
267 echo "<TR VALIGN='TOP'><TD><span class='text'>Name for Root Account: </span></TD><TD><INPUT TYPE='TEXT' VALUE='root' NAME='root' SIZE='30'></TD><TD><span class='text'>(This is name for MySQL root account. For localhost, it is usually ok to leave it 'root'.)</span><br></TD></TR>
268 <TR VALIGN='TOP'><TD><span class='text'>Root Pass: </span></TD><TD><INPUT TYPE='PASSWORD' VALUE='' NAME='rootpass' SIZE='30'></TD><TD><span class='text'>(This is your MySQL root password. For localhost, it is usually ok to leave it blank.)</span><br></TD></TR>\n";
269 echo "<TR VALIGN='TOP'><TD><span class='text'>User Hostname: </span></TD><TD><INPUT TYPE='TEXT' VALUE='localhost' NAME='loginhost' SIZE='30'></TD><TD><span class='text'>(If you run Apache/PHP and MySQL on the same computer, then leave this as 'localhost'. If they are on separate computers, then enter the IP address of the computer running Apache/PHP.)</span><br></TD></TR>";
270 echo "<TR VALIGN='TOP'><TD><span class='text'>UTF-8 Collation: </span></TD><TD colspan='2'>" .
271 "<select name='collate'>" .
272 "<option value='utf8_bin' >Bin</option>" .
273 "<option value='utf8_czech_ci' >Czech</option>" .
274 "<option value='utf8_danish_ci' >Danish</option>" .
275 "<option value='utf8_esperanto_ci' >Esperanto</option>" .
276 "<option value='utf8_estonian_ci' >Estonian</option>" .
277 "<option value='utf8_general_ci' selected>General</option>" .
278 "<option value='utf8_hungarian_ci' >Hungarian</option>" .
279 "<option value='utf8_icelandic_ci' >Icelandic</option>" .
280 "<option value='utf8_latvian_ci' >Latvian</option>" .
281 "<option value='utf8_lithuanian_ci'>Lithuanian</option>" .
282 "<option value='utf8_persian_ci' >Persian</option>" .
283 "<option value='utf8_polish_ci' >Polish</option>" .
284 "<option value='utf8_roman_ci' >Roman</option>" .
285 "<option value='utf8_romanian_ci' >Romanian</option>" .
286 "<option value='utf8_slovak_ci' >Slovak</option>" .
287 "<option value='utf8_slovenian_ci' >Slovenian</option>" .
288 "<option value='utf8_spanish2_ci' >Spanish2 (Traditional)</option>" .
289 "<option value='utf8_spanish_ci' >Spanish (Modern)</option>" .
290 "<option value='utf8_swedish_ci' >Swedish</option>" .
291 "<option value='utf8_turkish_ci' >Turkish</option>" .
292 "<option value='utf8_unicode_ci' >Unicode (German, French, Russian, Armenian, Greek)</option>" .
293 "<option value='' >None (Do not force UTF-8)</option>" .
294 "</select>" .
295 "</TD></TR><TR VALIGN='TOP'><TD>&nbsp;</TD><TD colspan='2'><span class='text'>(This is the collation setting for mysql. Leave as 'General' if you are not sure. If the language you are planning to use in OpenEMR is in the menu, then you can select it. Otherwise, just select 'General'.)</span><br></TD></TR>";
298 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
300 // Include a "source" site ID drop-list and a checkbox to indicate
301 // if cloning its database. When checked, do not display initial user
302 // and group stuff below.
303 $dh = opendir($OE_SITES_BASE);
304 if (!$dh) {
305 die("Cannot read directory '$OE_SITES_BASE'.");
308 $siteslist = array();
309 while (false !== ($sfname = readdir($dh))) {
310 if (substr($sfname, 0, 1) == '.') {
311 continue;
314 if ($sfname == 'CVS') {
315 continue;
318 if ($sfname == $site_id) {
319 continue;
322 $sitedir = "$OE_SITES_BASE/$sfname";
323 if (!is_dir($sitedir)) {
324 continue;
327 if (!is_file("$sitedir/sqlconf.php")) {
328 continue;
331 $siteslist[$sfname] = $sfname;
334 closedir($dh);
335 // If this is not the first site...
336 if (!empty($siteslist)) {
337 ksort($siteslist);
338 echo "<tr valign='top'>\n";
339 echo " <td class='text'>Source Site: </td>\n";
340 echo " <td class='text'><select name='source_site_id'>";
341 foreach ($siteslist as $sfname) {
342 echo "<option value='$sfname'";
343 if ($sfname == 'default') {
344 echo " selected";
347 echo ">$sfname</option>";
350 echo "</select></td>\n";
351 echo " <td class='text'>(The site directory that will be a model for the new site.)</td>\n";
352 echo "</tr>\n";
353 echo "<tr valign='top'>\n";
354 echo " <td class='text'>Clone Source Database: </td>\n";
355 echo " <td class='text'><input type='checkbox' name='clone_database' onclick='cloneClicked()' /></td>\n";
356 echo " <td class='text'>(Clone the source site's database instead of creating a fresh one.)</td>\n";
357 echo "</tr>\n";
360 echo "<TR VALIGN='TOP' class='noclone'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
361 echo "<TR VALIGN='TOP' class='noclone'><TD><span class='text'>Initial User:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuser' VALUE='admin'></TD><TD><span class='text'>(This is the login name of user that will be created for you. Limit this to one word.)</span></TD></TR>
362 <TR VALIGN='TOP' class='noclone'><TD><span class='text'>Initial User Password:</span></TD><TD><INPUT SIZE='30' TYPE='PASSWORD' NAME='iuserpass' VALUE=''></TD><TD><span class='text'>(This is the password for the initial user account above.)</span></TD></TR>
363 <TR VALIGN='TOP' class='noclone'><TD><span class='text'>Initial User's First Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iufname' VALUE='Administrator'></TD><TD><span class='text'>(This is the First name of the 'initial user'.)</span></TD></TR>
364 <TR VALIGN='TOP' class='noclone'><TD><span class='text'>Initial User's Last Name:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='iuname' VALUE='Administrator'></TD><TD><span class='text'>(This is the Last name of the 'initial user'.)</span></TD></TR>
365 <TR VALIGN='TOP' class='noclone'><TD><span class='text'>Initial Group:</span></TD><TD><INPUT SIZE='30' TYPE='TEXT' NAME='igroup' VALUE='Default'></TD><TD><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>
367 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
369 echo "</TABLE>
370 <br>
371 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
372 break;
374 case 3:
375 // Form Validation
376 // (applicable if not cloning from another database)
378 $pass_step2_validation = true;
379 $error_step2_message = "ERROR at ";
381 if (! $installer->char_is_valid($_REQUEST['server'])) {
382 $pass_step2_validation = false;
383 $error_step2_message .= "Database Server Host, ";
386 if (! $installer->char_is_valid($_REQUEST['port'])) {
387 $pass_step2_validation = false;
388 $error_step2_message .= "Database Server Port, ";
391 if (! $installer->databaseNameIsValid($_REQUEST['dbname'])) {
392 $pass_step2_validation = false;
393 $error_step2_message .= "Database Name, ";
396 if (! $installer->collateNameIsValid($_REQUEST['collate'])) {
397 $pass_step2_validation = false;
398 $error_step2_message .= "Collation Name, ";
401 if (! $installer->char_is_valid($_REQUEST['login'])) {
402 $pass_step2_validation = false;
403 $error_step2_message .= "Database Login Name, ";
406 if (! $installer->char_is_valid($_REQUEST['pass'])) {
407 $pass_step2_validation = false;
408 $error_step2_message .= "Database Login Password, ";
411 if (!$pass_step2_validation) {
412 die($error_step2_message);
416 if (empty($installer->clone_database)) {
417 if (! $installer->login_is_valid()) {
418 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
419 echo "Click Back in browser to re-enter.<br>\n";
420 break;
423 if (! $installer->iuser_is_valid()) {
424 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
425 echo "Click Back in browser to re-enter.<br>\n";
426 break;
429 if (! $installer->user_password_is_valid()) {
430 echo "ERROR. Please pick a proper 'Initial User Password'.<br>\n";
431 echo "Click Back in browser to re-enter.<br>\n";
432 break;
436 if (! $installer->password_is_valid()) {
437 echo "ERROR. Please pick a proper 'Password'.<br>\n";
438 echo "Click Back in browser to re-enter.<br>\n";
439 break;
442 echo "<b>Step $state</b><br><br>\n";
443 echo "Configuring OpenEMR...<br><br>\n";
445 // Skip below if database shell has already been created.
446 if ($inst != 2) {
447 echo "Connecting to MySQL Server...\n";
448 flush();
449 if (! $installer->root_database_connection()) {
450 echo "ERROR. Check your login credentials.\n";
451 echo $installer->error_message;
452 break;
453 } else {
454 echo "OK.<br>\n";
455 flush();
459 // Only pertinent if cloning another installation database
460 if ($allow_cloning_setup && !empty($installer->clone_database)) {
461 echo "Dumping source database...";
462 flush();
463 if (! $installer->create_dumpfiles()) {
464 echo $installer->error_message;
465 break;
466 } else {
467 echo " OK.<br>\n";
468 flush();
472 // Only pertinent if mirroring another installation directory
473 if (! empty($installer->source_site_id)) {
474 echo "Creating site directory...";
475 if (! $installer->create_site_directory()) {
476 echo $installer->error_message;
477 break;
478 } else {
479 echo "OK.<BR>";
480 flush();
484 // Skip below if database shell has already been created.
485 if ($inst != 2) {
486 echo "Creating database...\n";
487 flush();
488 if (! $installer->create_database()) {
489 echo "ERROR. Check your login credentials.\n";
490 echo $installer->error_message;
491 break;
492 } else {
493 echo "OK.<br>\n";
494 flush();
497 echo "Creating user with permissions for database...\n";
498 flush();
499 $user_mysql_error = true;
500 if (! $installer->create_database_user()) {
501 echo "ERROR when creating specified user.\n";
502 echo $installer->error_message;
503 break;
504 } else {
505 $user_mysql_error = false;
507 if (! $installer->grant_privileges()) {
508 echo "ERROR when granting privileges to the specified user.\n";
509 echo $installer->error_message;
510 break;
511 } else {
512 $user_mysql_error = false;
514 if (!$user_mysql_error) {
515 echo "OK.<br>\n";
516 flush();
519 echo "Reconnecting as new user...\n";
520 flush();
521 $installer->disconnect();
522 } else {
523 echo "Connecting to MySQL Server...\n";
526 if (! $installer->user_database_connection()) {
527 echo "ERROR. Check your login credentials.\n";
528 echo $installer->error_message;
529 break;
530 } else {
531 echo "OK.<br>\n";
532 flush();
535 // Load the database files
536 $dump_results = $installer->load_dumpfiles();
537 if (! $dump_results) {
538 echo $installer->error_message;
539 break;
540 } else {
541 echo $dump_results;
542 flush();
545 echo "Writing SQL configuration...\n";
546 flush();
547 if (! $installer->write_configuration_file()) {
548 echo $installer->error_message;
549 break;
550 } else {
551 echo "OK.<br>\n";
552 flush();
555 // Only pertinent if not cloning another installation database
556 if (empty($installer->clone_database)) {
557 echo "Setting version indicators...\n";
558 flush();
559 if (! $installer->add_version_info()) {
560 echo "ERROR.\n";
561 echo $installer->error_message;
563 break;
564 } else {
565 echo "OK<br>\n";
566 flush();
569 echo "Writing global configuration defaults...\n";
570 flush();
571 if (! $installer->insert_globals()) {
572 echo "ERROR.\n";
573 echo $installer->error_message;
575 break;
576 } else {
577 echo "OK<br>\n";
578 flush();
581 echo "Adding Initial User...\n";
582 flush();
583 if (! $installer->add_initial_user()) {
584 echo $installer->error_message;
585 break;
588 echo "OK<br>\n";
589 flush();
592 if ($allow_cloning_setup && !empty($installer->clone_database)) {
593 // Database was cloned, skip ACL setup.
594 echo "Click 'continue' for further instructions.";
595 $next_state = 7;
596 } else {
597 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
598 $next_state = 4;
601 echo "
602 <FORM METHOD='POST'>\n
603 <INPUT TYPE='HIDDEN' NAME='state' VALUE='$next_state'>
604 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
605 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>
606 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>
607 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$installer->iuname'>
608 <INPUT TYPE='HIDDEN' NAME='iufname' VALUE='$installer->iufname'>";
609 if ($allow_cloning_setup) {
610 echo "<INPUT TYPE='HIDDEN' NAME='clone_database' VALUE='$installer->clone_database'>";
612 echo "
613 <br>\n
614 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
616 break;
617 case 4:
618 echo "<b>Step $state</b><br><br>\n";
619 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
621 if (! $installer->install_gacl()) {
622 echo $installer->error_message;
623 break;
624 } else {
625 // display the status information for gacl setup
626 echo $installer->debug_message;
629 echo "Gave the '$installer->iuser' user (password is '$installer->iuserpass') administrator access.<br><br>";
631 echo "Done installing and configuring access controls (php-GACL).<br>";
632 echo "Next step will configure PHP.";
634 echo "<br><FORM METHOD='POST'>\n
635 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
636 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
637 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>\n
638 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>\n
639 <br>\n
640 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
642 break;
644 case 5:
645 echo "<b>Step $state</b><br><br>\n";
646 echo "Configuration of PHP...<br><br>\n";
647 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
648 echo "<ul>";
649 $gotFileFlag = 0;
650 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
651 $phpINIfile = php_ini_loaded_file();
652 if ($phpINIfile) {
653 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
654 $gotFileFlag = 1;
658 echo "<li>","To ensure proper functioning of OpenEMR you must make sure that PHP settings include:";
659 echo "<table class='phpset'><tr><th>Setting</th><th>Required value</th><th>Current value</th></tr>";
660 echo "<tr><td>short_open_tag </td><td>Off</td><td>", ini_get('short_open_tag')?'On':'Off', "</td></tr>\n";
661 echo "<tr><td>display_errors </td><td>Off</td><td>", ini_get('display_errors')?'On':'Off', "</td></tr>\n";
662 echo "<tr><td>register_globals </td><td>Off</td><td>", ini_get('register_globals')?'On':'Off', "</td></tr>\n";
663 echo "<tr><td>max_input_vars </td><td>at least 3000</td><td>", ini_get('max_input_vars'), "</td></tr>\n";
664 echo "<tr><td>max_execution_time </td><td>at least 60</td><td>", ini_get('max_execution_time'), "</td></tr>\n";
665 echo "<tr><td>max_input_time </td><td>-1</td><td>", ini_get('max_input_time'), "</td></tr>\n";
666 echo "<tr><td>post_max_size </td><td>at least 30M</td><td>", ini_get('post_max_size'), "</td></tr>\n";
667 echo "<tr><td>memory_limit </td><td>at least 256M</td><td>", ini_get('memory_limit'), "</td></tr>\n";
668 echo "</table>";
669 echo "</li>";
671 echo "<li>In order to take full advantage of the patient documents capability you must make sure that settings in php.ini file include \"file_uploads = On\", that \"upload_max_filesize\" is appropriate for your use and that \"upload_tmp_dir\" is set to a correct value that will work on your system.</li>\n";
672 if (!$gotFileFlag) {
673 echo "<li>If you are having difficulty finding your php.ini file, then refer to the <a href='Documentation/INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual for suggestions.</li>\n";
676 echo "</ul>";
678 echo "<br>We recommend you print these instructions for future reference.<br><br>";
679 echo "Next step will configure Apache web server.";
681 echo "<br><FORM METHOD='POST'>\n
682 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
683 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
684 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>\n
685 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>\n
686 <br>\n
687 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
689 break;
691 case 6:
692 echo "<b>Step $state</b><br><br>\n";
693 echo "Configuration of Apache web server...<br><br>\n";
694 echo "The \"".preg_replace("/${site_id}/", "*", realpath($docsDirectory))."\", \"".preg_replace("/${site_id}/", "*", realpath($billingDirectory))."\" and \"".preg_replace("/${site_id}/", "*", realpath($billingDirectory2))."\" directories contain patient information, and
695 it is important to secure these directories. Additionally, some settings are required for the Zend Framework to work in OpenEMR. This can be done by pasting the below to end of your apache configuration file:<br>
696 &nbsp;&nbsp;&lt;Directory \"".realpath(dirname(__FILE__))."\"&gt;<br>
697 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride FileInfo<br>
698 &nbsp;&nbsp;&lt;/Directory&gt;<br>
699 &nbsp;&nbsp;&lt;Directory \"".realpath(dirname(__FILE__))."/sites\"&gt;<br>
700 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride None<br>
701 &nbsp;&nbsp;&lt;/Directory&gt;<br>
702 &nbsp;&nbsp;&lt;Directory \"".preg_replace("/${site_id}/", "*", realpath($docsDirectory))."\"&gt;<br>
703 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
704 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
705 &nbsp;&nbsp;&lt;/Directory&gt;<br>
706 &nbsp;&nbsp;&lt;Directory \"".preg_replace("/${site_id}/", "*", realpath($billingDirectory))."\"&gt;<br>
707 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
708 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
709 &nbsp;&nbsp;&lt;/Directory&gt;<br>
710 &nbsp;&nbsp;&lt;Directory \"".preg_replace("/${site_id}/", "*", realpath($billingDirectory2))."\"&gt;<br>
711 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
712 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
713 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
715 echo "If you are having difficulty finding your apache configuration file, then refer to the <a href='Documentation/INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual for suggestions.<br><br>\n";
716 echo "<br>We recommend you print these instructions for future reference.<br><br>";
717 echo "Click 'continue' for further instructions.";
719 echo "<br><FORM METHOD='POST'>\n
720 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
721 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
722 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>\n
723 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>\n
724 <br>\n
725 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
727 break;
729 case 0:
730 default:
731 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
732 echo "<ul><li>Before proceeding, be sure that you have a properly installed and configured MySQL server available, and a PHP configured webserver.</li>\n";
734 echo "<li>Detailed installation instructions can be found in the <a href='Documentation/INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li>\n";
736 echo "<li>If you are upgrading from a previous version, do NOT use this script. Please read the 'Upgrading' section found in the <a href='Documentation/INSTALL' target='_blank'><span STYLE='text-decoration: underline;'>'INSTALL'</span></a> manual file.</li></ul>";
738 if ($checkPermissions) {
739 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
740 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
741 $errorWritable = 0;
742 foreach ($writableFileList as $tempFile) {
743 if (is_writable($tempFile)) {
744 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
745 } else {
746 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
747 echo "(configure file permissions; see below for further instructions)</p>\n";
748 $errorWritable = 1;
752 if ($errorWritable) {
753 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
754 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
755 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
756 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
757 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
758 break;
761 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
762 $errorWritable = 0;
763 foreach ($writableDirList as $tempDir) {
764 if (is_writable($tempDir)) {
765 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
766 } else {
767 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
768 echo "(configure directory permissions; see below for further instructions)</p>\n";
769 $errorWritable = 1;
773 if ($errorWritable) {
774 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
775 echo "In linux, recommend changing owners of these directories 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>\n";
776 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
777 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
778 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
779 break;
782 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
783 } else {
784 echo "<br>Click to continue installation.<br>\n";
787 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'>" .
788 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>" .
789 "<INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
794 </span>
796 </BODY>
797 </HTML>