Seite wählen

Take advantage of our open source WordPress shell command installer for Linux in PHP.

In the agency’s everyday it often happens that I have to install WordPress. To be more precise it happens very often and I asked my self one day if it wouldn’t be much more efficient to just run a Linux Shell script to do that for me. So I invested a day to write down my idea and forge it into plain PHP code to be executed as Linux shell script.


An installer? But why?

The installer creates a virtual host for Apache, a MySQL database and database user, Downloads the WordPress archive, creates an wp-config.php file and restarts the server so that the changes of the Apache virtual host config take effect.

All in all this can take from 15 minutes to 2 hours to make it by hand according to your server setup and your skillset. So as I like to have always my head free this Installer can be useful for you too.

The challenge

The idea was to save time, so i developed the WordPress shell command installer only for my current server environment. At the same time i wanted to keep it kind of flexible to give space to other developers to make adjustments to run it for other environments.

Currently the installer script is compatible with MySQL 5.7, Ubuntu 18.04 Apache 2.4.29, and requires at least PHP 7.

You also must run it with root permissions

sudo ./wp-install.php

I decided to use the php.ini file config format to save the configuration data. My choice was to use two configuration files for the WordPress shell command installer script. One machine related config file (config.local.ini) and another more project specific file (the config.ini file).

The Configuration of the Installer

Let’s go trough the config.ini file as is holds the WordPress project specific data.

The email address is just for the virtual host config and will be used maybe later for the WordPress installation. At the moment you have to enter your email address after the installation procedure manually into the freshly installed WordPress instance.

Table prefix is the prefix the WordPress shell command installer will just pass over to the WordPress config file and will be used by WordPress to prefix the MySQL database tables.

The Download URL is the url of the original WordPress file to be Downloaded from the web. In our case we use the German WordPress installation from, which will be extracted by the Linux shell command unzip, which should be installed on your server.

webmaster_email =
table_prefix = wp_
download_url = ""
db_host = localhost

Pitfalls of the WordPress shell command installer

Well of course the whole thing did no run at the first attempt. I had a little trouble to figure out why the creating of the MySQL user did not work. The reason was simple. The password generated contained a forward tick character which is not very much effective when you want to create a MySQL password and then send it from the WordPress shell command installer to the command line. So I simply excluded that character by calling the password generation method again as kind of a recursive function.

    private function getRandomNumber() {

        $number = rand(40, 126);

        // Forward ticks not suitable for mysql passwords.
        if ($number == self::FORWARD_TICK_ASCII_CODE) {
            $number = $this->getRandomNumber();

        return $number;


So the WordPress shell command installer is a quite young project at this moment and some things like a proper error handling, Windows and Mac OS X compatibility are to be done.

All in all the installer is suitable for servers where WordPress needs to be installed often as single site install, without having to think about how to enter all the required commands in the command line manually as this is a cognitive break I want to avoid.

And here we go (again): The path to the Git repository