Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 234 lines (185 sloc) 7.458 kb
<?php
/*
* Name: Wordpress Self-Installer
* Author: Jordan Andree
* Author URL: http://noblegiant.com
* Script URL: http://noblegiant.com/blog/2010/08/wordpress-self-installer/
* Notes: Script is still a work-in-progress and currently only supports Linux/Unix based development enviroments
*/
class config {
var $host = 'localhost'; /* Database Host */
var $user = 'USER'; /* Database User */
var $pass = 'PASSWORD'; /* Database Password */
}
$c = new config();
$con = mysql_connect($c->host, $c->user, $c->pass );
if(!$con) die ('<h2>DATABASE CONNECTION ERROR</h2>');
if(!function_exists('curl_exec')) die('<h2>cURL Extension missing</h2>');
define('BASE', $_SERVER['DOCUMENT_ROOT']);
define('DS', '/');
?>
<html lang="en">
<head>
<title>Wordpress Self-Installer</title>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Droid+Serif:regular,italic);
@import url(http://fonts.googleapis.com/css?family=Molengo);
@import url(http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:extralight);
body {margin:0px; font-family:'Molengo', Arial, Helvetica, Sans-serif; font-size:.80em; background:#222; color:#888 ;}
h1, h2 { color:#0085AF; text-shadow:0px 1px 1px #000; margin:0px 0px 20px; font-family:Georgia, serif; font-weight:normal; border-bottom:1px solid #404040; padding:0px 0px 10px;}
h1 {font-size:250%; color:#ccc;font-family: Georgia, Serif; font-style:normal;}
h2 {font-size:180%;}
a { color:#bbb; text-decoration:none;}
a:hover { color:#fff;}
#wrap { width:960px; padding:10px; margin:0 auto;}
.header { width:920px; margin:0px 0px 10px 0px; background:#0085AF !important;}
.header h1 { border:0px; margin:0px; padding:0px;}
.header em {float:right; color:#07566F; margin:8px 10px 0px; font-size:140%;}
.databases, .create, .output, .header { padding:20px; background:#333; -moz-border-radius:4px; -webkit-border-radius:4px; border-radius:4px; }
.databases, .create, .output, .header { -moz-box-shadow:0px 1px 1px rgba(0,0,0,.2); box-shadow:0px 1px 1px rgba(0,0,0,.2); -webkit-box-shadow:0px 1px 1px rgba(0,0,0,.2);}
.databases { margin:10px 0px 0px 0px; width:220px; float:left;}
.databases ul { padding:0px; margin:0px; list-style-position:inside; list-style-type:circle;}
.create { margin:10px 0px 10px 0px; float:right;width:640px; }
.output { margin:10px 0px 0px 0px; float:right; width:640px;}
.copyright { font-size:80%; padding:10px; float:right; width:660px; color:#333;}
.copyright a { color:#555;}
.copyright a:hover { color:#666;}
</style>
</head>
<div id="wrap">
<div class="header">
<em>Beta</em>
<h1>Wordpress Self-Installer</h1>
</div>
<div class="databases">
<ul><h2>Wordpress Installs</h2>
<?php
$query = mysql_query("SHOW DATABASES");
$read = opendir(BASE.DS);
while(false !== ($dir = readdir($read))){
if(is_dir(BASE.DS.$dir.DS) && $dir != '.' && $dir != '..'){
if(file_exists(BASE.DS.$dir.DS.'wp-settings.php')){
echo '<li><a href="'.$dir.'">'.$dir.'</a></li>';
}
}
}
?>
</ul>
</div>
<div class="create">
<h2>Create New Wordpress Installation</h2>
<form action="wordpress.php?action=new" method="post">
<label for="name">New Wordpress Installation Name:</label>&nbsp;&nbsp;<input type="text" name="name" size="40" />
<!--<br /><br />Include filler Posts, Comments, and Pages&nbsp;&nbsp;<input type="checkbox" name="filler" id="filler" checked="false">-->
<br /><br />
<input type="submit" value="Submit" />
</form>
</div>
<div class="output">
<h2>Installation Progress</h2>
<div id="none">None yet!</div>
<?php
if(!empty($_GET['action'])){
switch($_GET['action']){
case 'new':
$name = $_POST['name'];
echo '<style>#none { display:none}</style>';
if(empty($name)){
echo 'Installation Name required';
break;
}
define('ABSPATH', BASE.DS.$name.DS);
echo 'Creating database...';
// first creat our database
$create_db = mysql_query("CREATE DATABASE {$name}");
if($create_db)
// database done!
echo 'Done!<br /><br />';
/** Wordpress Download **/
echo 'Downloading latest version of Wordpress...';
// curl init
$ch = curl_init();
// get latest tar
curl_setopt($ch,CURLOPT_URL,'http://wordpress.org/latest.tar.gz');
// file intance
$filename = 'latest.tar.gz';
$save = fopen($filename, 'a');
// ask curl to save latest to our file handle
curl_setopt($ch,CURLOPT_FILE, $save);
// execute
$latest = curl_exec($ch);
// close curl connection
curl_close($ch);
// close file
fclose($save);
echo 'Done!<br /><br />';
/** Wordpress File and Directory Setup **/
echo 'Unpacking Wordpress core files...';
// make directory
if(!file_exists(BASE.DS.$name)){
mkdir(BASE.DS.$name, 0755);
}
// execute tar of file
$tar = "tar -xvzf $filename -C $name/";
$results = system(escapeshellcmd($tar), $retval);
// delete tar
unlink($filename);
// make temp dir
$rand = rand(1,10000);
$tmpdir = 'tmp_'.$rand;
mkdir(BASE.DS.$tmpdir, 0755);
// copy wordpress installation to tmp dir
rename(ABSPATH.'wordpress'.DS, BASE.DS.$tmpdir.DS);
// copy tmp dir files to new dir with set name
rename(BASE.DS.$tmpdir.DS, ABSPATH);
echo 'Done!<br /><br />';
echo 'Setting up Wordpress <code>wp-config.php</code> file...';
/** Wordpress Configuration Setup **/
$wp_config_sample = ABSPATH.'wp-config-sample.php';
$file = fopen($wp_config_sample, 'r');
$file_text = fread($file, filesize($wp_config_sample));
// setup config with params
$file_text = str_replace('database_name_here', $name, $file_text);
$file_text = str_replace('username_here', $c->user, $file_text);
$file_text = str_replace('password_here', $c->pass, $file_text);
$new_config = fopen(ABSPATH.'wp-config.php', 'w');
fwrite($new_config, $file_text);
fclose($new_config);
echo 'Done!<br /><br />';
// add filler content if selected
/* $filler = $_POST['filler'];
if($filler){
echo 'Inserting filler Posts, Comments, and Pages';
// include our fresh wordpress config so we can use some WP functions
include ABSPATH.'wp-config.php';
// params for posts and comments per post **to be editable later**
$number_of_posts = 25;
$number_of_comments_per_post = 5;
$lorem = '';
// loop it now
for($i = 0; $i <= $number_of_posts; $i++){
$newpost = array();
$newpost['post_title'] = $heroname;
$newpost['post_content'] = nl2br($story);
$newpost['post_status'] = 'publish';
$newpost['post_author'] = 1;
$newpost['post_type'] = 'post';
$newpost['post_category'] = array(1);
$post_ID = wp_insert_post( $my_post);
}
echo 'Done!<br /><br />';
} */
echo 'You will be redirected to setup your Wordpress site name and admin account in 15 seconds<br />';
echo '<a href="'.$name.'">Click Here</a> to go there immediately';
// and redirect
echo '<meta http-equiv="Refresh" content="15;URL='.$name.'">';
break;
default:
return false;
}
} ?>
</div>
<div class="copyright">
crafted by <a href="http://jordanandree.com">jordan andree</a>. this script wouldn't be possible without <a href="http://wordpress.org">wordpress</a>
<br clear="all" />
</div>
Jump to Line
Something went wrong with that request. Please try again.