Question

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

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top