Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php
  3. /**
  4. * Main index page
  5. * @package default
  6. * @author Marko Tomic <marko@markomedia.com.au>
  7. * @copyright Copyright 2013 Marko Tomic
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version 1.0.0
  10. * This file is part of wordpress-install.
  11. *
  12. * wordpress-install is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation, either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * wordpress-install is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with wordpress-install. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. require_once('includes/tools.inc.php');
  26. $tab = (chr(9));
  27.  
  28. $SERVERNAME = promptUser("Nama Domain ? TANPA http:// ( mysite.com)");
  29. $APACHEUSER = promptUser("User Webserver ? (i.e. www-data , nginx , apache ");
  30. $MYSQLDB = promptUser("Nama Database Untuk WordPress :");
  31. $MYSQLPWD = promptUser("Enter MySQL password: ( root password )", "");
  32. $MYSQLHOST ='localhost';
  33. $MYSQLUSER = 'root';
  34. $WEBROOT = '/var/www/html/'.$SERVERNAME.'/';
  35. $VHOSTPATH = '/etc/nginx/conf.d/virtual.conf';
  36. $RT = '/root/wordpress.txt';
  37.  
  38. //Need this to emulate the browser-based installation
  39. $_SERVER['HTTP_HOST'] = $SERVERNAME;
  40. $_SERVER['REQUEST_URI'] = "/";
  41.  
  42. msg('Creating DB ...');
  43. if(strlen($MYSQLPWD)) {
  44. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -p" . $MYSQLPWD . " -e 'CREATE DATABASE IF NOT EXISTS '" . $MYSQLDB . ";");
  45. } else {
  46. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -e 'CREATE DATABASE IF NOT EXISTS '" . $MYSQLDB . ";");
  47. }
  48. msg('Creating USER DB ...');
  49. // Create Random password
  50. $seed = str_split('abcdefghijklmnopqrstuvwxyz'
  51. .'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  52. .'0123456789'); // and any other characters
  53. shuffle($seed); // probably optional since array_is randomized; this may be redundant
  54. $rand = '';
  55. $usrrand = '';
  56. $wppwd = '';
  57. foreach (array_rand($seed, 8) as $k) $rand .= $seed[$k];
  58. foreach (array_rand($seed, 3) as $k) $usrrand .= $seed[$k];
  59. foreach (array_rand($seed, 8) as $k) $wppwd .= $seed[$k];
  60. $SUB_SQLPWD = "'".$rand."'";
  61. $MYSQLPWD = $SUB_MYSQLPWD;
  62.  
  63. // CREATE USER IF NOT EXISTS 'hora'@'localhost' IDENTIFIED BY 'superhero';
  64. $SUB_MYSQLUSR = substr($SERVERNAME,1,3);
  65. $MYSQLUSR = "'".$SUB_MYSQLUSR."_".$usrrand."'";
  66. if(strlen($MYSQLPWD)) {
  67. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -p" . $MYSQLPWD . " -e 'CREATE USER IF NOT EXISTS " . $MYSQLUSR . "@'localhost' IDENTIFIED BY " . $SQLPWD . "';");
  68. } else {
  69. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -e 'CREATE USER IF NOT EXISTS '" . $MYSQLUSR . "@'localhost' IDENTIFIED BY " . $SQLPWD . ";");
  70. }
  71. msg('Give User Privallage ...');
  72. //GRANT ALL PRIVILEGES ON namadatabase.* TO 'user'@'localhost';
  73.  
  74. if(strlen($MYSQLPWD)) {
  75. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -p" . $MYSQLPWD . " -e 'GRANT ALL PRIVILEGES ON '" . $MYSQLDB . ".* TO " . $MYSQLUSR ."@'localhost';");
  76. } else {
  77. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -e 'GRANT ALL PRIVILEGES ON '" . $MYSQLDB . ".* TO ". $MYSQLUSR ."@'localhost';");
  78. }
  79.  
  80. msg('Downloading Wordpress ...');
  81. exc('wget http://wordpress.org/latest.tar.gz');
  82.  
  83. msg('Unpacking WordPresss ...');
  84. exc('tar xzf latest.tar.gz');
  85.  
  86. msg('moving wordpress into the webroot ' . $WEBROOT);
  87. //make sure webroot exists
  88. exc('mkdir -p "' . $WEBROOT . '"');
  89. exc('cp -r wordpress/* "' . $WEBROOT . '"');
  90. exc('rm -rf wordpress');
  91.  
  92. msg("Setup folder permissions..");
  93. //set folder permissions to apache user
  94. exc('chown -R ' . $APACHEUSER . ':staff ' . $WEBROOT);
  95.  
  96. //add local site to the hosts file
  97. msg("Add entry in /etc/hosts file...");
  98.  
  99. msg("Setting up the vhost...");
  100. //set up NGINX vhost
  101. $VHOST='server {'. PHP_EOL;
  102. $VHOST.=$tab.'listen 80;'. PHP_EOL;
  103. $VHOST.=$tab.'root '. $WEBROOT . ';'. PHP_EOL;
  104. $VHOST.=$tab.'server_name '.$SERVERNAME.' www.'.$SERVERNAME.';'. PHP_EOL;
  105. $VHOST.=$tab.'location / {'. PHP_EOL;
  106. $VHOST.=$tab.'# try_files $uri $uri/ =404;'. PHP_EOL;
  107. $VHOST.=$tab.'index index.php index.html index.htm;'. PHP_EOL;
  108. $VHOST.=$tab.'try_files $uri $uri/ /index.php?q=$uri&$args;'. PHP_EOL;
  109. $VHOST.=$tab.'}';
  110.  
  111. $VHOST.=$tab.$tab.'error_page 404 /404.html;'. PHP_EOL;
  112. $VHOST.=$tab.$tab.'error_page 500 502 503 504 /50x.html;'. PHP_EOL;
  113. $VHOST.=$tab.$tab.'location = /50x.html {'. PHP_EOL;
  114. $VHOST.=$tab.$tab.'root /usr/share/nginx/html;'. PHP_EOL;
  115. $VHOST.=$tab.'}'. PHP_EOL;
  116. $VHOST.=$tab.'# Feed'. PHP_EOL;
  117. $VHOST.=$tab.'location ~* \.(?:rss|atom)$ {'. PHP_EOL;
  118. $VHOST.=$tab.$tab.'expires 1h;'. PHP_EOL;
  119. $VHOST.=$tab.$tab.'add_header Cache-Control "public";'. PHP_EOL;
  120. $VHOST.=$tab.'} '. PHP_EOL;
  121. $VHOST.=$tab.'# Media: images, icons, video, audio, HTC'. PHP_EOL;
  122. $VHOST.=$tab.'location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {'. PHP_EOL;
  123. $VHOST.=$tab.$tab.'expires 1y;'. PHP_EOL;
  124. $VHOST.=$tab.$tab.'access_log off;'. PHP_EOL;
  125. $VHOST.=$tab.$tab.'add_header Cache-Control "public";'. PHP_EOL;
  126. $VHOST.=$tab.'}'. PHP_EOL;
  127. $VHOST.=$tab.'# CSS dan Javascript'. PHP_EOL;
  128. $VHOST.=$tab.'location ~* \.(?:css|js)$ {'. PHP_EOL;
  129. $VHOST.=$tab.$tab.'expires 1y;'. PHP_EOL;
  130. $VHOST.=$tab.$tab.'access_log off;'. PHP_EOL;
  131. $VHOST.=$tab.$tab.'add_header Cache-Control "public";'. PHP_EOL;
  132. $VHOST.=$tab.'}'. PHP_EOL;
  133.  
  134. $VHOST.=$tab.'# Media: fonts'. PHP_EOL;
  135. $VHOST.=$tab.'location ~* \.(?:eot|ttf|woff|woff2)$ {'. PHP_EOL;
  136. $VHOST.=$tab.$tab.'expires 1y;'. PHP_EOL;
  137. $VHOST.=$tab.$tab.'access_log off;'. PHP_EOL;
  138. $VHOST.=$tab.$tab.'add_header Cache-Control "public";'. PHP_EOL;
  139. $VHOST.=$tab.'}'. PHP_EOL;
  140. $VHOST.=$tab.'location ~ \.php$ {'. PHP_EOL;
  141. $VHOST.=$tab.$tab.'try_files $uri =404;'. PHP_EOL;
  142. $VHOST.=$tab.$tab.'fastcgi_split_path_info ^(.+\.php)(/.+)$;'. PHP_EOL;
  143. $VHOST.=$tab.$tab.'# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;'. PHP_EOL;
  144. $VHOST.=$tab.$tab.'fastcgi_pass php-fpm;'. PHP_EOL;
  145. $VHOST.=$tab.$tab.'fastcgi_index index.php;'. PHP_EOL;
  146. $VHOST.=$tab.$tab.'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;'. PHP_EOL;
  147. $VHOST.=$tab.$tab.'include fastcgi_params;'. PHP_EOL;
  148. $VHOST.=$tab.'}'. PHP_EOL;
  149. $VHOST.='}'. PHP_EOL;
  150.  
  151. $fw = fopen($VHOSTPATH, "a");
  152. fwrite($fw, $VHOST);
  153.  
  154. msg("Setting up the config file...");
  155. //Now let's set up the config file
  156. $config_file = file($WEBROOT . 'wp-config-sample.php');
  157. $secret_keys = file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' );
  158. $secret_keys = explode( "\n", $secret_keys );
  159. foreach ( $secret_keys as $k => $v ) {
  160. $secret_keys[$k] = substr( $v, 28, 64 );
  161. }
  162. array_pop($secret_keys);
  163.  
  164. $config_file = str_replace('database_name_here', $MYSQLDB, $config_file);
  165. $config_file = str_replace('username_here', $MYSQLUSER, $config_file);
  166. $config_file = str_replace('password_here', $MYSQLPWD, $config_file);
  167. $config_file = str_replace('localhost', $MYSQLHOST, $config_file);
  168. $config_file = str_replace("'AUTH_KEY', 'put your unique phrase here'", "'AUTH_KEY', '{$secret_keys[0]}'", $config_file);
  169. $config_file = str_replace("'SECURE_AUTH_KEY', 'put your unique phrase here'", "'SECURE_AUTH_KEY', '{$secret_keys[1]}'", $config_file);
  170. $config_file = str_replace("'LOGGED_IN_KEY', 'put your unique phrase here'", "'LOGGED_IN_KEY', '{$secret_keys[2]}'", $config_file);
  171. $config_file = str_replace("'NONCE_KEY', 'put your unique phrase here'", "'NONCE_KEY', '{$secret_keys[3]}'", $config_file);
  172. $config_file = str_replace("'AUTH_SALT', 'put your unique phrase here'", "'AUTH_SALT', '{$secret_keys[4]}'", $config_file);
  173. $config_file = str_replace("'SECURE_AUTH_SALT', 'put your unique phrase here'", "'SECURE_AUTH_SALT', '{$secret_keys[5]}'", $config_file);
  174. $config_file = str_replace("'LOGGED_IN_SALT', 'put your unique phrase here'", "'LOGGED_IN_SALT', '{$secret_keys[6]}'", $config_file);
  175. $config_file = str_replace("'NONCE_SALT', 'put your unique phrase here'", "'NONCE_SALT', '{$secret_keys[7]}'", $config_file);
  176.  
  177. if(file_exists($WEBROOT .'wp-config.php')) {
  178. unlink($WEBROOT .'wp-config.php');
  179. }
  180.  
  181. $fw = fopen($WEBROOT . 'wp-config.php', "a");
  182.  
  183. foreach ( $config_file as $line_num => $line ) {
  184. fwrite($fw, $line);
  185. }
  186.  
  187. msg("Installing WordPress...");
  188. define('ABSPATH', $WEBROOT);
  189. define('WP_CONTENT_DIR', 'wp-content/');
  190. define('WPINC', 'wp-includes');
  191. define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
  192.  
  193. define('WP_USE_THEMES', true);
  194. define('DB_NAME', $MYSQLDB);
  195. define('DB_USER', $MYSQLUSR);
  196. define('DB_PASSWORD', $SQLPWD);
  197. define('DB_HOST', $MYSQLHOST);
  198.  
  199. $_GET['step'] = 2;
  200. $_POST['weblog_title'] = "My WordPress";
  201. $_POST['user_name'] = "admin";
  202. $_POST['admin_email'] = "admin@domain.com";
  203. $_POST['blog_public'] = true;
  204. $_POST['admin_password'] = $wppwd;
  205. $_POST['admin_password2'] = $wppwd;
  206.  
  207. require_once(ABSPATH . 'wp-admin/install.php');
  208. require_once(ABSPATH . 'wp-load.php');
  209. require_once(ABSPATH . WPINC . '/class-wp-walker.php');
  210. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  211.  
  212. msg('Save Data .......');
  213.  
  214. $DATA = $SERVERNAME;
  215. $DATA .= $tab."admin|".$wppwd;
  216. $DATA .= $tab.$MYSQUSR."|".$MYSQLDB;
  217.  
  218. $saver = fopen($RT, "a");
  219. fwrite($saver, $DATA);
  220.  
  221. msg('restarting NGINX');
  222. exc('rm latest.tar.gz');
  223. msg('Your WordPress site is ready. Navigate to http://' . $SERVERNAME . ' in your web browser');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement