-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwpinstall.php
executable file
·147 lines (126 loc) · 6.16 KB
/
wpinstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/php
<?php
/**
* Main index page
* @package default
* @author Marko Tomic <[email protected]>
* @copyright Copyright 2013 Marko Tomic
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version 1.0.0
* This file is part of wordpress-install.
*
* wordpress-install is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wordpress-install is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with wordpress-install. If not, see <http://www.gnu.org/licenses/>.
*/
require_once('includes/tools.inc.php');
$tab = (chr(9));
$WEBROOT = promptUser("Your webroot directory? (Include trailing slash. i.e. /Users/johnsmith/Sites/mysite/www/)");
$VHOSTPATH = promptUser("Enter your vhost file path: (i.e. /etc/apache2/users/mysite.conf)");
$SERVERNAME = promptUser("What is your development server name? DO NOT include http:// (i.e. mysite.dev)");
$APACHEUSER = promptUser("What is the user apache runs under? (i.e. www or yourusername)");
$MYSQLDB = promptUser("Enter MySQL Database name:");
$MYSQLHOST = promptUser("Enter MySQL host:", "127.0.0.1");
$MYSQLUSER = promptUser("Enter MySQL user:", "root");
$MYSQLPWD = promptUser("Enter MySQL password: (leave blank if not sure)", "");
//Need this to emulate the browser-based installation
$_SERVER['HTTP_HOST'] = $SERVERNAME;
$_SERVER['REQUEST_URI'] = "/";
msg('Creating DB ...');
if(strlen($MYSQLPWD)) {
exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -p" . $MYSQLPWD . " -e 'CREATE DATABASE IF NOT EXISTS '" . $MYSQLDB . ";");
} else {
exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -e 'CREATE DATABASE IF NOT EXISTS '" . $MYSQLDB . ";");
}
msg('Downloading Wordpress ...');
exc('wget http://wordpress.org/latest.tar.gz');
msg('Unpacking WordPresss ...');
exc('tar xzf latest.tar.gz');
msg('moving wordpress into the webroot ' . $WEBROOT);
//make sure webroot exists
exc('mkdir -p "' . $WEBROOT . '"');
exc('cp -r wordpress/* "' . $WEBROOT . '"');
exc('rm -rf wordpress');
msg("Setup folder permissions..");
//set folder permissions to apache user
exc('chown -R ' . $APACHEUSER . ':staff ' . $WEBROOT);
//add local site to the hosts file
msg("Add entry in /etc/hosts file...");
exc('echo "127.0.0.1\t' . $SERVERNAME . '" >> /etc/hosts');
msg("Setting up the vhost...");
//set up apache vhost
$VHOST='NameVirtualHost *:80' . PHP_EOL . PHP_EOL;
$VHOST.='<Directory ' . $WEBROOT . '>' . PHP_EOL;
$VHOST.=$tab . 'Options Indexes FollowSymLinks MultiViews' . PHP_EOL;
$VHOST.=$tab . 'AllowOverride All' . PHP_EOL;
$VHOST.=$tab . 'Order allow,deny' . PHP_EOL;
$VHOST.=$tab . 'Allow from all' . PHP_EOL;
$VHOST.='</Directory>' . PHP_EOL;
$VHOST.='<VirtualHost *:80>' . PHP_EOL;
$VHOST.=$tab . 'DocumentRoot ' . $WEBROOT . PHP_EOL;
$VHOST.=$tab . 'ServerName ' . $SERVERNAME . PHP_EOL;
$VHOST.=$tab . 'DirectoryIndex index.php' . PHP_EOL;
$VHOST.='</VirtualHost>';
$fw = fopen($VHOSTPATH, "w");
fwrite($fw, $VHOST);
msg("Setting up the config file...");
//Now let's set up the config file
$config_file = file($WEBROOT . 'wp-config-sample.php');
$secret_keys = file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' );
$secret_keys = explode( "\n", $secret_keys );
foreach ( $secret_keys as $k => $v ) {
$secret_keys[$k] = substr( $v, 28, 64 );
}
array_pop($secret_keys);
$config_file = str_replace('database_name_here', $MYSQLDB, $config_file);
$config_file = str_replace('username_here', $MYSQLUSER, $config_file);
$config_file = str_replace('password_here', $MYSQLPWD, $config_file);
$config_file = str_replace('localhost', $MYSQLHOST, $config_file);
$config_file = str_replace("'AUTH_KEY', 'put your unique phrase here'", "'AUTH_KEY', '{$secret_keys[0]}'", $config_file);
$config_file = str_replace("'SECURE_AUTH_KEY', 'put your unique phrase here'", "'SECURE_AUTH_KEY', '{$secret_keys[1]}'", $config_file);
$config_file = str_replace("'LOGGED_IN_KEY', 'put your unique phrase here'", "'LOGGED_IN_KEY', '{$secret_keys[2]}'", $config_file);
$config_file = str_replace("'NONCE_KEY', 'put your unique phrase here'", "'NONCE_KEY', '{$secret_keys[3]}'", $config_file);
$config_file = str_replace("'AUTH_SALT', 'put your unique phrase here'", "'AUTH_SALT', '{$secret_keys[4]}'", $config_file);
$config_file = str_replace("'SECURE_AUTH_SALT', 'put your unique phrase here'", "'SECURE_AUTH_SALT', '{$secret_keys[5]}'", $config_file);
$config_file = str_replace("'LOGGED_IN_SALT', 'put your unique phrase here'", "'LOGGED_IN_SALT', '{$secret_keys[6]}'", $config_file);
$config_file = str_replace("'NONCE_SALT', 'put your unique phrase here'", "'NONCE_SALT', '{$secret_keys[7]}'", $config_file);
if(file_exists($WEBROOT .'wp-config.php')) {
unlink($WEBROOT .'wp-config.php');
}
$fw = fopen($WEBROOT . 'wp-config.php', "a");
foreach ( $config_file as $line_num => $line ) {
fwrite($fw, $line);
}
msg("Installing WordPress...");
define('ABSPATH', $WEBROOT);
define('WP_CONTENT_DIR', 'wp-content/');
define('WPINC', 'wp-includes');
define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
define('WP_USE_THEMES', true);
define('DB_NAME', $MYSQLDB);
define('DB_USER', $MYSQLUSER);
define('DB_PASSWORD', $MYSQLPWD);
define('DB_HOST', $MYSQLHOST);
$_GET['step'] = 2;
$_POST['weblog_title'] = "My Test Blog";
$_POST['user_name'] = "admin";
$_POST['admin_email'] = "[email protected]";
$_POST['blog_public'] = true;
$_POST['admin_password'] = "admin";
$_POST['admin_password2'] = "admin";
require_once(ABSPATH . 'wp-admin/install.php');
require_once(ABSPATH . 'wp-load.php');
require_once(ABSPATH . WPINC . '/class-wp-walker.php');
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
msg('restarting apache');
exc('apachectl -k graceful');
msg('Your WordPress site is ready. Navigate to http://' . $SERVERNAME . ' in your web browser');