Asked  7 Months ago    Answers:  5   Viewed   28 times

I'm beginning a new project in PHP and I'd love to get some feedback from other developers on their preferred strategy for PHP deployment. I'd love to automate things a bit so that once changes are committed they can be quickly migrated to a development or production server.

I have experience with deployments using Capistrano with Ruby as well as some basic shell scripting.

Before I dive head first on my own it would be great to hear how others have approached this in their projects.

Further information

Currently developers work on local installations of the site and commit changes to a subversion repository. Initial deployments are made by exporting a tagged release from svn and uploading that to the server.

Additional changes are typically made piecemeal by manually uploading changed files.

 Answers

20

For PHP, SVN with Phing build scripts are the way to go. Phing is similar to ANT but is written in PHP, which makes it much easier for PHP developers to modify for their needs.

Our deployment routine is as follows:

  • Everyone develops on the same local server at work, every developer has a checkout on his machine back home as well.
  • Commits trigger a post-commit hook which updates a staging server.
  • Tests are ran on staging server, if they pass - continue.
  • Phing build script is ran:
  • Takes down production server, switching the domain to an "Under construction" page
  • Runs SVN update on production checkout
  • Runs schema deltas script
  • Runs tests
  • If tests fail - run rollback script
  • If tests pass, server routes back to production checkout

There's also phpUnderControl, which is a Continuous Integration server. I didn't find it very useful for web projects to be honest.

Wednesday, March 31, 2021
 
altermativ
answered 7 Months ago
99

I would store the dates in the MS-SQL format to assist in using the date manipulation functions in T-SQL to their fullest. It's easier to write and read

SELECT * FROM Foo
WHERE DateDiff(d,field1,now()) < 1

Than to try and perform the equivalent operation by manipulating integers

To convert a MsSQL date into a unix timestamp use dateDiff:

SELECT DATEDIFF(s,'1970-01-01 00:00:00',fieldName) as fieldNameTS
FROM TableName
WHERE fieldName between '10/1/2008' and '10/31/2008'

To Convert an Unix Timestamp into a MsSQL Date, you can either do it in PHP:

$msSQLDate = date("Y-m-d H:i:s", $unixDate );

or in MsSQL

INSERT INTO TableName ( 
  fieldName
) VALUES (
  DATEADD(s,'1970-01-01 00:00:00', ? ) 
) 

Where parameter one is int($unixDate)

Wednesday, March 31, 2021
 
Tak
answered 7 Months ago
Tak
84

In Phing, if your deployment is Phing based, you could use the ReplaceTokens filter.

Example (not tested):

<target name="-modify-config"
        hidden="true" description="Modifies the xyz.conf ">
  <copy file="${some.directory}/xyz.conf.dist"
        tofile="${some.directory}/xyz.conf"
        overwrite="true" >
    <filterchain>
      <replacetokens begintoken="%" endtoken="%">
        <token key="KEY_A" value="${value.a}" />
        <token key="KEY_B" value="${value.b}" /> 
      </replacetokens>
    </filterchain>
  </copy>
</target>
Saturday, May 29, 2021
 
Sethunath
answered 5 Months ago
79

Just ran into the same problem. The key is to not use deploy_via copy but rather set :local_repository

This should be set to the URL you use to access the repository from your development computer/laptop.

So mine has

set :repository, "file:///srv/git/myapp.git"
set :local_repository, "nameOfHostFromSSHConfig:/srv/git/myapp.git"

Seems to have worked. Just remember to then remove the deploy_via copy line as well.

Wednesday, July 28, 2021
 
mistero
answered 3 Months ago
83

Good previous answers so just a little to add here:

  • underscores are really annoying for ESS users; given that ESS is pretty widely used you won't see many underscores in code authored by ESS users (and that set includes a bunch of R Core as well as CRAN authors, excptions like Hadley notwithstanding);

  • dots are evil too because they can get mixed up in simple method dispatch; I believe I once read comments to this effect on one of the R list: dots are a historical artifact and no longer encouraged;

  • so we have a clear winner still standing in the last round: camelCase. I am also not sure if I really agree with the assertion of 'lacking precendent in the R community'.

And yes: pragmatism and consistency trump dogma. So whatever works and is used by colleagues and co-authors. After all, we still have white-space and braces to argue about :)

Saturday, July 31, 2021
 
Jeffrey Stilwell
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :