Posts Tagged ‘Debian’

Update your Server to PHP5.4+

13 Apr

With many new features and more speed it makes sense to upgrade to PHP5.4.
It is also a requirement when you start using CakePHP3.0 (the dev releases) or code that contains short array syntax.
So the sooner you upgrade the better.

The following examples are for Debian Squeeze.


Make sure you have a backup of your server/files/db and your php.ini and other config files.


Debian doesn’t offer this natively.
We need to add some special packages for this.

Open the sources list using nano, vi or the edit tool of your choice:

vi /etc/apt/sources.list

And add those two lines at the end:

deb stable all
deb-src stable all
deb squeeze-php54 all
deb-src squeeze-php54 all

We need a public key to avoid those warnings showing up:

cat dotdeb.gpg | apt-key add -

Use apt-get update and apt-get install php5.

That should take care of it. PHP5.4.x should now be installed and ready to work with.
And have fun playing around with CakePHP3.0 or some new features of PHP5.4 🙂

Keep other packages up to date

Also make sure other packages are up to date using apt-get upgrade.

If it doesn’t install right away, one might also need apt-get dist-upgrade. Careful with this, though. It might install/overwrite more than it should.

Dev Libraries

If php5-dev libraries are needed, they can be installed via apt-get install php5-dev.

Key Benefits of 5.4

  • Speed/Stability
  • Traits
  • Closures and $this
  • callable as typehint
  • Short array syntax (no mixin of method brackets and array brackets anymore)

The only real benefit coming in 5.5 is "Generators" which will allow handling of huge arrays and larger amount of data more gracefully.
But other than that 5.4 is just fine for the moment.

Features of 5.3 you can now also use in Cake3

  • Namespaces
  • Closures
  • Late Static Bindings
  • Ternary shorthand form
  • Magic method __callStatic()
  • Nested exceptions

These features weren’t used in Cake2 core (and probably most apps) so far due to the BC for PHP5.2. If you already updated your minimum requirement for your server and application, those
are also now of great use.

Further tips

The encoding even in more current verions of apache usually defaults to the old "ISO-8859-1" one. You should make it "utf-8" per default in your php.ini:

; PHP's default character set is set to empty.
default_charset = "utf-8"

Then even error pages or non-normal responses will be properly displayed. It is sad that even 2014 and in PHP5.4 the default is still not a proper one – probably due to BC or something.

No Comments

Posted in PHP


Cakephp Console on Linux systems

24 May

You could hard-wire the Cake path into the environment.
With multiple cake core versions on a single system, sometimes it is better not to do that, though.
So I just follow the following guidelines:

  • Only add the PHP path to the system environment path (not the cake one!)
  • Always navigate to your app folder.
  • Call your shells from there, either with Console/cake (if you have an app Console folder with cake file) or ../lib/Cake/Console/cake (core cake file).


The documentation in the cookbook is pretty well written.

Here with a little bit more detailed explanation:

# m h dom mon dow command
*/5 *   *   *   * cd /full/path/to/app && Console/cake myshell myparam

The tool Crontab is used here. This config file contains an example with a cronjob that is executed every 5 minutes.
Basically, you just tell the script to navigate into your app folder and call your shell as you normally would as real user (always from inside your app folder).

If you don’t have an app cake file (I don’t for some older projects), you can also use the core cake file just as fine:

# m h dom mon dow command
*/5 *   *   *   * cd /full/path/to/app && ../lib/Console/cake myshell myparam

You can edit the crontab for the www-data user, for example, using

crontab -e -u www-data

Using the user "www-data" (or a user that is affiliated with it) is advised to prevent running into issues with file access when creating or modifying files.
It is also a security issue using a user with more or different rights than he should have or needs.

Also note that your "cake" file (either app or core) needs to be executable, so make sure you have set the appropriate rights for it.

CakePHP 2.x and windows

See the updated windows post for the correct path here.
Also note the way more comfortable quick-links if you need to use 1.x and 2.x parallel.

1 Comment

Posted in CakePHP