August 21

Plugging mcrypt into PHP, on Mac OS X Lion 10.7

Perfected for Snow Leopard, now on to the king of the jungle.

 Now let’s get moving…
The following instructions cater to those who

a) are developing on OS X Lion 10.7.X,
b) need the capabilities provided by mcrypt during their PHP development, and
c) do not want to completely recompile PHP to get there.
You’ll get mcrypt loading dynamically for use in PHP with this method.
First, you are going to need a few things…
1) libmcrypt-2.5.8, which you can pick up here; NOTE: make sure to get libmcrypt and not mcrypt.
2) PHP 5.3.6 source, which you grab here; ADDITIONAL NOTE: You may update your OS X at some point, and PHP may get updated along with it. Use phpinfo() to check your version of PHP, and then download the PHP source for that version.
3) Xcode 4.1 tools, which you can pick up in the App Store.
Next, create a directory at root called ‘SourceCache’ and dump the files from #1 and #2 in there and unwrap.
Move to the libmcrypt-2.5.8 directory, and punch in this…
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ LDFLAGS=’-O3 -arch i386 -arch x86_64′ CXXFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ ./configure –disable-dependency-tracking
and then…
make -j6
and finally…
sudo make install
libmcrypt is ready – now for the PHP extension…
Move back to /SourceCache, then down to php-5.3.6/ext/mcrypt – type…

(phpize should be in /usr/bin – if not go find it and change the command as appropriate)
Then configure as follows…
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ LDFLAGS=’-O3 -arch i386 -arch x86_64′ CXXFLAGS=’-O3 -fno-common -arch i386 -arch x86_64′ ./configure –with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config
Again: make -j6 then sudo make install
Make sure you have php.ini in the /etc directory – it will probably be php.ini.default to start, particularly if you’ve just done an OS X upgrade or a clean Lion install, so rename it.

Ensure that enable_dl = On but do not remove the ; from in front of ;extension_dir = “./”.

Add one line to the .ini file in the Dynamic Extensions section…
Restart Apache – you should be all set (again), according to phpinfo():

Mcrypt on OS X Lion

Category: Lion, Mac | Comments Off on Plugging mcrypt into PHP, on Mac OS X Lion 10.7
August 19

Installation of MySQL server on Mac OS X Lion

At the time of writing this post, MySQL Server on MySQL site doesn’t have installer package for OS X 10.7 (aka Lion) but 10.6 Package works just fine for 10.7 as well. This may change soon and we may see package for OS X 10.7 as well or may be rename current package to 10.6 & above.

Installing MySQL community server:

  1. Download the latest  64-Bit DMG Archive (Apple Disk Image) from MySQL Site ( Current latest version is 5.5.14 which I’ll be using to install on my machine.
  2. Mount the Disk Image (I mean open/double-click the DMG file) and install MySQL server by double-clicking the PKG file (in my case mysql-5.5.14-osx10.6-x86_64.pkg) and follow onscreen instructions. ( It will ask for Master password, as it installs MySQL server in /usr/local )
  3. Add /usr/local/mysql/bin to your path by editing .profile file. (Optionally you can create alias to mysql and mysqladmin as mentioned in README File)
  4. You can start MySQL server by running “/usr/local/mysql/bin/mysqld_safe &” from terminal but Disk image you downloaded also consists of Startup Package & Preferences Pane which allows you to start/stop MySQL server from System Preferences and even Automatically Start MySQL Server at Startup.

*Please note /usr/local/mysql is only symlink to /usr/local/mysql-5.5.14-osx10.6-x86_64 which means when you upgrade to new version symlink will be changed to point to new version but won’t be deleting the older version. However you need to copy your data directory to new location to make sure your existing databases are intact post upgrade.
Installing MySQL Startup Scripts & Preferences Pane (OPTIONAL)

  1. Double Click MySQLStartupItem.pkg and Follow on screen instructions (You will be asked for Master Password)
  2. Double Click MySQL.prefPane which will add MySQL to OS X System Preferences and it should like something like below
  3. MySQL Preference Pane

  4. Check Automatically Start MySQL Server on Startup to start MySQL server at boot time.
Category: Lion, Mac | Comments Off on Installation of MySQL server on Mac OS X Lion
August 12

Simple script to backup all SQL Server databases

Sometimes things that seem complicated are much easier then you think and this is the power of using T-SQL to take care of repetitive tasks.  One of these tasks may be the need to backup all databases on your server.   This is not a big deal if you have a handful of databases, but I have seen several servers where there are 100+ databases on the same instance of SQL Server.  You could use Enterprise Manager to backup the databases or even use Maintenance Plans, but using T-SQL is a much simpler and faster approach.

With the use of T-SQL you can generate your backup commands and with the use of cursors you can cursor through all of your databases to back them up one by one.  This is a very straight forward process and you only need a handful of commands to do this.

Here is the script that will allow you to backup each database within your instance of SQL Server.  You will need to change the @path to the appropriate backup directory and each backup file will take on the name of “DBnameYYYDDMM.BAK”.

DECLARE @name VARCHAR(50) -- database name
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name

SET @path = ‘C:Backup’


FROM master.dbo.sysdatabases
WHERE name NOT IN (‘master’,’model’,’msdb’,’tempdb’)

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name

          SET @fileName = @path + @name + ‘_’ + @fileDate + ‘.BAK’
          BACKUP DATABASE @name TO DISK = @fileName
          FETCH NEXT FROM db_cursor INTO @name


CLOSE db_cursor
DEALLOCATE db_cursor

Category: SQL | Comments Off on Simple script to backup all SQL Server databases