Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.44 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("What is your development server name? DO NOT include http:// (i.e. mysite.dev)");
  29. $APACHEUSER = promptUser("What is the webserver user runs under? (i.e. www-data , nginx , apache ");
  30. $MYSQLDB = promptUser("Enter MySQL Database name:");
  31. $MYSQLPWD = promptUser("Enter MySQL password: (leave blank if not sure)", "");
  32. $MYSQLHOST ='localhost';
  33. $MYSQLUSER = 'root';
  34. $WEBROOT = '/var/www/html/'.$SERVERNAME.'/';
  35. $VHOSTPATH = '/etc/nginx/conf.d/virtual.conf';
  36.  
  37. //Need this to emulate the browser-based installation
  38. $_SERVER['HTTP_HOST'] = $SERVERNAME;
  39. $_SERVER['REQUEST_URI'] = "/";
  40.  
  41. msg('Creating DB ...');
  42. if(strlen($MYSQLPWD)) {
  43. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -p" . $MYSQLPWD . " -e 'CREATE DATABASE IF NOT EXISTS '" . $MYSQLDB . ";");
  44. } else {
  45. exc("mysql -h" . $MYSQLHOST . " -u" . $MYSQLUSER . " -e 'CREATE DATABASE IF NOT EXISTS '" . $MYSQLDB . ";");
  46. }
  47.  
  48. msg('Downloading Wordpress ...');
  49. exc('wget http://wordpress.org/latest.tar.gz');
  50.  
  51. msg('Unpacking WordPresss ...');
  52. exc('tar xzf latest.tar.gz');
  53.  
  54. msg('moving wordpress into the webroot ' . $WEBROOT);
  55. //make sure webroot exists
  56. exc('mkdir -p "' . $WEBROOT . '"');
  57. exc('cp -r wordpress/* "' . $WEBROOT . '"');
  58. exc('rm -rf wordpress');
  59.  
  60. msg("Setup folder permissions..");
  61. //set folder permissions to apache user
  62. exc('chown -R ' . $APACHEUSER . ':staff ' . $WEBROOT);
  63.  
  64. //add local site to the hosts file
  65. msg("Add entry in /etc/hosts file...");
  66.  
  67. msg("Setting up the vhost...");
  68. //set up NGINX vhost
  69. $VHOST='server {';
  70. $VHOST=$tab.'listen 80;';
  71. $VHOST=$tab.'root '. $WEBROOT . ';';
  72. $VHOST=$tab.'server_name '.$SERVERNAME.' www.'.$SERVERNAME.';';
  73. $VHOST=$tab.'location / {';
  74. $VHOST=$tab.'# try_files $uri $uri/ =404;';
  75. $VHOST=$tab.'index index.php index.html index.htm;';
  76. $VHOST=$tab.'try_files $uri $uri/ /index.php?q=$uri&$args;';
  77. $VHOST=$tab.'}';
  78.  
  79. $VHOST=$tab.$tab.'error_page 404 /404.html;';
  80. $VHOST=$tab.$tab.'error_page 500 502 503 504 /50x.html;';
  81. $VHOST=$tab.$tab.'location = /50x.html {';
  82. $VHOST=$tab.$tab.'root /usr/share/nginx/html;';
  83. $VHOST=$tab.'}';
  84. $VHOST=$tab.'# Feed';
  85. $VHOST=$tab.'location ~* \.(?:rss|atom)$ {';
  86. $VHOST=$tab.$tab.'expires 1h;';
  87. $VHOST=$tab.$tab.'add_header Cache-Control "public";';
  88. $VHOST=$tab.'} ';
  89. $VHOST=$tab.'# Media: images, icons, video, audio, HTC';
  90. $VHOST=$tab.'location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {';
  91. $VHOST=$tab.$tab.'expires 1y;';
  92. $VHOST=$tab.$tab.'access_log off;';
  93. $VHOST=$tab.$tab.'add_header Cache-Control "public";';
  94. $VHOST=$tab.'}';
  95. $VHOST=$tab.'# CSS dan Javascript';
  96. $VHOST=$tab.'location ~* \.(?:css|js)$ {';
  97. $VHOST=$tab.$tab.'expires 1y;';
  98. $VHOST=$tab.$tab.'access_log off;';
  99. $VHOST=$tab.$tab.'add_header Cache-Control "public";';
  100. $VHOST=$tab.'}';
  101.  
  102. $VHOST=$tab.'# Media: fonts';
  103. $VHOST=$tab.'location ~* \.(?:eot|ttf|woff|woff2)$ {';
  104. $VHOST=$tab.$tab.'expires 1y;';
  105. $VHOST=$tab.$tab.'access_log off;';
  106. $VHOST=$tab.$tab.'add_header Cache-Control "public";';
  107. $VHOST=$tab.'}';
  108. $VHOST=$tab.'location ~ \.php$ {';
  109. $VHOST=$tab.$tab.'try_files $uri =404;';
  110. $VHOST=$tab.$tab.'fastcgi_split_path_info ^(.+\.php)(/.+)$;';
  111. $VHOST=$tab.$tab.'# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;';
  112. $VHOST=$tab.$tab.'fastcgi_pass php-fpm;';
  113. $VHOST=$tab.$tab.'fastcgi_index index.php;';
  114. $VHOST=$tab.$tab.'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;';
  115. $VHOST=$tab.$tab.'include fastcgi_params;';
  116. $VHOST=$tab.'}';
  117. $VHOST='}';
  118.  
  119. $fw = fopen($VHOSTPATH, "w");
  120. fwrite($fw, $VHOST);
  121.  
  122. msg("Setting up the config file...");
  123. //Now let's set up the config file
  124. $config_file = file($WEBROOT . 'wp-config-sample.php');
  125. $secret_keys = file_get_contents( 'https://api.wordpress.org/secret-key/1.1/salt/' );
  126. $secret_keys = explode( "\n", $secret_keys );
  127. foreach ( $secret_keys as $k => $v ) {
  128. $secret_keys[$k] = substr( $v, 28, 64 );
  129. }
  130. array_pop($secret_keys);
  131.  
  132. $config_file = str_replace('database_name_here', $MYSQLDB, $config_file);
  133. $config_file = str_replace('username_here', $MYSQLUSER, $config_file);
  134. $config_file = str_replace('password_here', $MYSQLPWD, $config_file);
  135. $config_file = str_replace('localhost', $MYSQLHOST, $config_file);
  136. $config_file = str_replace("'AUTH_KEY', 'put your unique phrase here'", "'AUTH_KEY', '{$secret_keys[0]}'", $config_file);
  137. $config_file = str_replace("'SECURE_AUTH_KEY', 'put your unique phrase here'", "'SECURE_AUTH_KEY', '{$secret_keys[1]}'", $config_file);
  138. $config_file = str_replace("'LOGGED_IN_KEY', 'put your unique phrase here'", "'LOGGED_IN_KEY', '{$secret_keys[2]}'", $config_file);
  139. $config_file = str_replace("'NONCE_KEY', 'put your unique phrase here'", "'NONCE_KEY', '{$secret_keys[3]}'", $config_file);
  140. $config_file = str_replace("'AUTH_SALT', 'put your unique phrase here'", "'AUTH_SALT', '{$secret_keys[4]}'", $config_file);
  141. $config_file = str_replace("'SECURE_AUTH_SALT', 'put your unique phrase here'", "'SECURE_AUTH_SALT', '{$secret_keys[5]}'", $config_file);
  142. $config_file = str_replace("'LOGGED_IN_SALT', 'put your unique phrase here'", "'LOGGED_IN_SALT', '{$secret_keys[6]}'", $config_file);
  143. $config_file = str_replace("'NONCE_SALT', 'put your unique phrase here'", "'NONCE_SALT', '{$secret_keys[7]}'", $config_file);
  144.  
  145. if(file_exists($WEBROOT .'wp-config.php')) {
  146. unlink($WEBROOT .'wp-config.php');
  147. }
  148.  
  149. $fw = fopen($WEBROOT . 'wp-config.php', "a");
  150.  
  151. foreach ( $config_file as $line_num => $line ) {
  152. fwrite($fw, $line);
  153. }
  154.  
  155. msg("Installing WordPress...");
  156. define('ABSPATH', $WEBROOT);
  157. define('WP_CONTENT_DIR', 'wp-content/');
  158. define('WPINC', 'wp-includes');
  159. define( 'WP_LANG_DIR', WP_CONTENT_DIR . '/languages' );
  160.  
  161. define('WP_USE_THEMES', true);
  162. define('DB_NAME', $MYSQLDB);
  163. define('DB_USER', $MYSQLUSER);
  164. define('DB_PASSWORD', $MYSQLPWD);
  165. define('DB_HOST', $MYSQLHOST);
  166.  
  167. $_GET['step'] = 2;
  168. $_POST['weblog_title'] = "My Test Blog";
  169. $_POST['user_name'] = "admin";
  170. $_POST['admin_email'] = "admin@domain.com";
  171. $_POST['blog_public'] = true;
  172. $_POST['admin_password'] = "admin";
  173. $_POST['admin_password2'] = "admin";
  174.  
  175. require_once(ABSPATH . 'wp-admin/install.php');
  176. require_once(ABSPATH . 'wp-load.php');
  177. require_once(ABSPATH . WPINC . '/class-wp-walker.php');
  178. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  179.  
  180. msg('restarting apache');
  181. exc('apachectl -k graceful');
  182. msg('Your WordPress site is ready. Navigate to http://' . $SERVERNAME . ' in your web browser');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement