Friday, September 23, 2011

Database Configuration for MSSQL

If you are connecting to a MSSQL database, first ensure that your php-mssql package is installed. A simple command can show you this:
$ rpm -qa | grep php-mssql
The output should look something like this:
php-mssql-5.3.8-4.el6.remi.x86_64
Next check that freetds is installed.
$ rpm -qa | grep freetds
The output should look something like this:
freetds-0.82-6.el6.x86_64
You should now be able to connect to your MSSQL database directly from the command line. Make sure to replace the server, user and password with valid information.
$ /usr/bin/tsql -S [mssql.servername.or.ip] -U [ValidUser]
locale is "en-US.UTF-8"
locale charset is "UTF-8"
Password: [password]
1>
Enter "quit" to exit your successful connection. If the tsql command doesn't return the 1> prompt, verify that you can get to your MSSQL server with the following command:
ssh [mssql.servername.or.ip] -p 1433
Also verify that your username and password are valid.
At this point you can set your database configuration to connect to the database.
    var $default = array(
        'driver' => 'mssql',
        'persistent' => false,
        'host' => 'mssql.server.or.ip',
        'login' => 'username',
        'password' => 'password',
        'database' => 'database',
        'prefix' => ''
    );
Through much trial and error I've discovered that if you connect directly to the server in this manner some commands, such as mssql_bind, mssql_execute, and mssql_init don't work. Now you could setup and execute stored procedure commands through mssql_query this isn't as secure.
Instead, set up a freetds configuration for the server, connect with that instead, and the commands will now work fine.
Edit /etc/freetds.conf and add the following block:
[ServerIdentifier]
        host = [mssql.servername.or.ip]
        port = 1433
        tds version = 8.0
Then use the ServerIdentifier you chose instead of the server name or ip in the database configuration host variable and you're all set.

Monday, September 19, 2011

Multiple Applications, One Cake (or more)

With running multiple CakePHP applications, keeping them all up to date with the latest security fixes can be an issue. Instead of having to update each one individually, having a shared cake installation can be beneficial.

While there are many different methods of doing this, I couldn't get any of the ones I tried to work. So I deconstructed the process and made it VERY simple and functional. Obviously since we are using symlinks this is applicable only on Linux.

Step 1: Extract CakePHP to where you want your application to reside. e.g. /var/www/html/myApp/
Step 2: Extract CakePHP to where you want your Cake to reside. For ease in updating, I named mine the same as the version number. e.g. /var/www/cakephp-1.3.11
Step 3: While unnecessary, I found it convenient to create a symlink to the cake directory named 'cake', otherwise you have to either name your cake folder the same every update, or update all your application symlinks
$ ln -s /var/www/cakephp-1.3.11 /var/www/cake
Step 4: Delete the cake directory in your application.
$ rm -fr /var/www/html/myApp/cake
Step 5: Create a symlink in the application folder to the shared cake folder.
$ ln -s /var/www/cake/cake /var/www/html/myApp/cake
Now any application that has that symlink in it instead of the cake folder will use the shared folder. Update the shared folder once, all applications that are sharing it get updated.
Step 1: Extract new version of cake to same directory as old version of cake. e.g. /var/www/cakephp-1.3.12
Step 2: Update your shared simple symlink to the new directory
$ ln -f -s /var/www/cakephp-1.3.12 /var/www/cake
That easy.

If you want to have an application use an older version of Cake, just install it in the application itself as normal, OR install it next to the other version and change the symlink in the app folder to match the different version of cake.
Step 1: Extract different version of cake for sharing. e.g. /var/www/cakephp-2.0.0-RC2
Step 2: Update your application's symlink to the new directory
$ ln -f -s /var/www/cakephp-2.0.0-RC2/cake /var/www/html/my2.0App/cake