Using Vagrant box for WordPress development

Setting up development environment is a tedious processes. Vagrant makes it easier to create and configure lightweight, reproducible, and portable development environments.


We can use vagrant box to create our WordPress development environment, where nginx, php, MySQL, WordPress and other necessary softwares were pre-installed.

I wrote a solution for that, named WordPress-Vagrant.

Laravel framework offers a nice vagrant box named Homestead, that already contains almost everything that we need. So, instead of creating a new box from scratch, I did use homestead as base box and added WordPress on it.

Once you clone the repository and setup according to instructions, you shall get a virtual machine with following softwares pre-installed.

  • Ubuntu 14.04
  • PHP 5.6
  • HHVM
  • Nginx
  • MySQL
  • Postgres
  • Node (With PM2, Bower, Grunt, and Gulp)
  • Redis
  • Memcached (PHP 5.x Only)
  • Beanstalkd
  • WP-CLI
  • PHPUnit
  • Composer
  • Running WordPress instance

Newly created WordPress instance can be accessable by visiting

All WordPress files serve from a directory named wordpress, inside your project directory on your local machine. So, you can use your favourite IDE for writing your codes.

Initially wordpress directory contains no files. When you run vagrant up, it will dump all WordPress files for you.

Visit WordPress-Vagrant and feel free to fork.

WordPress Error handling with WP_Error class

WordPress has WP_Error class for checking WordPress errors and error messages since version 2.1.0. WordPress uses object of WP_Error class for reporting errors from several WP functions. However, we can use this object in plugin or theme to handle error within WordPress. This class containing various useful method for managing error.


Constructor of WP_Error allows three parameters: $code, $message and $data
Syntex is:

$error = new WP_Error( $code, $message, $data );

here, $code containing error code. it may be string or integer, $message containing error message and $data containing error data. however all parameter are optional.

Suppose, we want to report new error, so we can use:

$error = new WP_Error( 'not_found', 'Page Not Found', 'Page Data' );

Here, we consider not_found as error code, ‘Page Not Found’ as error message and ‘Page Data’ as error data.

After creating error object we can check error by is_wp_error function.

Add FTP info to your wordpress site

Sometimes WordPress asking you for ftp details when you are going to add new plugins or themes or going to upgrade. In that case it also restrict you to edit your file or .htaccess file. This problem occur while your WordPress don’t have sufficient or wrong FTP info for accessing your files in server.

To overcome this problem, let your wordpress know about your FTP account by adding those lines in wp-config.php file.

define('FTP_HOST', '');
define('FTP_USER', 'FTP_Username');
define('FTP_PASS', 'FTP_password');
//*For using SSL Connection set this to true*
define('FTP_SSL', true);