WordPress local development environment [closed]

WordPress local development environment:

Local development environments could apply to developing any type of application but there are some specific WordPress gotchas that could hinder your transition from local to dev.

The goal of a local development environment is to mimic as close as possible the production environment and allow seamless transition.

Matching URL If you plan on using the same database for production it’s much easier to set your local dev to the same domain as production.

  • Open your host file: sudo nano /etc/hosts and add 127.0.0.1 your-domain.com

Move root to sites dir It’s much easier to manage your WordPress install under the sites dir than /Applications/Mamp/httdocs.

Edit your vhost file adding each site mapping it to the dir location:

/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
DocumentRoot "/Users/your_name/Sites/domain"
ServerName domain.com #This should be the same as what was added to your host file
</VirtualHost>

Edit your.conf files mapping your vhosts and enabling Macs built in Apache web server.

/etc/apache2/extra/httpd.conf

#Uncomment line 112:
LoadModule php5_module libexec/apache2/libphp5.so

#Change your directives line 247

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from ALL
</Directory>

#Map your vhost file line: 621
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf

/etc/apache2/users/yourname.conf

<Directory "/Users/yourname/Sites/">
     Options Indexes MultiViews
     AllowOverride All
     Order allow,deny
     Allow from All
</Directory>

Start your web server Go to system preferences -> sharing and check the web sharing box.

wp-config.php Map your database host location to Mamp:

localhost:/Applications/MAMP/tmp/mysql/mysql.sock

Define local constants so you can use the same wp-config between dev and production:

if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
  include( dirname( __FILE__ ) . '/local-config.php' );
  define( 'WP_LOCAL_DEV', true ); 
} else {
  define( 'DB_NAME',     'production_db'       );
  define( 'DB_USER',     'production_user'     );
  define( 'DB_PASSWORD', 'production_password' );
  define( 'DB_HOST',     'production_db_host'  );
}

Now set you local db constants in local-config.php

Extra Tip: Use Mark Jaquith’s Disable Plugins when doing dev plugin to define plugins to disable when on local. Put it in wp-content/mu-plugins and define the plugins to disable at the bottom of the file:

new CWS_Disable_Plugins_When_Local_Dev( array( 'vaultpress.php' ) );

Install WordPress It’ much easier to manage installs using SVN (You will have to install the Subversion binaries for Mac first ).

When your ready for production export your db using phpmyadmin and move your files to the server.

mkdir /sites/domain-name  
cd /sites/domain-name  
svn co http://core.svn.wordpress.org/tags/3.2.1 .  

Leave a Comment