Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- /**
- * Main index page
- * @package default
- * @author Marko Tomic <marko@markomedia.com.au>
- * @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));
- $SERVERNAME = promptUser("What is your development server name? DO NOT include http:// (i.e. mysite.dev)");
- $APACHEUSER = promptUser("What is the webserver user runs under? (i.e. www-data , nginx , apache ");
- $MYSQLDB = promptUser("Enter MySQL Database name:");
- $MYSQLPWD = promptUser("Enter MySQL password: (leave blank if not sure)", "");
- $MYSQLHOST ='localhost';
- $MYSQLUSER = 'root';
- $WEBROOT = '/var/www/html/'.$SERVERNAME.'/';
- $VHOSTPATH = '/etc/nginx/conf.d/virtual.conf';
- //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...");
- msg("Setting up the vhost...");
- //set up NGINX vhost
- $VHOST='server {';
- $VHOST=$tab.'listen 80;';
- $VHOST=$tab.'root '. $WEBROOT . ';';
- $VHOST=$tab.'server_name '.$SERVERNAME.' www.'.$SERVERNAME.';';
- $VHOST=$tab.'location / {';
- $VHOST=$tab.'# try_files $uri $uri/ =404;';
- $VHOST=$tab.'index index.php index.html index.htm;';
- $VHOST=$tab.'try_files $uri $uri/ /index.php?q=$uri&$args;';
- $VHOST=$tab.'}';
- $VHOST=$tab.$tab.'error_page 404 /404.html;';
- $VHOST=$tab.$tab.'error_page 500 502 503 504 /50x.html;';
- $VHOST=$tab.$tab.'location = /50x.html {';
- $VHOST=$tab.$tab.'root /usr/share/nginx/html;';
- $VHOST=$tab.'}';
- $VHOST=$tab.'# Feed';
- $VHOST=$tab.'location ~* \.(?:rss|atom)$ {';
- $VHOST=$tab.$tab.'expires 1h;';
- $VHOST=$tab.$tab.'add_header Cache-Control "public";';
- $VHOST=$tab.'} ';
- $VHOST=$tab.'# Media: images, icons, video, audio, HTC';
- $VHOST=$tab.'location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {';
- $VHOST=$tab.$tab.'expires 1y;';
- $VHOST=$tab.$tab.'access_log off;';
- $VHOST=$tab.$tab.'add_header Cache-Control "public";';
- $VHOST=$tab.'}';
- $VHOST=$tab.'# CSS dan Javascript';
- $VHOST=$tab.'location ~* \.(?:css|js)$ {';
- $VHOST=$tab.$tab.'expires 1y;';
- $VHOST=$tab.$tab.'access_log off;';
- $VHOST=$tab.$tab.'add_header Cache-Control "public";';
- $VHOST=$tab.'}';
- $VHOST=$tab.'# Media: fonts';
- $VHOST=$tab.'location ~* \.(?:eot|ttf|woff|woff2)$ {';
- $VHOST=$tab.$tab.'expires 1y;';
- $VHOST=$tab.$tab.'access_log off;';
- $VHOST=$tab.$tab.'add_header Cache-Control "public";';
- $VHOST=$tab.'}';
- $VHOST=$tab.'location ~ \.php$ {';
- $VHOST=$tab.$tab.'try_files $uri =404;';
- $VHOST=$tab.$tab.'fastcgi_split_path_info ^(.+\.php)(/.+)$;';
- $VHOST=$tab.$tab.'# fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;';
- $VHOST=$tab.$tab.'fastcgi_pass php-fpm;';
- $VHOST=$tab.$tab.'fastcgi_index index.php;';
- $VHOST=$tab.$tab.'fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;';
- $VHOST=$tab.$tab.'include fastcgi_params;';
- $VHOST=$tab.'}';
- $VHOST='}';
- $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'] = "admin@domain.com";
- $_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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement