Developing WordPress themes and plugins locally is a complicated task. The need of a web server installed in your system, the creation of specific databases for each project, the manual installation of WordPress, all these are repeatedly done and time consuming. Besides that, WordPress’ file structure is strict and does not offer the flexibility to organize your project the way you want or use higher level languages like CoffeeScript, Sass or LESS.
In this tutorial I’m going to show you how to minimize the time you spend to start a new WordPress project from scratch and how to do the same for existing projects, using Marv.
What is Marv?
Marv is a Ruby gem that was created to make WordPress development easier, faster and let you deal with the important aspects of your project. Marv is Open Source and its source code can be found on Github, where you can find detailed usage instructions, submit issues and feature requests.
A few requirements before we begin:
- I’m using Ubuntu and its terminal application, so some of the commands below will apply to Ubuntu users
- A web browser, in my case Mozilla Firefox
You first need to make sure you have Ruby and Rubygems installed in your system. Then, start a new terminal to install some additional dependencies, with the right permissions:
$ apt-get install build-essential mysql-server mysql-client libmysqlclient-dev php5-cli php5-mysql
And install Marv:
$ gem install marv
Create a local WordPress server using Marv
One of Marv’s coolest features is the ease of creating a new local WordPress server, along with a MySQL database. I’m going to name my server “demo-server”, you can use whatever fits your needs. So let’s start a new terminal and type:
$ marv server create demo-server
Configure Marv
Assuming this is the first Marv command you use, Marv is going to ask if you want to set some defaults, project, server and database details. I’m going to type y, and give Marv some info about my projects. I enter a default value for the project’s URI, author, author URI, project license and license URI.
Then Marv asks if you want to set some defaults about your local servers. I’m typing y again, and set default details about the servers I’m going to create using Marv. For the host, I’m entering localhost and my default port will be 3000.
Now, I’m going to set the details of MySQL, so that Marv can take care of the database user and their privileges. So I’m setting root as the default user, entering the user’s password, database host and port.
And there’s the last question for the default options, about which WordPress version will be set as the default to be downloaded, when you create a new server. I’m choosing latest and Marv will always download and install the newest version of WordPress. You can also specify a previous version when creating a new server.
All these options will be stored in a global configuration file, and used when you create a new server and project. In case of a new theme, these options will be written in the stylesheet that contains your theme details. In case of a new plugin, they will be written in your plugin .php file.
Of course, there is the option to change these details every time you create a new server and project, and if you want to recreate the whole configuration file, simply type:
$ marv config
This will ask the same questions and overwrite the global configuration file.
Back to the server we wanted to create
Having set up the default options, when creating a new server, Marv asks about the new server details, with the ones you entered before given as defaults, how cool is that?!
I’m hitting enter in all these questions, and when the server is ready, Marv will ask if you want to start it. I’m typing y and the server I just created is running.
Now I can open the link in my browser, enter the details of the new site and a fresh WordPress installation is complete.
Some useful commands about Marv servers
To stop a running server, type:
$ marv server stop demo-server
In case you have a number of running servers and want to stop them all, write:
$ marv server stop all
To start the server, simply type:
$ marv server start demo-server
If you want to run the server with the debug option enabled, simply add –debug in the end of the command:
$ marv server start demo-server --debug
Use Ctr+C to stop the server.
To delete a Marv server, use:
$ marv server remove demo-server
To list Marv servers type:
$ marv server list
And to list all running servers use the previous command and append the word running:
$ marv server list running
This was the first part of this tutorial, I hope Marv will help you develop projects faster they way it helps our team. In case you have any problems, you can submit issues on Github. Stay tuned for part 2, in which I’m going to show you how to use Marv for theme and plugin development.