[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-users] OT connecting to a mysql database



"Jay Fesco" <jay@xxxxxxxxxxxx> wrote:
> You're right, it's OT.  You may want to join the MySQL users list:
>
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)

Good advice.  They're the best resources for this problem.  I'm going to
offer an alternative to your localhost solution below, which by the way is a
good one, but might not be feasible for everyone.  My solution is a little
more complex, but fits nicely into my development process.

> That being said, I develop with MySQL and UltraDev as well, but I NEVER
> connect directly to my production databases on the Raq from UD.  I emulate
> them on localhost, do my testing there, and then upload as needed.

I have several solutions, but in general here's what I do.  For each site I
create several parallel versions.  They are generally located off of the
/home/sites/sitex directory in parallel directories.  For example -
production, development and demo.  I either setup the production site
through the GUI or manually in httpd.conf and then manually edit the
VirtualHost container for the site to change the DocumentRoot from:

DocumentRoot /home/sites/sitex/web

to:

DocumentRoot /home/sites/sitex/production/web

I then find the line in httpd.conf that reads "Listen 80" and add 2 more
lines to tell Apache to listen on 2 additional ports.  I'll allow you to
pick ports that make sense for you, but for the example let's say they're
1001 and 1002.  I add the following lines:

Listen 1001
Listen 1002

The development version of the site listens on port 1001 and the demo
version on port 1002.

Then I copy and paste the VirtualHost container for sitex twice (once for
each port).  I edit the new VirtualHost containers making the following
changes (this example is for the development copy, comments after ##):

<VirtualHost 123.45.67.89:1001> ## Add the colon and port number
DocumentRoot /home/sites/sitex/development/web ## change production to
development

and change all of the :80 to :1001

Then create the appropriate directories on the server and restart Apache
(/etc/rc.d/init.d/httpd restart).  I then create separate versions of each
database.  Given them names like dbname_production, dbname_development and
dbname_demo.  In the scripts for each site I either hardcode the dbname or
determine it automatically using a function I create that parses something
like DOCUMENT_ROOT.

Then it's trivial to move copies of the web files and database between
versions.  A simple "rm -r production; cp -pR development production",
followed by "mysqldump dname_development >> dbname_development.dump;
mysqladmin drop dbname_production; mysql < dbname_development.dump" (if this
makes sense case by case) and the production site has been updated from the
development version.  I do the same with the demo version, sharing parts of
a site/app with a client as I see fit.  I then don't have to worry whether
they corrupt my development data, see incomplete functionality I don't want
them to or otherwise interfere in the development process.

To view the non-production version of the site in a browser the user must
enter the port #.  For example, http://host.domain.tld:1001/page.php.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/