path fix for public images
[openemr.git] / setup.php
bloba171362970fc433994d5e8d47823c1278b850eb2
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 $COMMAND_LINE = php_sapi_name() == 'cli';
26 require_once (dirname(__FILE__) . '/library/authentication/password_hashing.php');
27 require_once dirname(__FILE__) . '/library/classes/Installer.class.php';
29 //turn off PHP compatibility warnings
30 ini_set("session.bug_compat_warn","off");
32 $state = isset($_POST["state"]) ? ($_POST["state"]) : '';
34 // Make this true for IPPF.
35 $ippf_specific = false;
37 // If this script was invoked with no site ID, then ask for one.
38 if (!$COMMAND_LINE && empty($_REQUEST['site'])) {
39 echo "<html>\n";
40 echo "<head>\n";
41 echo "<title>OpenEMR Setup Tool</title>\n";
42 echo "<link rel='stylesheet' href='interface/themes/style_blue.css'>\n";
43 echo "</head>\n";
44 echo "<body>\n";
45 echo "<p><b>Optional Site ID Selection</b></p>\n";
46 echo "<p>Most OpenEMR installations support only one site. If that is " .
47 "true for you then ignore the rest of this text and just click Continue.</p>\n";
48 echo "<p>Otherwise please enter a unique Site ID here.</p>\n";
49 echo "<p>A Site ID is a short identifier with no spaces or special " .
50 "characters other than periods or dashes. It is case-sensitive and we " .
51 "suggest sticking to lower case letters for ease of use.</p>\n";
52 echo "<p>If each site will have its own host/domain name, then use that " .
53 "name as the Site ID (e.g. www.example.com).</p>\n";
54 echo "<p>The site ID is used to identify which site you will log in to. " .
55 "If it is a hostname then it is taken from the hostname in the URL. " .
56 "Otherwise you must append \"?site=<i>siteid</i>\" to the URL used for " .
57 "logging in.</p>\n";
58 echo "<p>It is OK for one of the sites to have \"default\" as its ID. This " .
59 "is the ID that will be used if it cannot otherwise be determined.</p>\n";
60 echo "<form method='post'><input type='hidden' name='state' value='0'>" .
61 "Site ID: <input type='text' name='site' value='default'>&nbsp;" .
62 "<input type='submit' value='Continue'><br></form><br>\n";
63 echo "</body></html>\n";
64 exit();
67 // Support "?site=siteid" in the URL, otherwise assume "default".
68 $site_id = 'default';
69 if (!$COMMAND_LINE && !empty($_REQUEST['site'])) {
70 $site_id = trim($_REQUEST['site']);
73 // Die if site ID is empty or has invalid characters.
74 if (empty($site_id) || preg_match('/[^A-Za-z0-9\\-.]/', $site_id))
75 die("Site ID '".htmlspecialchars($site_id,ENT_NOQUOTES)."' contains invalid characters.");
77 //If having problems with file and directory permission
78 // checking, then can be manually disabled here.
79 $checkPermissions = True;
81 $installer = new Installer( $_REQUEST );
82 global $OE_SITE_DIR; // The Installer sets this
84 $docsDirectory = "$OE_SITE_DIR/documents";
85 $billingDirectory = "$OE_SITE_DIR/edi";
86 $billingDirectory2 = "$OE_SITE_DIR/era";
87 $lettersDirectory = "$OE_SITE_DIR/letter_templates";
88 $gaclWritableDirectory = dirname(__FILE__)."/gacl/admin/templates_c";
89 $requiredDirectory1 = dirname(__FILE__)."/interface/main/calendar/modules/PostCalendar/pntemplates/compiled";
90 $requiredDirectory2 = dirname(__FILE__)."/interface/main/calendar/modules/PostCalendar/pntemplates/cache";
92 $zendModuleConfigFile = dirname(__FILE__)."/interface/modules/zend_modules/config/application.config.php";
94 //These are files and dir checked before install for
95 // correct permissions.
96 if (is_dir($OE_SITE_DIR)) {
97 $writableFileList = array($installer->conffile,$zendModuleConfigFile);
98 $writableDirList = array($docsDirectory, $billingDirectory, $billingDirectory2, $lettersDirectory, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
100 else {
101 $writableFileList = array();
102 $writableDirList = array($OE_SITES_BASE, $gaclWritableDirectory, $requiredDirectory1, $requiredDirectory2);
105 // Include the sqlconf file if it exists yet.
106 $config = 0;
107 if (file_exists($OE_SITE_DIR)) {
108 include_once($installer->conffile);
110 else if ($state > 3) {
111 // State 3 should have created the site directory if it is missing.
112 die("Internal error, site directory is missing.");
116 <HTML>
117 <HEAD>
118 <TITLE>OpenEMR Setup Tool</TITLE>
119 <LINK REL=STYLESHEET HREF="interface/themes/style_sky_blue.css">
120 <link rel="shortcut icon" href="public/images/favicon.ico" />
122 <style>
123 .noclone { }
124 table.phpset { border-collapse:collapse; }
125 table.phpset td, table.phpset th { font-size:9pt; border:1px solid gray; padding:2px; }
126 </style>
128 <script type="text/javascript" src="public/assets/jquery-min-1-2-1/index.js"></script>
130 <script language="javascript">
131 // onclick handler for "clone database" checkbox
132 function cloneClicked() {
133 var cb = document.forms[0].clone_database;
134 $('.noclone').css('display', cb.checked ? 'none' : 'block');
136 </script>
138 </HEAD>
139 <BODY>
141 <span class="title">OpenEMR Setup</span>
142 <br><br>
143 <span class="text">
145 <?php
146 if (strtolower(ini_get('register_globals')) != 'off' && (bool) ini_get('register_globals')) {
147 echo "It appears that you have register_globals enabled in your php.ini\n" .
148 "configuration file. This causes unacceptable security risks. You must\n" .
149 "turn it off before continuing with installation.\n";
150 exit(1);
153 if(!extension_loaded("xml")) {
154 echo "Error: PHP XML extension missing. To continue, install PHP XML extension, then restart web server.";
155 exit(1);
157 if( !(extension_loaded("mysql") || extension_loaded("mysqlnd") || extension_loaded("mysqli")) ) {
158 echo "Error: PHP MySQL extension missing. To continue, install and enable MySQL extension, then restart web server.";
159 exit(1);
161 if( !(extension_loaded("mbstring") ) ) {
162 echo "Error: PHP mb_string extension missing. To continue, install and enable mb_string extension, then restart web server.";
163 exit(1);
167 <?php
168 if ($state == 7) {
171 <p>Congratulations! OpenEMR is now installed.</p>
173 <ul>
174 <li>Access controls (php-GACL) are installed for fine-grained security, and can be administered in
175 OpenEMR's admin->acl menu.</li>
176 <li>Reviewing <?php echo $OE_SITE_DIR; ?>/config.php is a good idea. This file
177 contains some settings that you may want to change.</li>
178 <li>There's much information and many extra tools bundled within the OpenEMR installation directory.
179 Please refer to openemr/Documentation. Many forms and other useful scripts can be found at openemr/contrib.</li>
180 <li>To ensure a consistent look and feel through out the application using
181 <a href='http://www.mozilla.org/products/firefox/'>Firefox</a> is recommended.</li>
182 <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>
183 <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>
184 </ul>
186 We recommend you print these instructions for future reference.
187 </p>
188 <?php if (empty($installer->clone_database)) {
189 echo "<p><b>The initial OpenEMR user is '".$installer->iuser."' and the password is '".$installer->iuserpass."'</b></p>";
190 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>";
191 } ?>
193 <a href='./?site=<?php echo $site_id; ?>'>Click here to start using OpenEMR. </a>
194 </p>
196 <?php
197 exit();
201 <?php
203 $inst = isset($_POST["inst"]) ? ($_POST["inst"]) : '';
206 if (($config == 1) && ($state < 4)) {
207 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";
209 else {
210 switch ($state) {
212 case 1:
213 echo "<b>Step $state</b><br><br>\n";
214 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
215 <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>
216 <br><br>\n
217 <FORM METHOD='POST'>\n
218 <INPUT TYPE='HIDDEN' NAME='state' VALUE='2'>\n
219 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
220 <LABEL FOR='inst1'><INPUT TYPE='RADIO' ID='inst1' NAME='inst' VALUE='1' checked>Have setup create the database</label><br>\n
221 <LABEL FOR='inst2'><INPUT TYPE='RADIO' ID='inst2' NAME='inst' VALUE='2'>I have already created the database</label><br>\n
222 <br>\n
223 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
224 break;
226 case 2:
227 echo "<b>Step $state</b><br><br>\n";
228 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.
229 <br><br>\n
230 <FORM METHOD='POST'>
231 <INPUT TYPE='HIDDEN' NAME='state' VALUE='3'>
232 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
233 <INPUT TYPE='HIDDEN' NAME='inst' VALUE='$inst'>
234 <TABLE>\n
235 <TR VALIGN='TOP'><TD COLSPAN=2><font color='red'>MYSQL SERVER:</font></TD></TR>
236 <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>
237 <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>
238 <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>
239 <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>
240 <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";
241 if ($inst != 2) {
242 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>
243 <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";
244 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>";
245 echo "<TR VALIGN='TOP'><TD><span class='text'>UTF-8 Collation: </span></TD><TD colspan='2'>" .
246 "<select name='collate'>" .
247 "<option value='utf8_bin' >Bin</option>" .
248 "<option value='utf8_czech_ci' >Czech</option>" .
249 "<option value='utf8_danish_ci' >Danish</option>" .
250 "<option value='utf8_esperanto_ci' >Esperanto</option>" .
251 "<option value='utf8_estonian_ci' >Estonian</option>" .
252 "<option value='utf8_general_ci' selected>General</option>" .
253 "<option value='utf8_hungarian_ci' >Hungarian</option>" .
254 "<option value='utf8_icelandic_ci' >Icelandic</option>" .
255 "<option value='utf8_latvian_ci' >Latvian</option>" .
256 "<option value='utf8_lithuanian_ci'>Lithuanian</option>" .
257 "<option value='utf8_persian_ci' >Persian</option>" .
258 "<option value='utf8_polish_ci' >Polish</option>" .
259 "<option value='utf8_roman_ci' >Roman</option>" .
260 "<option value='utf8_romanian_ci' >Romanian</option>" .
261 "<option value='utf8_slovak_ci' >Slovak</option>" .
262 "<option value='utf8_slovenian_ci' >Slovenian</option>" .
263 "<option value='utf8_spanish2_ci' >Spanish2 (Traditional)</option>" .
264 "<option value='utf8_spanish_ci' >Spanish (Modern)</option>" .
265 "<option value='utf8_swedish_ci' >Swedish</option>" .
266 "<option value='utf8_turkish_ci' >Turkish</option>" .
267 "<option value='utf8_unicode_ci' >Unicode (German, French, Russian, Armenian, Greek)</option>" .
268 "<option value='' >None (Do not force UTF-8)</option>" .
269 "</select>" .
270 "</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>";
272 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
274 // Include a "source" site ID drop-list and a checkbox to indicate
275 // if cloning its database. When checked, do not display initial user
276 // and group stuff below.
277 $dh = opendir($OE_SITES_BASE);
278 if (!$dh) die("Cannot read directory '$OE_SITES_BASE'.");
279 $siteslist = array();
280 while (false !== ($sfname = readdir($dh))) {
281 if (substr($sfname, 0, 1) == '.') continue;
282 if ($sfname == 'CVS' ) continue;
283 if ($sfname == $site_id ) continue;
284 $sitedir = "$OE_SITES_BASE/$sfname";
285 if (!is_dir($sitedir) ) continue;
286 if (!is_file("$sitedir/sqlconf.php")) continue;
287 $siteslist[$sfname] = $sfname;
289 closedir($dh);
290 // If this is not the first site...
291 if (!empty($siteslist)) {
292 ksort($siteslist);
293 echo "<tr valign='top'>\n";
294 echo " <td class='text'>Source Site: </td>\n";
295 echo " <td class='text'><select name='source_site_id'>";
296 foreach ($siteslist as $sfname) {
297 echo "<option value='$sfname'";
298 if ($sfname == 'default') echo " selected";
299 echo ">$sfname</option>";
301 echo "</select></td>\n";
302 echo " <td class='text'>(The site directory that will be a model for the new site.)</td>\n";
303 echo "</tr>\n";
304 echo "<tr valign='top'>\n";
305 echo " <td class='text'>Clone Source Database: </td>\n";
306 echo " <td class='text'><input type='checkbox' name='clone_database' onclick='cloneClicked()' /></td>\n";
307 echo " <td class='text'>(Clone the source site's database instead of creating a fresh one.)</td>\n";
308 echo "</tr>\n";
311 echo "<TR VALIGN='TOP' class='noclone'><TD COLSPAN=2><font color='red'>OPENEMR USER:</font></TD></TR>";
312 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>
313 <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>
314 <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>
315 <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>
316 <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>
318 echo "<TR VALIGN='TOP'><TD>&nbsp;</TD></TR>";
320 echo "</TABLE>
321 <br>
322 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
323 break;
325 case 3:
327 // Form Validation
328 // (applicable if not cloning from another database)
330 $pass_step2_validation = TRUE;
331 $error_step2_message = "ERROR at ";
333 if ( ! $installer->char_is_valid($_REQUEST['server'])) {
334 $pass_step2_validation = FALSE;
335 $error_step2_message .= "Database Server Host, ";
338 if ( ! $installer->char_is_valid($_REQUEST['port'])) {
339 $pass_step2_validation = FALSE;
340 $error_step2_message .= "Database Server Port, ";
342 if ( ! $installer->char_is_valid($_REQUEST['dbname'])) {
343 $pass_step2_validation = FALSE;
344 $error_step2_message .= "Database Name, ";
346 if ( ! $installer->char_is_valid($_REQUEST['login'])) {
347 $pass_step2_validation = FALSE;
348 $error_step2_message .= "Database Login Name, ";
350 if ( ! $installer->char_is_valid($_REQUEST['pass'])) {
351 $pass_step2_validation = FALSE;
352 $error_step2_message .= "Database Login Password, ";
354 if (!$pass_step2_validation) {
355 die($error_step2_message);
359 if (empty($installer->clone_database)) {
360 if ( ! $installer->login_is_valid() ) {
361 echo "ERROR. Please pick a proper 'Login Name'.<br>\n";
362 echo "Click Back in browser to re-enter.<br>\n";
363 break;
365 if ( ! $installer->iuser_is_valid() ) {
366 echo "ERROR. The 'Initial User' field can only contain one word and no spaces.<br>\n";
367 echo "Click Back in browser to re-enter.<br>\n";
368 break;
370 if ( ! $installer->user_password_is_valid() ) {
371 echo "ERROR. Please pick a proper 'Initial User Password'.<br>\n";
372 echo "Click Back in browser to re-enter.<br>\n";
373 break;
376 if ( ! $installer->password_is_valid() ) {
377 echo "ERROR. Please pick a proper 'Password'.<br>\n";
378 echo "Click Back in browser to re-enter.<br>\n";
379 break;
382 echo "<b>Step $state</b><br><br>\n";
383 echo "Configuring OpenEMR...<br><br>\n";
385 // Skip below if database shell has already been created.
386 if ($inst != 2) {
388 echo "Connecting to MySQL Server...\n";
389 flush();
390 if ( ! $installer->root_database_connection() ) {
391 echo "ERROR. Check your login credentials.\n";
392 echo $installer->error_message;
393 break;
395 else {
396 echo "OK.<br>\n";
397 flush();
401 // Only pertinent if cloning another installation database
402 if ( ! empty($installer->clone_database)) {
404 echo "Dumping source database...";
405 flush();
406 if ( ! $installer->create_dumpfiles() ) {
407 echo $installer->error_message;
408 break;
410 else {
411 echo " OK.<br>\n";
412 flush();
416 // Only pertinent if mirroring another installation directory
417 if ( ! empty($installer->source_site_id)) {
419 echo "Creating site directory...";
420 if ( ! $installer->create_site_directory() ) {
421 echo $installer->error_message;
422 break;
424 else {
425 echo "OK.<BR>";
426 flush();
430 // Skip below if database shell has already been created.
431 if ($inst != 2) {
432 echo "Creating database...\n";
433 flush();
434 if ( ! $installer->create_database() ) {
435 echo "ERROR. Check your login credentials.\n";
436 echo $installer->error_message;
437 break;
438 } else {
439 echo "OK.<br>\n";
440 flush();
443 echo "Creating user with permissions for database...\n";
444 flush();
445 if ( ! $installer->grant_privileges() ) {
446 echo "ERROR when granting privileges to the specified user.\n";
447 echo $installer->error_message;
448 break;
449 } else {
450 echo "OK.<br>\n";
451 flush();
454 echo "Reconnecting as new user...\n";
455 flush();
456 $installer->disconnect();
457 } else {
459 echo "Connecting to MySQL Server...\n";
461 if ( ! $installer->user_database_connection() ) {
462 echo "ERROR. Check your login credentials.\n";
463 echo $installer->error_message;
464 break;
466 else {
467 echo "OK.<br>\n";
468 flush();
471 // Load the database files
472 $dump_results = $installer->load_dumpfiles();
473 if ( ! $dump_results ) {
474 echo $installer->error_message;
475 break;
476 } else {
477 echo $dump_results;
478 flush();
481 echo "Writing SQL configuration...\n";
482 flush();
483 if ( ! $installer->write_configuration_file() ) {
484 echo $installer->error_message;
485 break;
487 else {
488 echo "OK.<br>\n";
489 flush();
492 // Only pertinent if not cloning another installation database
493 if (empty($installer->clone_database)) {
495 echo "Setting version indicators...\n";
496 flush();
497 if ( ! $installer->add_version_info() ) {
498 echo "ERROR.\n";
499 echo $installer->error_message;;
500 break;
502 else {
503 echo "OK<br>\n";
504 flush();
507 echo "Writing global configuration defaults...\n";
508 flush();
509 if ( ! $installer->insert_globals() ) {
510 echo "ERROR.\n";
511 echo $installer->error_message;;
512 break;
514 else {
515 echo "OK<br>\n";
516 flush();
519 echo "Adding Initial User...\n";
520 flush();
521 if ( ! $installer->add_initial_user() ) {
522 echo $installer->error_message;
523 break;
525 echo "OK<br>\n";
526 flush();
529 if ( ! empty($installer->clone_database) ) {
530 // Database was cloned, skip ACL setup.
531 echo "Click 'continue' for further instructions.";
532 $next_state = 7;
534 else {
535 echo "\n<br>Next step will install and configure access controls (php-GACL).<br>\n";
536 $next_state = 4;
539 echo "
540 <FORM METHOD='POST'>\n
541 <INPUT TYPE='HIDDEN' NAME='state' VALUE='$next_state'>
542 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
543 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>
544 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>
545 <INPUT TYPE='HIDDEN' NAME='iuname' VALUE='$installer->iuname'>
546 <INPUT TYPE='HIDDEN' NAME='iufname' VALUE='$installer->iufname'>
547 <INPUT TYPE='HIDDEN' NAME='clone_database' VALUE='$installer->clone_database'>
548 <br>\n
549 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
551 break;
552 case 4:
553 echo "<b>Step $state</b><br><br>\n";
554 echo "Installing and Configuring Access Controls (php-GACL)...<br><br>";
556 if ( ! $installer->install_gacl() ) {
557 echo $installer->error_message;
558 break;
560 else {
561 // display the status information for gacl setup
562 echo $installer->debug_message;
565 echo "Gave the '$installer->iuser' user (password is '$installer->iuserpass') administrator access.<br><br>";
567 echo "Done installing and configuring access controls (php-GACL).<br>";
568 echo "Next step will configure PHP.";
570 echo "<br><FORM METHOD='POST'>\n
571 <INPUT TYPE='HIDDEN' NAME='state' VALUE='5'>\n
572 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
573 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>\n
574 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>\n
575 <br>\n
576 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
578 break;
580 case 5:
581 echo "<b>Step $state</b><br><br>\n";
582 echo "Configuration of PHP...<br><br>\n";
583 echo "We recommend making the following changes to your PHP installation, which can normally be done by editing the php.ini configuration file:\n";
584 echo "<ul>";
585 $gotFileFlag = 0;
586 if (version_compare(PHP_VERSION, '5.2.4', '>=')) {
587 $phpINIfile = php_ini_loaded_file();
588 if ($phpINIfile) {
589 echo "<li><font color='green'>Your php.ini file can be found at ".$phpINIfile."</font></li>\n";
590 $gotFileFlag = 1;
593 echo "<li>","To ensure proper functioning of OpenEMR you must make sure that PHP settings include:";
594 echo "<table class='phpset'><tr><th>Setting</th><th>Required value</th><th>Current value</th></tr>";
595 echo "<tr><td>short_open_tag </td><td>Off</td><td>", ini_get('short_open_tag')?'On':'Off', "</td></tr>\n";
596 echo "<tr><td>display_errors </td><td>Off</td><td>", ini_get('display_errors')?'On':'Off', "</td></tr>\n";
597 echo "<tr><td>register_globals </td><td>Off</td><td>", ini_get('register_globals')?'On':'Off', "</td></tr>\n";
598 echo "<tr><td>max_input_vars </td><td>at least 3000</td><td>", ini_get('max_input_vars'), "</td></tr>\n";
599 echo "<tr><td>max_execution_time </td><td>at least 60</td><td>", ini_get('max_execution_time'), "</td></tr>\n";
600 echo "<tr><td>max_input_time </td><td>at least 90</td><td>", ini_get('max_input_time'), "</td></tr>\n";
601 echo "<tr><td>post_max_size </td><td>at least 30M</td><td>", ini_get('post_max_size'), "</td></tr>\n";
602 echo "<tr><td>memory_limit </td><td>at least 128M</td><td>", ini_get('memory_limit'), "</td></tr>\n";
603 echo "</table>";
604 echo "</li>";
606 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";
607 if (!$gotFileFlag) {
608 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";
610 echo "</ul>";
612 echo "<br>We recommend you print these instructions for future reference.<br><br>";
613 echo "Next step will configure Apache web server.";
615 echo "<br><FORM METHOD='POST'>\n
616 <INPUT TYPE='HIDDEN' NAME='state' VALUE='6'>\n
617 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
618 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>\n
619 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>\n
620 <br>\n
621 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
623 break;
625 case 6:
626 echo "<b>Step $state</b><br><br>\n";
627 echo "Configuration of Apache web server...<br><br>\n";
628 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
629 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>
630 &nbsp;&nbsp;&lt;Directory \"".realpath(dirname(__FILE__))."\"&gt;<br>
631 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride FileInfo<br>
632 &nbsp;&nbsp;&lt;/Directory&gt;<br>
633 &nbsp;&nbsp;&lt;Directory \"".realpath(dirname(__FILE__))."/sites\"&gt;<br>
634 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AllowOverride None<br>
635 &nbsp;&nbsp;&lt;/Directory&gt;<br>
636 &nbsp;&nbsp;&lt;Directory \"".preg_replace("/${site_id}/","*",realpath($docsDirectory))."\"&gt;<br>
637 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
638 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
639 &nbsp;&nbsp;&lt;/Directory&gt;<br>
640 &nbsp;&nbsp;&lt;Directory \"".preg_replace("/${site_id}/","*",realpath($billingDirectory))."\"&gt;<br>
641 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
642 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
643 &nbsp;&nbsp;&lt;/Directory&gt;<br>
644 &nbsp;&nbsp;&lt;Directory \"".preg_replace("/${site_id}/","*",realpath($billingDirectory2))."\"&gt;<br>
645 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;order deny,allow<br>
646 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Deny from all<br>
647 &nbsp;&nbsp;&lt;/Directory&gt;<br><br>";
649 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";
650 echo "<br>We recommend you print these instructions for future reference.<br><br>";
651 echo "Click 'continue' for further instructions.";
653 echo "<br><FORM METHOD='POST'>\n
654 <INPUT TYPE='HIDDEN' NAME='state' VALUE='7'>\n
655 <INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>\n
656 <INPUT TYPE='HIDDEN' NAME='iuser' VALUE='$installer->iuser'>\n
657 <INPUT TYPE='HIDDEN' NAME='iuserpass' VALUE='$installer->iuserpass'>\n
658 <br>\n
659 <INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>\n";
661 break;
663 case 0:
664 default:
665 echo "<p>Welcome to OpenEMR. This utility will step you through the installation and configuration of OpenEMR for your practice.</p>\n";
666 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";
668 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";
670 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>";
672 if ($checkPermissions) {
673 echo "<p>We will now ensure correct file and directory permissions before starting installation:</p>\n";
674 echo "<FONT COLOR='green'>Ensuring following files are world-writable...</FONT><br>\n";
675 $errorWritable = 0;
676 foreach ($writableFileList as $tempFile) {
677 if (is_writable($tempFile)) {
678 echo "'".realpath($tempFile)."' file is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
680 else {
681 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open file '".realpath($tempFile)."' for writing.<br>\n";
682 echo "(configure file permissions; see below for further instructions)</p>\n";
683 $errorWritable = 1;
686 if ($errorWritable) {
687 echo "<p><FONT COLOR='red'>You can't proceed until all above files are ready (world-writable).</FONT><br>\n";
688 echo "In linux, recommend changing file permissions with the 'chmod 666 filename' command.<br>\n";
689 echo "Fix above file permissions and then click the 'Check Again' button to re-check files.<br>\n";
690 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
691 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
692 break;
695 echo "<br><FONT COLOR='green'>Ensuring following directories have proper permissions...</FONT><br>\n";
696 $errorWritable = 0;
697 foreach ($writableDirList as $tempDir) {
698 if (is_writable($tempDir)) {
699 echo "'".realpath($tempDir)."' directory is <FONT COLOR='green'><b>ready</b></FONT>.<br>\n";
701 else {
702 echo "<p><FONT COLOR='red'>UNABLE</FONT> to open directory '".realpath($tempDir)."' for writing by web server.<br>\n";
703 echo "(configure directory permissions; see below for further instructions)</p>\n";
704 $errorWritable = 1;
707 if ($errorWritable) {
708 echo "<p><FONT COLOR='red'>You can't proceed until all directories are ready.</FONT><br>\n";
709 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";
710 echo "Fix above directory permissions and then click the 'Check Again' button to re-check directories.<br>\n";
711 echo "<FORM METHOD='POST'><INPUT TYPE='SUBMIT' VALUE='Check Again'></p>" .
712 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'></FORM><br>\n";
713 break;
716 echo "<br>All required files and directories have been verified. Click to continue installation.<br>\n";
718 else {
719 echo "<br>Click to continue installation.<br>\n";
722 echo "<FORM METHOD='POST'><INPUT TYPE='HIDDEN' NAME='state' VALUE='1'>" .
723 "<INPUT TYPE='HIDDEN' NAME='site' VALUE='$site_id'>" .
724 "<INPUT TYPE='SUBMIT' VALUE='Continue'><br></FORM><br>";
730 </span>
732 </BODY>
733 </HTML>