]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/setup-config.php
Wordpress 2.9
[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  * Disable error reporting
21  *
22  * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) f
23 or debugging
24  */
25 error_reporting(0);
26
27 /**#@+
28  * These three defines are required to allow us to use require_wp_db() to load
29  * the database class while being wp-content/db.php aware.
30  * @ignore
31  */
32 define('ABSPATH', dirname(dirname(__FILE__)).'/');
33 define('WPINC', 'wp-includes');
34 define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
35 /**#@-*/
36
37 require_once(ABSPATH . WPINC . '/compat.php');
38 require_once(ABSPATH . WPINC . '/functions.php');
39 require_once(ABSPATH . WPINC . '/classes.php');
40
41 if (!file_exists(ABSPATH . 'wp-config-sample.php'))
42         wp_die('Sorry, I need a wp-config-sample.php file to work from. Please re-upload this file from your WordPress installation.');
43
44 $configFile = file(ABSPATH . 'wp-config-sample.php');
45
46 // Check if wp-config.php has been created
47 if (file_exists(ABSPATH . 'wp-config.php'))
48         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>");
49
50 // Check if wp-config.php exists above the root directory but is not part of another install
51 if (file_exists(ABSPATH . '../wp-config.php') && ! file_exists(ABSPATH . '../wp-settings.php'))
52         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>");
53
54 if ( version_compare( '4.3', phpversion(), '>' ) )
55         wp_die( sprintf( /*WP_I18N_OLD_PHP*/'Your server is running PHP version %s but WordPress requires at least 4.3.'/*/WP_I18N_OLD_PHP*/, phpversion() ) );
56
57 if ( !extension_loaded('mysql') && !file_exists(ABSPATH . 'wp-content/db.php') )
58         wp_die( /*WP_I18N_OLD_MYSQL*/'Your PHP installation appears to be missing the MySQL extension which is required by WordPress.'/*/WP_I18N_OLD_MYSQL*/ );
59
60 if (isset($_GET['step']))
61         $step = $_GET['step'];
62 else
63         $step = 0;
64
65 /**
66  * Display setup wp-config.php file header.
67  *
68  * @ignore
69  * @since 2.3.0
70  * @package WordPress
71  * @subpackage Installer_WP_Config
72  */
73 function display_header() {
74         header( 'Content-Type: text/html; charset=utf-8' );
75 ?>
76 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
77 <html xmlns="http://www.w3.org/1999/xhtml">
78 <head>
79 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
80 <title>WordPress &rsaquo; Setup Configuration File</title>
81 <link rel="stylesheet" href="css/install.css" type="text/css" />
82
83 </head>
84 <body>
85 <h1 id="logo"><img alt="WordPress" src="images/wordpress-logo.png" /></h1>
86 <?php
87 }//end function display_header();
88
89 switch($step) {
90         case 0:
91                 display_header();
92 ?>
93
94 <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>
95 <ol>
96         <li>Database name</li>
97         <li>Database username</li>
98         <li>Database password</li>
99         <li>Database host</li>
100         <li>Table prefix (if you want to run more than one WordPress in a single database) </li>
101 </ol>
102 <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>
103 <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>
104
105 <p class="step"><a href="setup-config.php?step=1" class="button">Let&#8217;s go!</a></p>
106 <?php
107         break;
108
109         case 1:
110                 display_header();
111         ?>
112 <form method="post" action="setup-config.php?step=2">
113         <p>Below you should enter your database connection details. If you're not sure about these, contact your host. </p>
114         <table class="form-table">
115                 <tr>
116                         <th scope="row"><label for="dbname">Database Name</label></th>
117                         <td><input name="dbname" id="dbname" type="text" size="25" value="wordpress" /></td>
118                         <td>The name of the database you want to run WP in. </td>
119                 </tr>
120                 <tr>
121                         <th scope="row"><label for="uname">User Name</label></th>
122                         <td><input name="uname" id="uname" type="text" size="25" value="username" /></td>
123                         <td>Your MySQL username</td>
124                 </tr>
125                 <tr>
126                         <th scope="row"><label for="pwd">Password</label></th>
127                         <td><input name="pwd" id="pwd" type="text" size="25" value="password" /></td>
128                         <td>...and MySQL password.</td>
129                 </tr>
130                 <tr>
131                         <th scope="row"><label for="dbhost">Database Host</label></th>
132                         <td><input name="dbhost" id="dbhost" type="text" size="25" value="localhost" /></td>
133                         <td>99% chance you won't need to change this value.</td>
134                 </tr>
135                 <tr>
136                         <th scope="row"><label for="prefix">Table Prefix</label></th>
137                         <td><input name="prefix" id="prefix" type="text" id="prefix" value="wp_" size="25" /></td>
138                         <td>If you want to run multiple WordPress installations in a single database, change this.</td>
139                 </tr>
140         </table>
141         <p class="step"><input name="submit" type="submit" value="Submit" class="button" /></p>
142 </form>
143 <?php
144         break;
145
146         case 2:
147         $dbname  = trim($_POST['dbname']);
148         $uname   = trim($_POST['uname']);
149         $passwrd = trim($_POST['pwd']);
150         $dbhost  = trim($_POST['dbhost']);
151         $prefix  = trim($_POST['prefix']);
152         if (empty($prefix)) $prefix = 'wp_';
153
154         // Test the db connection.
155         /**#@+
156          * @ignore
157          */
158         define('DB_NAME', $dbname);
159         define('DB_USER', $uname);
160         define('DB_PASSWORD', $passwrd);
161         define('DB_HOST', $dbhost);
162         /**#@-*/
163
164         // We'll fail here if the values are no good.
165         require_wp_db();
166         if ( !empty($wpdb->error) )
167                 wp_die($wpdb->error->get_error_message());
168
169         foreach ($configFile as $line_num => $line) {
170                 switch (substr($line,0,16)) {
171                         case "define('DB_NAME'":
172                                 $configFile[$line_num] = str_replace("putyourdbnamehere", $dbname, $line);
173                                 break;
174                         case "define('DB_USER'":
175                                 $configFile[$line_num] = str_replace("'usernamehere'", "'$uname'", $line);
176                                 break;
177                         case "define('DB_PASSW":
178                                 $configFile[$line_num] = str_replace("'yourpasswordhere'", "'$passwrd'", $line);
179                                 break;
180                         case "define('DB_HOST'":
181                                 $configFile[$line_num] = str_replace("localhost", $dbhost, $line);
182                                 break;
183                         case '$table_prefix  =':
184                                 $configFile[$line_num] = str_replace('wp_', $prefix, $line);
185                                 break;
186                 }
187         }
188         if ( ! is_writable(ABSPATH) ) :
189                 display_header();
190 ?>
191 <p>Sorry, but I can't write the <code>wp-config.php</code> file.</p>
192 <p>You can create the <code>wp-config.php</code> manually and paste the following text into it.</p>
193 <textarea cols="90" rows="15"><?php
194                 foreach( $configFile as $line ) {
195                         echo htmlentities($line);
196                 }
197 ?></textarea>
198 <p>After you've done that, click "Run the install."</p>
199 <p class="step"><a href="install.php" class="button">Run the install</a></p>
200 <?php
201         else :
202                 $handle = fopen(ABSPATH . 'wp-config.php', 'w');
203                 foreach( $configFile as $line ) {
204                         fwrite($handle, $line);
205                 }
206                 fclose($handle);
207                 chmod(ABSPATH . 'wp-config.php', 0666);
208                 display_header();
209 ?>
210 <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>
211
212 <p class="step"><a href="install.php" class="button">Run the install</a></p>
213 <?php
214         endif;
215         break;
216 }
217 ?>
218 </body>
219 </html>