Download and install wordpress with single PHP script

One of the common tasts that I have to do recently is installing wordpress on new website. While configuring the WordPress is simple and fast before you get there you need to download wordpress ZIP file, extract it to the correct folder (by default unzipping the file will create folder “wordpress” that you most likely don’t need). I’ve put together the folling script that would automatically download latest WordPress version, unzip it to correct folder and redirect you to configuration page. All you need to do is craete and configure the database.

You can download the script from here. Here’s the script listing for information purposes (because WordPress changes quotation symbols copy-pasting it will not product working PHP code):


$URL = “”;

$ch = curl_init($URL);

curl_setopt($ch, CURLOPT_VERBOSE, 1);


curl_setopt ($ch, CURLOPT_URL, $URL);

curl_setopt ($ch, CURLOPT_TIMEOUT, 600);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

$content = curl_exec($ch);

$fh = fopen(“”, “wb”);

fwrite($fh, $content);


$zip = zip_open(“”);

$dst_path = $_REQUEST[‘path’];

if ($dst_path == ”) { $dst_path = ‘.’; }

while ($entry = zip_read($zip))


$name = zip_entry_name($entry);

if (preg_match(‘/\/$/’, $name)) { continue; }

$new_name = preg_replace(‘/^wordpress/i’, $dst_path, $name);

if (preg_match(‘/^(.+)\/([^\/]+)$/i’, $new_name, $matches)) {

$directory = $matches[1];

if ($directory != ” && !is_dir($directory)) {

if (!mkdir($directory, 0777, 1)) {

return FALSE;




$fh = fopen($new_name, “wb”);

zip_entry_open($zip, $entry, “rb”);

while ($data = zip_entry_read($entry))


fwrite($fh, $data);






header(“Location: /”);


Using it is very simple: create file installwordpress.php and copy-paste this script there and then navigate your browser to this file. All should happen automatically.

Leave a comment

Your email address will not be published. Required fields are marked *