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