Created
May 17, 2019 04:46
-
-
Save varunsridharan/4727e96493b831a9623c8edbd9f496e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define( 'PATH', __DIR__ ); | |
define( 'MYSQL_USER', 'mysqldump' ); | |
define( 'MYSQL_PASS', 'mysqldump' ); | |
var_dump( $_POST ); | |
/** | |
* Class WP_Installer | |
* | |
* @author Varun Sridharan <varunsridharan23@gmail.com> | |
* @since 1.0 | |
*/ | |
class WP_Installer { | |
protected $install_path = false; | |
protected $template_wp = false; | |
protected $template_db = false; | |
protected $db_name = false; | |
protected $install_folder = false; | |
protected $laragon_apache = false; | |
protected $domain = false; | |
/** | |
* WP_Installer constructor. | |
*/ | |
public function __construct() { | |
if ( count( array_filter( $_POST ) ) < 7 ) { | |
echo 'Required Arguments Are Missing'; | |
return false; | |
} | |
if ( empty( $_POST['install_path'] ) ) { | |
echo 'Invalid Install Path'; | |
return false; | |
} | |
$response = array(); | |
$this->install_path = self::slashit( $_POST['install_path'] ); | |
$this->install_folder = basename( $this->install_path ); | |
$this->template_wp = self::slashit( $_POST['template_wp_path'] ); | |
$this->template_db = $_POST['template_db_name']; | |
$this->db_name = $_POST['db_name']; | |
$this->domain = $_POST['install_domain']; | |
$this->laragon_apache = $_POST['laragon_apache_path']; | |
$this->full_path = self::slashit( self::slashit( PATH ) . $this->install_path ); | |
$this->template_full_path = self::slashit( self::slashit( PATH ) . $this->template_wp ); | |
// Creates Directory If Not Exists. | |
@mkdir( $this->full_path, 0777, true ); | |
// Copy Template From template to main. | |
$response[] = shell_exec( 'cp -r ' . $this->template_full_path . '* ' . $this->full_path ); | |
// Creates New Database. | |
$response[] = shell_exec( 'mysql -u ' . MYSQL_USER . ' --password=' . MYSQL_PASS . ' -e "create database ' . $this->db_name . '" ' ); | |
// Copy Database | |
$response[] = shell_exec( 'mysqldump --user=' . MYSQL_USER . ' ' . $this->template_db . ' > ' . $this->template_db . '.sql' ); | |
// Restores Backup DB. | |
$response[] = shell_exec( 'mysql -u ' . MYSQL_USER . ' --password=' . MYSQL_PASS . ' ' . $this->db_name . ' < ' . $this->template_db . '.sql' ); | |
// Deletes Backup File. | |
unlink( $this->template_db . '.sql' ); | |
// Deletes wp-config.php | |
unlink( $this->full_path . 'wp-config.php' ); | |
// Create WP-Config.php | |
$this->wpconfig(); | |
// Creates Apache Config. | |
$this->apache(); | |
// Creates Host File. | |
$this->hosts_files(); | |
var_dump( $response ); | |
// Reload Apache In Laragon | |
//$response[] = shell_exec( self::slashit( $_POST['laragon_path'] ) . 'laragon reload apache' ); | |
} | |
protected function wpconfig() { | |
$dbname = $this->db_name; | |
$content = <<<WPCONFIG | |
<?php | |
\$table_prefix = 'wp_'; | |
\$url = \$_SERVER['REQUEST_SCHEME'] . '://' . \$_SERVER['HTTP_HOST'] . '/'; | |
define( 'DB_NAME', '$dbname' ); | |
define( 'DB_USER', 'root' ); | |
define( 'DB_PASSWORD', '' ); | |
define( 'DB_HOST', 'localhost' ); | |
define( 'DB_CHARSET', 'utf8' ); | |
define( 'DB_COLLATE', '' ); | |
define('AUTH_KEY', 'MV}%znAg33Vx),r<_eCT!Tf%]s[H6B&%8t^|j#u6Q8DG^Me)ooV;W!/5.wAn|;)}'); | |
define('SECURE_AUTH_KEY', 'okue,U}KqH~=[;U3c*f7+(J?If<An}Ti|x.1!b{N[}| Q[Bs*P8)7X|.96zTz@:|'); | |
define('LOGGED_IN_KEY', 'XM\$X@@%H<M.g27l2ySa=ACk)euZvWC?(|h{f6NDA(\$XWtc:xcj3wczPxI+ow%W?l'); | |
define('NONCE_KEY', 'b<j)UE(y3MhA^n<V6a=hFw uqF.4*X*L%t5F\$KuMVdxTTHqK9jGr:-soM>/`Dasm'); | |
define('AUTH_SALT', '/#2r_iR%04vwL>wI_:4lU2w;;}y-Frz1_)#cw>daa!~~k{^w~cJ%Eyw6fP5OSg9g'); | |
define('SECURE_AUTH_SALT', 'ksQN*of,}$\$A4d!-z_gCzYSh:AkY4_op|BcD%t1Jit>e-p~]R!+/5}_>3B4q|iB&'); | |
define('LOGGED_IN_SALT', 'aebhVeWuzeM0}<K+<#V(q-V82P!)1:WZ,QUIE^|RzJVgrtOPN$1-yrMF]5}(K+i:'); | |
define('NONCE_SALT', ',LAqio`3|Z<m8P|e5+Gm90ylAOS|r@AU9{|B5nzTaxI;ky]OmG8As<5K1Uj4?1,>'); | |
define( 'MEDIA_TRASH', true ); | |
define( 'WP_AUTO_UPDATE_CORE', false ); | |
define( 'WP_MEMORY_LIMIT', '64M' ); | |
define( 'WP_MAX_MEMORY_LIMIT', '512M' ); | |
define( 'WP_SITEURL', \$url ); | |
define( 'WP_HOME', \$url ); | |
define( 'WP_DEBUG', true ); | |
define( 'WP_DEBUG_LOG', true ); | |
define( 'WP_DEBUG_DISPLAY', true ); | |
define( 'SCRIPT_DEBUG', true ); | |
define( 'SAVEQUERIES', true ); | |
define( 'WP_CACHE', false ); | |
define( 'COMPRESS_CSS', false ); | |
define( 'COMPRESS_SCRIPTS', false ); | |
define( 'CONCATENATE_SCRIPTS', false ); | |
define( 'ENFORCE_GZIP', false ); | |
if ( !defined('ABSPATH') ){ | |
define('ABSPATH', dirname(__FILE__) . '/'); | |
} | |
require_once(ABSPATH . 'wp-settings.php'); | |
WPCONFIG; | |
file_put_contents( $this->full_path . 'wp-config.php', $content ); | |
} | |
/** | |
* Creates Apache Config. | |
*/ | |
protected function apache() { | |
$path = str_replace( '\\', '/', $this->full_path ); | |
$domain = $this->domain; | |
$config = <<<APACHE_CONFIG | |
define ROOT "$path" | |
define SITE "$domain" | |
<VirtualHost *:80> | |
DocumentRoot "\${ROOT}" | |
ServerName \${SITE} | |
ServerAlias *.\${SITE} | |
<Directory "\${ROOT}"> | |
AllowOverride All | |
Require all granted | |
</Directory> | |
</VirtualHost> | |
<VirtualHost *:443> | |
DocumentRoot "\${ROOT}" | |
ServerName \${SITE} | |
ServerAlias *.\${SITE} | |
<Directory "\${ROOT}"> | |
AllowOverride All | |
Require all granted | |
</Directory> | |
SSLEngine on | |
SSLCertificateFile E:/localhost/etc/ssl/laragon.crt | |
SSLCertificateKeyFile E:/localhost/etc/ssl/laragon.key | |
</VirtualHost> | |
APACHE_CONFIG; | |
file_put_contents( self::slashit( $this->laragon_apache ) . $domain . '.conf', $config ); | |
} | |
protected function hosts_files() { | |
$domain = $this->domain; | |
$content = <<<HOSTS | |
127.0.0.1 $domain # VSP Magic ! | |
HOSTS; | |
$_c = file_get_contents( $_POST['hosts_file'] ); | |
$_c .= $content; | |
file_put_contents( $_POST['hosts_file'], $_c ); | |
} | |
/** | |
* @param $string | |
* | |
* @static | |
* @return string | |
*/ | |
public static function unslashit( $string ) { | |
return rtrim( rtrim( $string, '\\' ), '/' ); | |
} | |
/** | |
* @param $string | |
* | |
* @static | |
* @return string | |
*/ | |
public static function slashit( $string ) { | |
return self::unslashit( $string ) . '/'; | |
} | |
} | |
if ( isset( $_REQUEST['install_path'] ) ) { | |
new WP_Installer(); | |
} | |
?> | |
<title>Laragon Quick WP Installer</title> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" | |
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | |
<div class="container" style="margin-top:30px;"> | |
<form method="post"> | |
<div class="form-group"> | |
<label>Install Path</label> | |
<div class="input-group mb-3"> | |
<div class="input-group-prepend"><span class="input-group-text"><?php echo PATH . '/'; ?></span></div> | |
<input type="text" name="install_path" class="form-control" placeholder="Install Path"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label>Database Name.</label> | |
<input type="text" name="db_name" class="form-control" placeholder="wp_wc_"> | |
</div> | |
<div class="form-group"> | |
<label>Domain Name</label> | |
<input type="text" name="install_domain" class="form-control" placeholder="someplace.pc"> | |
</div> | |
<hr/> | |
<div class="form-group"> | |
<label>Template WordPress Path</label> | |
<div class="input-group mb-3"> | |
<div class="input-group-prepend"><span class="input-group-text"><?php echo PATH . '/'; ?></span></div> | |
<input type="text" name="template_wp_path" class="form-control" value="wp-template"> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label>Template WP Database.</label> | |
<input type="text" name="template_db_name" class="form-control" value="wp_template"> | |
</div> | |
<hr/> | |
<div class="form-group"> | |
<label>laragon path</label> | |
<input type="text" name="laragon_path" class="form-control" value="E:\localhost"> | |
</div> | |
<div class="form-group"> | |
<label>Apache (sites-enabled).conf laragon path</label> | |
<input type="text" name="laragon_apache_path" class="form-control" | |
value="E:\localhost\etc\apache2\sites-enabled"> | |
</div> | |
<div class="form-group"> | |
<label>Hosts File</label> | |
<input type="text" name="hosts_file" class="form-control" value="C:\Windows\System32\drivers\etc\hosts"> | |
</div> | |
<button type="submit" class="btn btn-primary">Submit</button> | |
</form> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment