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