configuring compatible development and production

2019-08-30 03:12发布

问题:

I am developing a Magento site. I have access to a local host and a remote host and would like to somehow configure development and production environments. On the remote host I restore the database data that was backed up on the local host, but when I do so, I overwrite the host's base name and this causes the site to be redirected to a nonexistent URL when the page is loaded. How can I avoid this clash:

I want to be able to develop either (a) on http:// remotehost/foobardev and back up my data to http:// remotehost/foobar or otherwise (b) develop on http:// localhost/foobar and deploy on http:// remotehost/foobar . I want to know how to transfer the database data back and forth without overwriting the values found in Magento Admin Panel -> System -> Configuration -> Web -> Unsecure Base URL / Secure Base URL when I run mysql and use the mysql command source to reinstate the database entries found on the development site onto the production site.

So, I would like an easier way to restore the database contents without overwriting the base url configured in magento admin panel as doing so would cause a redirect to a nonexisting or wrong place on each page load and thus render the system unusable.

回答1:

Not exactly a SO type of question. Magento EE has staging built in and can merge your data as well. You have to understand that syncing data from dev to live is not easily possible without some serious sync framework that keeps track on state of every row and column and knows what data is new and what is old and solve syncing conflicts.

Here's your flow based on assumption that you are using CE and does not have data migration tools bundled.

  • setup live database and count that data will move only from live to dev and never from dev to live as you don't have data migrations. Every config you need to make and preserve in database level do it on live database (test them out in dev environment and then create in live)
  • make a shell script , fabric script whatever deployment script you are comfortable with that will export live db dump , deletes dev database if exists and create a new database and import live database to it, run a pre or post sql script that will change/delete config values that are environment dependant (like base_url, secure_base_url etc)
  • to avoid double data entry always create all attributes and config values that you need to preserve with magento setup scripts.

Same goes about code and here's a common setup scenario with live, stage and development environments

  • one master version control (preferably bare just to avoid that someone will change files there) repository based on clean magento versions tree
  • separate branches for each environment (live, stage, dev(n)) and a verified code flow from dev (where you develop and can have broken codebase state) to stage (where release candidate resides and is ready for testing and does not change) from stage to live (where your live code is in stable state)
  • every developer works on a checkout from dev branch and commits to it's own dev branch and then pushes changes to dev where they can be evaluated and decided if changes are mature enough for staging
  • stage is a place where release candidate lives and client can test (or automated tests) and diagnose if it's ready enough to be released, no one ever changes code here and code comes from dev branch
  • live is live and running version where no one ever changes any code directly . If tests are passed code can come here from stage only

so to visualise it better imagine your codebase residing in git.

myproject_magento_se (your project git repository on bitbucket.org or in github or wherever you can host)
--> master (branch with all clean magento versions from your current to latest)
--> dev (git checkout -b master (or by specific version from master) 
--> stage (while on dev: git checkout -b stage)
--> live (while on stage: git checkout -b live)

and imagine your hosts setup like this:

www.mylivesite.com =  git clone yourgitrepo; git checkout live;
stage.mylivesite.com = git clone yourgitrepo; git checkout stage;
dev.mylivesite.com = git clone yourgitrepo; git checkout dev;

For all this you better have deployment scripts that do switching and code and database lifting between environments with a push of the button.

Here's a few common actions that you need to perform daily with every software project

  • move/reset data from live to stage from live to dev (have obfuscation calls if needed to scramble or change client related data)
  • move code from dev to stage
  • move code from stage to live
  • reset/create any dev with live state (Data and code)

have fun :) and go through this thread as well https://superuser.com/questions/90301/sync-two-mysql-databases and all other you can find searching on SO in similar matter.



标签: magento