PHPackages                             andrewmead/wpsites - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. andrewmead/wpsites

ActiveLibrary

andrewmead/wpsites
==================

Local WordPress site management

1.11.0(5mo ago)25554[12 issues](https://github.com/andrewjmead/wpsites/issues)MITPHPPHP ^8.2

Since Aug 3Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/andrewjmead/wpsites)[ Packagist](https://packagist.org/packages/andrewmead/wpsites)[ RSS](/packages/andrewmead-wpsites/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (30)Used By (0)

WPSites
=======

[](#wpsites)

WPSites is the fastest way to create a localhost WordPress website.

All you need to do is run `wpsites create`, select a template, name your site, and—boom! It's live!

Check it out:

    WPSites-Intro-Compressed.mp4    Contents
========

[](#contents)

1. [Why?](#why)
2. [Getting started](#getting-started)
3. [Commands](#commands)
    1. [Config](#config)
    2. [Create](#create)
    3. [Destroy](#destroy)
    4. [Open](#open)
    5. [Backup](#backup)
    6. [Restore](#restore)
4. [Configuring WPSites](#configuring-wpsites)
5. [Template options](#template-options)
6. [Limitations](#limitations)

Why?
====

[](#why)

I've been building [Independent Analytics](https://wordpress.org/plugins/independent-analytics/) for the last 2 years, and during that time I've created hundreds (thousands?) of temporary WordPress sites.

I would make a new site for development, to test customer issues, to track down regression in specific versions, and for countless other reasons.

**It was the same process over and over again. I'd create a new site only to configure it exactly the same way I'd done countless times before. Enable debug mode. Symlink the local build. Install the plugins we integrate with. The list goes on and on.**

No more.

Now I run `wpsites create`, select the template I want to use, and 10 seconds later I'm looking at the admin panel for my new WordPress site.

It's sublime.

This project has been a joy to work on. I hope you get some value out of it. If you run into any problems, please open an issue. I'd like to try to get WPSites working for as many people on as many different setups as possible.

Getting started
===============

[](#getting-started)

### Installing

[](#installing)

You'll want to install WPSites as a global composer package. This will give you access to the `wpsites` command from anywhere on your machine.

```
composer global require andrewmead/wpsites

```

The installation process will place the PHAR executable in `~/.composer/vendor/bin/`. Make sure this directory is part of your PATH, otherwise commands such as `wpsites create` will not work.

### Generating a config file

[](#generating-a-config-file)

Before you can create your first WordPress site, you'll need to generate a config file. You can do this by running `wpsites config`. This command will copy the default config file to `~/.wpsites.php`.

```
$ wpsites config

 Copying default config to `/Users/andrewmead/.wpsites.php`

 Config file successfully created!

```

Once your config file is created, open it in your text editor as there are a couple of values you'll need to change before you can create your first site.

### Configuring your site's directory

[](#configuring-your-sites-directory)

You need to tell WPSites where on your file system you want new sites to be created. This can be done by changing the value for `sites_directory` near the top of `~/.wpsites.php`.

```
// ~/.wpsites.php

return [
    // ...
    'sites_directory' => '$HOME/Herd',
    // ...
];
```

The default value of `$HOME/Herd` will work if you are using Laravel Herd. If you're using MAMP PRO, you'll need to change the path to `$HOME/Sites`.

You can store your sites anywhere, but make sure the site's directory is being served up by your localhost server.

### Configuring your database connection

[](#configuring-your-database-connection)

Aside from the site's directory, the only other thing you need to configure is your database connection.

There are three options you can use for this. Inside of `defaults`, you'll want to use `database_host`, `database_username`, and `database_password`.

By default, WPSites will try to connect to `127.0.0.1:3306` as the user `root` without a password. Change these values to match up with your localhost database server.

```
// ~/.wpsites.php

return [
    // ...
    'defaults' => [
        // ...
        'database_host'     => '127.0.0.1:3306',
        'database_username' => 'root',
        'database_password' => null,
        // ...
    ]
];
```

You can test your database connection in the next step by trying to create a new site.

### Creating your first site

[](#creating-your-first-site)

You're now ready to create your first site!

Create your first site by running `wpsites create`. You'll be prompted to pick a template. Select "Basic WordPress" for now. We'll talk more about templates a bit later. Next, pick a slug for your site.

In a few seconds, you should be looking at your brand-new WordPress site!

```
$ wpsites create

 ┌ Which template would you like to use? ───────────────────────┐
 │ › ● Basic WordPress                                          │
 │   ○ Basic Multisite WordPress                                │
 │   ○ Symlink plugin example                                   │
 │   ○ Bug recreation example                                   │
 └──────────────────────────────────────────────────────────────┘

 ┌ What slug would you like to use? ────────────────────────────┐
 │ any-slug-you-like                                            │
 └──────────────────────────────────────────────────────────────┘

 Downloading core files...

 Creating site...

 Creating database...

 Running installation...

 Enabling error log...

 Enabling automatic login...

 Installing default theme...

 Opening site...

```

Amazing!

Notice that you didn't need to log in to the admin panel. This is thanks to the `automatic-login` plugin. New sites have automatic login enabled. They also have the debug log enabled. There are settings in [template options](#template-options) to disable both of these, but I find it's perfect for local development.

Creating your first site is just the beginning. Read on to learn how you can make your own templates to create sites specific to your needs!

Commands
========

[](#commands)

1. [Config](#config)
2. [Create](#create)
3. [Destroy](#destroy)
4. [Open](#open)
5. [Backup](#backup)
6. [Restore](#restore)

### Config

[](#config)

Run `wpsites config` to create the default config file. You can rerun `wpsites config` to reset the config file back to its default state.

```
$ wpsites config

 Loading config file at "/Users/andrewmead/.wpsites.php"

 Copying default config to `/Users/andrewmead/.wpsites.php`

 Config file successfully created!

```

### Create

[](#create)

Run `wpsites create` to create a new WordPress site based on a template in your config file.

```
$ wpsites create

 Loading config file at "/Users/andrewmead/.wpsites.php"

 ┌ Which template would you like to use? ───────────────────────┐
 │ › ● Basic WordPress                                          │
 │   ○ Basic Multisite WordPress                                │
 │   ○ Symlink plugin example                                   │
 │   ○ Bug recreation example                                   │
 └──────────────────────────────────────────────────────────────┘

 ┌ What slug would you like to use? ────────────────────────────┐
 │ any-slug-you-like                                            │
 └──────────────────────────────────────────────────────────────┘

 Downloading core files...

 Creating site...

 Creating database...

 Running installation...

 Enabling error log...

 Enabling automatic login...

 Installing default theme...

 Opening site...

```

### Destroy

[](#destroy)

Run `wpsites destroy` to destroy one or more sites.

```
$ wpsites destroy

 Loading config file at "/Users/andrewmead/.wpsites.php"

 Checking which sites are WordPress sites...

 ┌ Which sites would you like to destroy? ──────────────────────┐
 │ wp-test                                                      │
 │ iawp                                                         │
 └──────────────────────────────────────────────────────────────┘

 ┌ Are you sure you want to destroy the sites listed above? ────┐
 │ Yes                                                          │
 └──────────────────────────────────────────────────────────────┘

 Deleting site "wp-test"

 Deleting site "iawp"

```

### Open

[](#open)

Run `wpsites open` to open an existing site in your browser.

```
➜  ~ wpsites open

 Loading config file at "/Users/andrewmead/.wpsites.php"

 Checking which sites are WordPress sites...

 ┌ Select a site to open ───────────────────────────────────────┐
 │ › ● iawp                                                     │
 │   ○ latest-production-install                                │
 │   ○ woocommerce                                              │
 └──────────────────────────────────────────────────────────────┘

```

### Backup

[](#backup)

Run `wpsites backup` to create a backup of an existing site.

Backups are created in `~/.wpsites/backups/`. Each backup contains `db.sql` and `files.zip`.

These backups are not created in a proprietary format. The database export is created using WP CLI's [`wp db export`](https://developer.wordpress.org/cli/commands/db/export/). The file export is just a zip of the WordPress files. That means you can take them with you if you decide to stop using WPSites.

```
➜  ~ wpsites backup

 Loading config file at "/Users/andrewmead/.wpsites.php"

 Checking which sites are WordPress sites...

 ┌ Select a site to backup ─────────────────────────────────────┐
 │ iawp                                                         │
 └──────────────────────────────────────────────────────────────┘

 ┌ Pick a name for the backup ──────────────────────────────────┐
 │ before-migration                                             │
 └──────────────────────────────────────────────────────────────┘

 Backing up database

 Backing up files

 Backup successfully created!

 Backup saved to /Users/andrewmead/.wpsites/backups/before-migration

```

### Restore

[](#restore)

Run `wpsites restore` to restore a backup.

```
➜  ~ wpsites restore

 Loading config file at "/Users/andrewmead/.wpsites.php"

 ┌ Select a backup to use ──────────────────────────────────────┐
 │ before-migration (2024-11-04 2:51 pm)                        │
 └──────────────────────────────────────────────────────────────┘

 Checking which sites are WordPress sites...

 ┌ Select a site to restore ────────────────────────────────────┐
 │ iawp                                                         │
 └──────────────────────────────────────────────────────────────┘

 Restoring files

 Importing database

 Backup successfully restored!

```

Configuring WPSites
===================

[](#configuring-wpsites)

In this section, you'll learn how to customize WPSites to fit your needs. This includes defining a reasonable set of defaults, as well as defining your own templates so you can quickly spin up a preconfigured site.

### Exploring the default config file

[](#exploring-the-default-config-file)

To get started, let's take a look at the default config file that was created when you initially ran `wpsites config`.

Here's the entirety of the default config file.

```
