Wordpress downloader

Discussion in 'Programming/Scripts' started by pecka33, Sep 22, 2023.

  1. pecka33

    pecka33 Member

    Hello,

    is here anybody who have php script to download and unzip latest version of wordpress to root of my domain?

    Thank you :)
     
  2. pecka33

    pecka33 Member

    I did this, hope that help someone :)

    Code:
    <?php
    
    // get latest german WordPress file
    $ch = curl_init();
    $source = "https://cs.wordpress.org/latest-cs_CZ.zip";
    curl_setopt($ch, CURLOPT_URL, $source);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $data = curl_exec ($ch);
    curl_close ($ch);
    
    // save as wordpress.zip
    $destination = "wordpress.zip";
    $file = fopen($destination, "w+");
    fputs($file, $data);
    fclose($file);
    
    echo " wordpress.zip stazeny; ";
    
    // unzip
    $zip = new ZipArchive;
    $res = $zip->open('wordpress.zip');
    if ($res === TRUE) {
        $zip->extractTo('.'); // directory to extract contents to
        $zip->close();
        echo ' wordpress.zip rozbaleny; ';
        unlink('wordpress.zip');
        echo ' wordpress.zip smazany; ';
    } else {
        echo ' unzip failed; ';
    }
    
     
  3. till

    till Super Moderator Staff Member ISPConfig Developer

    Why did you do not use wp_cli ?
     
    Th0m likes this.
  4. nhybgtvfr

    nhybgtvfr Well-Known Member HowtoForge Supporter

    yep.. wp-cli's definitely the way to go..
    all of that script above boils down to
    Code:
    wp core download
    or if you want a specific local, eg uk english..
    Code:
    wp core download --locale=en_GB
    will download and extract all wordpress files, ready to continue with a web based install..

    or you can continue to install using wp-cli:
    Code:
    wp core config --dbhost=127.0.0.1 --dbname=<dbname> --dbuser=<dbusername> --prompt=dbpass < db_password.txt
    wp core install --url=<site_url> --title="<site title>" --admin_name=<admin_username> --admin_email=<admin_email_address> --prompt=admin_password < admin_password.txt
    
    will firstly create the wp-config.php file and configure all the database settings in it. (will also create random salts in that file)
    and then proceed to populate the database with all the correct site details.

    you can forego the use of --prompt, but then you will need to type the passwords into the command line, which could be a security risk..
    this method pulls the password from a file instead.
    you will need to create the databse yourself (you can also do this using wp-cli) and the password files.. and you will need to delete the password files afterwards yourself as well.

    in the example, the dbhost is set to 127.0.0.1, assuming a local db, in a jailkitted environment with a chrooted php.
    without chroot or jailkit you can use localhost instead, or the actual hostname if the db is on a remote server.
     
    Th0m and ahrasis like this.

Share This Page