tags:

views:

290

answers:

1

Hi!

I'm using Phing to push a wordpress installation to my production server. Is it possible to define the wp-config properties inside my build file, and then have phing replace the wp-config contents to use those variables?

Like this:

<property name="prod.db_name" value="wordpress" />
<property name="prod.db_user" value="root" />
<property name="prod.db_password" value="toor" />
<property name="prod.db_host" value="prod.host.com" />

I then want a phing task which takes those values and replaces my wp-config with the correct properties.

How would i do this?

Thanks

+2  A: 

Yes, I think it is. Searching in the phing documentation led me to the CopyTask (appendix B), and the ReplaceRegexp filter (appendix D2).

Try to include this task in your build target (after defining your properties):

<copy file="./config-sample.php" tofile="./config.php">
  <filterchain>
    <replaceregexp>
      <regexp pattern="(define\('DB_NAME', ')\w+('\);)" replace="\1${prod.db_name}\2"/>
      <regexp pattern="(define\('DB_USER', ')\w+('\);)" replace="\1${prod.db_user}\2"/>
      <regexp pattern="(define\('DB_PASSWORD', ')\w+('\);)" replace="\1${prod.db_password}\2"/>
      <regexp pattern="(define\('DB_HOST', ')\w+('\);)" replace="\1${prod.db_host}\2"/>
    </replaceregexp>
  </filterchain>
</copy>

This task will copy config-sample.php (provided in the wordpress distribution) to config.php, performing a file transformation through regex replacement filters, thus overwriting the example parameters to your wanted values.

You might want to configure other parameters as well, like DB encoding & collate, security parameters (at least those ones), table prefix, language...

streetpc
Thanks for your comment. I'm going to check it out asap.
alexn
Thanks again! I got it working prop!
alexn
You're welcome.
streetpc