raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Retrieves and creates the wp-config.php file.
mp-wp_genesis 4 *
mp-wp_genesis 5 * The permissions for the base directory must allow for writing files in order
mp-wp_genesis 6 * for the wp-config.php to be created using this page.
mp-wp_genesis 7 *
mp-wp_genesis 8 * @package WordPress
mp-wp_genesis 9 * @subpackage Administration
mp-wp_genesis 10 */
mp-wp_genesis 11
mp-wp_genesis 12 /**
mp-wp_genesis 13 * We are installing.
mp-wp_genesis 14 *
mp-wp_genesis 15 * @package WordPress
mp-wp_genesis 16 */
mp-wp_genesis 17 define('WP_INSTALLING', true);
mp-wp_genesis 18
mp-wp_genesis 19 /**#@+
mp-wp_genesis 20 * These three defines are required to allow us to use require_wp_db() to load
mp-wp_genesis 21 * the database class while being wp-content/db.php aware.
mp-wp_genesis 22 * @ignore
mp-wp_genesis 23 */
mp-wp_genesis 24 define('ABSPATH', dirname(dirname(__FILE__)).'/');
mp-wp_genesis 25 define('WPINC', 'wp-includes');
mp-wp_genesis 26 define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
mp-wp_genesis 27 /**#@-*/
mp-wp_genesis 28
mp-wp_genesis 29 require_once('../wp-includes/compat.php');
mp-wp_genesis 30 require_once('../wp-includes/functions.php');
mp-wp_genesis 31 require_once('../wp-includes/classes.php');
mp-wp_genesis 32
mp-wp_genesis 33 if (!file_exists('../wp-config-sample.php'))
mp-wp_genesis 34 wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
mp-wp_genesis 35
mp-wp_genesis 36 $configFile = file('../wp-config-sample.php');
mp-wp_genesis 37
mp-wp_genesis 38 if ( !is_writable('../'))
mp-wp_genesis 39 wp_die("Sorry, I can't write to the directory. You'll have to either change the permissions on your WordPress directory or create your wp-config.php manually.");
mp-wp_genesis 40
mp-wp_genesis 41 // Check if wp-config.php has been created
mp-wp_genesis 42 if (file_exists('../wp-config.php'))
mp-wp_genesis 43 wp_die("<p>The file 'wp-config.php' already exists. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href='install.php'>installing now</a>.</p>");
mp-wp_genesis 44
mp-wp_genesis 45 // Check if wp-config.php exists above the root directory
mp-wp_genesis 46 if (file_exists('../../wp-config.php') && ! file_exists('../../wp-load.php'))
mp-wp_genesis 47 wp_die("<p>The file 'wp-config.php' already exists one level above your WordPress installation. If you need to reset any of the configuration items in this file, please delete it first. You may try <a href='install.php'>installing now</a>.</p>");
mp-wp_genesis 48
mp-wp_genesis 49 if (isset($_GET['step']))
mp-wp_genesis 50 $step = $_GET['step'];
mp-wp_genesis 51 else
mp-wp_genesis 52 $step = 0;
mp-wp_genesis 53
mp-wp_genesis 54 /**
mp-wp_genesis 55 * Display setup wp-config.php file header.
mp-wp_genesis 56 *
mp-wp_genesis 57 * @ignore
mp-wp_genesis 58 * @since 2.3.0
mp-wp_genesis 59 * @package WordPress
mp-wp_genesis 60 * @subpackage Installer_WP_Config
mp-wp_genesis 61 */
mp-wp_genesis 62 function display_header() {
mp-wp_genesis 63 header( 'Content-Type: text/html; charset=utf-8' );
mp-wp_genesis 64 ?>
mp-wp_genesis 65 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
mp-wp_genesis 66 <html xmlns="http://www.w3.org/1999/xhtml">
mp-wp_genesis 67 <head>
mp-wp_genesis 68 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
mp-wp_genesis 69 <title>WordPress &rsaquo; Setup Configuration File</title>
mp-wp_genesis 70 <link rel="stylesheet" href="css/install.css" type="text/css" />
mp-wp_genesis 71
mp-wp_genesis 72 </head>
mp-wp_genesis 73 <body>
mp-wp_update-imag... 74 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.svg" /></h1>
mp-wp_genesis 75 <?php
mp-wp_genesis 76 }//end function display_header();
mp-wp_genesis 77
mp-wp_genesis 78 switch($step) {
mp-wp_genesis 79 case 0:
mp-wp_genesis 80 display_header();
mp-wp_genesis 81 ?>
mp-wp_genesis 82
mp-wp_genesis 83 <p>Welcome to WordPress. Before getting started, we need some information on the database. You will need to know the following items before proceeding.</p>
mp-wp_genesis 84 <ol>
mp-wp_genesis 85 <li>Database name</li>
mp-wp_genesis 86 <li>Database username</li>
mp-wp_genesis 87 <li>Database password</li>
mp-wp_genesis 88 <li>Database host</li>
mp-wp_genesis 89 <li>Table prefix (if you want to run more than one WordPress in a single database) </li>
mp-wp_genesis 90 </ol>
mp-wp_genesis 91 <p><strong>If for any reason this automatic file creation doesn't work, don't worry. All this does is fill in the database information to a configuration file. You may also simply open <code>wp-config-sample.php</code> in a text editor, fill in your information, and save it as <code>wp-config.php</code>. </strong></p>
mp-wp_genesis 92 <p>In all likelihood, these items were supplied to you by your Web Host. If you do not have this information, then you will need to contact them before you can continue. If you&#8217;re all ready&hellip;</p>
mp-wp_genesis 93
mp-wp_genesis 94 <p class="step"><a href="setup-config.php?step=1" class="button">Let&#8217;s go!</a></p>
mp-wp_genesis 95 <?php
mp-wp_genesis 96 break;
mp-wp_genesis 97
mp-wp_genesis 98 case 1:
mp-wp_genesis 99 display_header();
mp-wp_genesis 100 ?>
mp-wp_genesis 101 <form method="post" action="setup-config.php?step=2">
mp-wp_genesis 102 <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
mp-wp_genesis 103 <table class="form-table">
mp-wp_genesis 104 <tr>
mp-wp_genesis 105 <th scope="row"><label for="dbname">Database Name</label></th>
mp-wp_genesis 106 <td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
mp-wp_genesis 107 <td>The name of the database you want to run WP in. </td>
mp-wp_genesis 108 </tr>
mp-wp_genesis 109 <tr>
mp-wp_genesis 110 <th scope="row"><label for="uname">User Name</label></th>
mp-wp_genesis 111 <td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
mp-wp_genesis 112 <td>Your MySQL username</td>
mp-wp_genesis 113 </tr>
mp-wp_genesis 114 <tr>
mp-wp_genesis 115 <th scope="row"><label for="pwd">Password</label></th>
mp-wp_genesis 116 <td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
mp-wp_genesis 117 <td>...and MySQL password.</td>
mp-wp_genesis 118 </tr>
mp-wp_genesis 119 <tr>
mp-wp_genesis 120 <th scope="row"><label for="dbhost">Database Host</label></th>
mp-wp_genesis 121 <td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
mp-wp_genesis 122 <td>99% chance you won't need to change this value.</td>
mp-wp_genesis 123 </tr>
mp-wp_genesis 124 <tr>
mp-wp_genesis 125 <th scope="row"><label for="prefix">Table Prefix</label></th>
mp-wp_genesis 126 <td><input name="prefix" id="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
mp-wp_genesis 127 <td>If you want to run multiple WordPress installations in a single database, change this.</td>
mp-wp_genesis 128 </tr>
mp-wp_genesis 129 </table>
mp-wp_genesis 130 <p class="step"><input name="submit" type="submit" value="Submit" class="button" /></p>
mp-wp_genesis 131 </form>
mp-wp_genesis 132 <?php
mp-wp_genesis 133 break;
mp-wp_genesis 134
mp-wp_genesis 135 case 2:
mp-wp_genesis 136 $dbname = trim($_POST['dbname']);
mp-wp_genesis 137 $uname = trim($_POST['uname']);
mp-wp_genesis 138 $passwrd = trim($_POST['pwd']);
mp-wp_genesis 139 $dbhost = trim($_POST['dbhost']);
mp-wp_genesis 140 $prefix = trim($_POST['prefix']);
mp-wp_genesis 141 if (empty($prefix)) $prefix = 'wp_';
mp-wp_genesis 142
mp-wp_genesis 143 // Test the db connection.
mp-wp_genesis 144 /**#@+
mp-wp_genesis 145 * @ignore
mp-wp_genesis 146 */
mp-wp_genesis 147 define('DB_NAME', $dbname);
mp-wp_genesis 148 define('DB_USER', $uname);
mp-wp_genesis 149 define('DB_PASSWORD', $passwrd);
mp-wp_genesis 150 define('DB_HOST', $dbhost);
mp-wp_genesis 151 /**#@-*/
mp-wp_genesis 152
mp-wp_genesis 153 // We'll fail here if the values are no good.
mp-wp_genesis 154 require_wp_db();
mp-wp_genesis 155 if ( !empty($wpdb->error) )
mp-wp_genesis 156 wp_die($wpdb->error->get_error_message());
mp-wp_genesis 157
mp-wp_genesis 158 $handle = fopen('../wp-config.php', 'w');
mp-wp_genesis 159
mp-wp_genesis 160 foreach ($configFile as $line_num => $line) {
mp-wp_genesis 161 switch (substr($line,0,16)) {
mp-wp_genesis 162 case "define('DB_NAME'":
mp-wp_genesis 163 fwrite($handle, str_replace("putyourdbnamehere", $dbname, $line));
mp-wp_genesis 164 break;
mp-wp_genesis 165 case "define('DB_USER'":
mp-wp_genesis 166 fwrite($handle, str_replace("'usernamehere'", "'$uname'", $line));
mp-wp_genesis 167 break;
mp-wp_genesis 168 case "define('DB_PASSW":
mp-wp_genesis 169 fwrite($handle, str_replace("'yourpasswordhere'", "'$passwrd'", $line));
mp-wp_genesis 170 break;
mp-wp_genesis 171 case "define('DB_HOST'":
mp-wp_genesis 172 fwrite($handle, str_replace("localhost", $dbhost, $line));
mp-wp_genesis 173 break;
mp-wp_genesis 174 case '$table_prefix =':
mp-wp_genesis 175 fwrite($handle, str_replace('wp_', $prefix, $line));
mp-wp_genesis 176 break;
mp-wp_genesis 177 default:
mp-wp_genesis 178 fwrite($handle, $line);
mp-wp_genesis 179 }
mp-wp_genesis 180 }
mp-wp_genesis 181 fclose($handle);
mp-wp_genesis 182 chmod('../wp-config.php', 0666);
mp-wp_genesis 183
mp-wp_genesis 184 display_header();
mp-wp_genesis 185 ?>
mp-wp_genesis 186 <p>All right sparky! You've made it through this part of the installation. WordPress can now communicate with your database. If you are ready, time now to&hellip;</p>
mp-wp_genesis 187
mp-wp_genesis 188 <p class="step"><a href="install.php" class="button">Run the install</a></p>
mp-wp_genesis 189 <?php
mp-wp_genesis 190 break;
mp-wp_genesis 191 }
mp-wp_genesis 192 ?>
mp-wp_genesis 193 </body>
mp-wp_genesis 194 </html>