Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Really need to do some work to support a local development copy #14

Open
hubrix opened this issue Mar 4, 2013 · 6 comments
Open

Really need to do some work to support a local development copy #14

hubrix opened this issue Mar 4, 2013 · 6 comments

Comments

@hubrix
Copy link

hubrix commented Mar 4, 2013

I've now gone through the exercise twice of setting up a local copy and it's a big pain. I think it's worth trying to make some generic config so that one is able to run a local copy without too much pain. It basically involves having two wp-config.php files and having a vendor copy of wordpress. I have not figured out how to deal with memcachesasl locally yet, i just disable it.

I also had to do this to object-cache.php but it seems hacky

diff --git a/config/public/wp-content/object-cache.php b/config/public/wp-content/object-cache.php
index c4486c2..1f5e232 100644
--- a/config/public/wp-content/object-cache.php
+++ b/config/public/wp-content/object-cache.php
@@ -353,14 +353,12 @@ class WP_Object_Cache {

                global $memcachier_servers;

-               if ( isset($memcachier_servers) )
-                       $buckets = $memcachier_servers;
-               else
-                       $buckets = array(
-                               'default' => array(
-                                       getenv("MEMCACHIER_SERVERS")
-                               )
-                       );
+    if ( isset($memcachier_servers) )
+      $buckets = $memcachier_servers;
+    elseif (getenv("MEMCACHIER_SERVERS"))
+      $buckets = array( 'default' => array( getenv("MEMCACHIER_SERVERS")));
+    else
+      $buckets = array('default' => array( 'localhost:11211' ));

                reset($buckets);

@@ -370,7 +368,7 @@ class WP_Object_Cache {
                                list ( $node, $port ) = explode(':', $server);

                                $this->mc[$bucket]->addServer($node, $port);
-                               $this->mc[$bucket]->setSaslAuthData(getenv("MEMCACHIER_USERNAME"), getenv("MEMCACHIER_PASSWORD"));
+        if(getenv("MEMCACHIER_USERNAME")) $this->mc[$bucket]->setSaslAuthData(getenv("MEMCACHIER_USERNAME"), getenv("MEMCACHIER_PASSWORD"));

                        }
                }
@mchung
Copy link
Owner

mchung commented Mar 4, 2013

@hubrix, at the moment, there's no story around developing on a wordpress-on-heroku site. It's just for pushing WP sites to production. I understand this might be a PITA, so I'm definitely open to suggestions.

Can you share how you like to work? If we can come up with a non-crufty approach, I'd consider folding that in to the buildpack

@hubrix
Copy link
Author

hubrix commented Mar 4, 2013

So here's how I have things set up.

I added a wordpress directory to vendor and created a local Apache vhost to point to that.
the wp-content from that directory is symlinked to public/config/wp-content.
I have mysql and memcache installed locally.
there is a local wp-config, at the moment its in the vendor wordpress directory but really should be symlinked out.

this allows pretty decent local work.
there are two things which are still missing that i need to script out (I've done them manually)

  1. push uploads to s3 via script from local
  2. synchronize local db to cleardb

Mark Friedgan

On Sunday, March 3, 2013 at 10:57 PM, Marc Chung wrote:

@hubrix (https://github.com/hubrix), at the moment, there's no story around developing on a wordpress-on-heroku site. It's just for pushing WP sites to production. I understand this might be a PITA, so I'm definitely open to suggestions.
Can you share how you like to work? If we can come up with a non-crufty approach, I'd consider folding that in to the buildpack


Reply to this email directly or view it on GitHub (#14 (comment)).

@luisherranz
Copy link
Contributor

Hey @hubrix, you can use object-cache and batcache locally if you have APC. Just add object-cache.php to the gitignore and substitute it for this one:
http://wordpress.org/extend/plugins/apc/

Instead of creating two different wp-config.php files I suggest you to use ENV variables with the same names than Heroku's.

To synchronise the db with cleardb you must change two things, the url and the path directory, but you need to avoid corruption in the serialised data. I do it with this script:
http://interconnectit.com/products/search-and-replace-for-wordpress-databases/

To push things to s3 I'm using this plugin:
http://wordpress.org/extend/plugins/amazon-s3-and-cloudfront/
I like it more than WPRO.

@cureau
Copy link

cureau commented Aug 12, 2013

Thanks to @hubrix and @luisherranz, I got a pretty workable local setup. For others who follow their advice, I'd mention two things:

  1. if you symlink your wp-content directory link as @hubrix suggests, you might get some plugin activation fatal errors on your local environment if some plugins use wordpress constants to resolve their plugin directory. to fix this you need to add this to your wp-config.php:

define('WP_CONTENT_DIR', realpath($_SERVER['DOCUMENT_ROOT'] . '/wp-content'));

  1. the search and replace cli that @luisherranz recommended works great. Below is a script to automate the db import (production --> local). Of course replace the XYZs with your own credentials, and grab the searchreplacedb2cli.php file from github:

https://github.com/interconnectit/Search-Replace-DB

Import script:


CLEAR_DB_HOST="XYZ"
CLEAR_DB_USER="XYZ"
CLEAR_DB_NAME="XYZ"
CLEAR_DB_PASS="XYZ"

LOCAL_DB_NAME="XYZ"
LOCAL_DB_PASS="XYZ"


SEARCH_THIS="XYZ"
REPLACE_WITH="XYZ"

NOW="$(date +"%d-%m-%Y")"

mkdir -p backups

echo "Backing Up ClearDB "$CLEAR_DB_NAME
mysqldump -h $CLEAR_DB_HOST -u $CLEAR_DB_USER -p$CLEAR_DB_PASS $CLEAR_DB_NAME > ./backups/db-$NOW.sql --add-drop-table

echo "Importing ClearDB "$CLEAR_DB_NAME
sudo mysql -u root -p$LOCAL_DB_PASS -h localhost $LOCAL_DB_NAME < ./backups/db-$NOW.sql

echo "Replacing "$SEARCH_THIS" with "$REPLACE_WITH
./searchreplacedb2cli.php --host localhost --user root --database $LOCAL_DB_NAME --pass $LOCAL_DB_PASS --charset utf\-8 --search $SEARCH_THIS --replace $REPLACE_WITH


KEEP_BACKUP_DAYS=15

echo "Removing backups older than "$KEEP_BACKUP_DAYS" days old"
find ./backups -mtime +$KEEP_BACKUP_DAYS -type f -delete


echo "Done!"```

@luisherranz
Copy link
Contributor

Great script! Thanks @cureau!

@rdetert
Copy link

rdetert commented Feb 12, 2014

I'd like to know how to run this stuff locally. Any way we can get some cut and paste instructions? I'm migrating over from App Fog to Heroku and wp-admin is hanging and I have no idea why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants