maandag 16 maart 2015

Wordpress installer PHP script

Example PHP script for installing wordpress in the root of your domain.
This exact script is used in my new upcoming android app Wordpress Installer.
You can save it in a file, upload it to your host and run it in your browser.
It will download Wordpress, unzip the wordpress archive, launch the wordpress first-run script, afterwards this script will delete itself.
the $wpextr variable can be changed to install into a subfolder. Use a leading and a trailing slash.


// 2015
function rrmdir($dir) {
   if (is_dir($dir)) {
     $objects = scandir($dir);
     foreach ($objects as $object) {
       if ($object != "." && $object != "..") {
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
$url = "";
$destination = "";   
if (!file_exists($destination)){
    if (function_exists("curl_init")){   
    $fp = fopen ($destination, 'w+');
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
    curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );

    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 100 );
    curl_setopt( $ch, CURLOPT_FILE, $fp );
    curl_exec( $ch );
    curl_close( $ch );
  fclose( $fp );
    if (!file_put_contents($destination, fopen($url, "r"))){
        die("Cant download file..");   
if (filesize($destination) > 0) {$succes= true;echo "Archive download succes.<br />";}else{$succes=false;}

    echo "Archive already exists, no download required<br />";

if ($succes==true)
$zip = new ZipArchive;
if ($zip->open($destination) === TRUE) {
    #echo $_SERVER['DOCUMENT_ROOT'].$wpextr;
    echo 'Archive extracted succes';

if ($handle = opendir($_SERVER['DOCUMENT_ROOT'].$wpextr.'wordpress')) {
    while (false !== ($fileName = readdir($handle))) {
        if ($fileName!==".." ||$fileName!==".")     @rename($_SERVER['DOCUMENT_ROOT'].$wpextr."wordpress/".$fileName, $_SERVER['DOCUMENT_ROOT'].$wpextr.$fileName);

header("Location: http://".$_SERVER['HTTP_HOST'].$wpextr."/wp-admin/install.php");

} else {
    echo 'ExtractTo function: Opening the wordpress zip file failed. Your webhost seems ancient.';
// xD

Geen opmerkingen:

Een reactie posten