Wednesday, March 16, 2011

Creating a new MySQL database with user

I do the following:
  1. Start -> Programs -> MySQL -> MySQL Server 5.1 -> MySQL Command Line Client and provide password.
  2. At mysql> prompt, type show databases;. This will display the existing databases.
  3. To create a database "love", I'll run create database love;.
  4.  Now if you try show databases, you'll see the "love" database.
But I want to be more fancy. I want the database love to be accessible by "lovely" with password "deadly" only from local machine. To do that execute the following query:

mysql> CREATE USER 'lovely'@'localhost' IDENTIFIED BY 'deadly';
Query OK, 0 rows affected (0.00 sec)


mysql> grant all privileges on love.* to 'lovely'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec) 
 

Installing MySQL on Windows XP

Following worked for me:
  1. Download MySQL from http://dev.mysql.com/downloads/mirror.php?id=401744
  2. Double click on the installer and do a typical install.
  3. On configuration, select developer machine
  4. Select Multifunction database
  5. Select OLTP (that's what I wanted).
  6. Provide root password
  7. Click Finish to complete the installation
Once the server is installed and configured, I downloaded the workbench. This is a neat tool that I like. Download it from http://dev.mysql.com/downloads/mirror.php?id=401808

Configuring PHP 5 and Apache 2.2 on Windhows XP

First thing first. Install Apache:
  1. Download Apache from this location http://apache.deathculture.net//httpd/binaries/win32/httpd-2.2.17-win32-x86-openssl-0.9.8o.msi
  2. Double Click on the installer and click "Next -> Next" to install via default setting.
  3. Now I do not want to use others to use my Apache Web server and hence to disable it from being used from outside I am going to limit the server availability to localhost. To do that goto C:\Program Files\Apache Software Foundation\Apache2.2\conf and open httpd.conf.
  4. Search for ServerName and Replace the line with ServerName localhost:80. This makes it only available via localhost.
  5. Also, change the value of ServerAdmin to ServerAdmin admin@localhost.
  6. Now restart the server via Start -> Programs -> Apache HTTP Server -> Control Apache Server -> Restart and open a browser and type http://localhost/. If everything works out well, you'll see the text "It works!".
Now let's focus on PHP.
  1. Download PHP installer from http://windows.php.net/downloads/releases/php-5.3.5-Win32-VC9-x86.msi location
  2. Double click on the installer to run it.
  3. In Webserver setup page select Apache 2.2.x module and hit next.
  4. Provide location of Apache configuration files location in my case it is C:\Program Files\Apache Software Foundation\Apache2.2\conf\
  5. Hit Next, Install and Finish to complete the installation.
  6. Now if you try to restart the server, it will fail. That's because the PHPIniDir and LoadModule values are wrong.
  7. So, change the following in the httpd.conf
    1. PHPIniDir "C:/Program Files/PHP"
    2. LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
  8. Now restart the server. It should work.
  9. To check if PHP is working create a file hello.php at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs
  10. Edit the file and add <?php phpinfo(); ?> 
  11. Save it restart the server and open browser. Open url http://localhost/hello.php and you should see PHP related information.
Once you are done with the basic installation, you can make some changes which will make your life much more easier. Like the following:

short_open_tag - if you like <? better than <?php, you can edit C:\Program Files\PHP\php.ini and change short_open_tag = Off to short_open_tag = On. You can test it by changing hello.php. Replace  <?php phpinfo(); ?> to <? phpinfo(); ?>. Save it and rerun from browser.

Default Index Page - for lot of php application the default page is index.php instead of index.html. So, it is recommended that you add index.php before index.html. Following line of code in httpd.conf should take care of that:
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

      Sunday, March 13, 2011

      Is Ruby on Rails (RoR) really not scalable?

      I was thinking about learning ruby lately. After, my experience with Java, C# and PHP and I saw a job with $200K, I think it is high time I learn Ruby. But I saw some adverse listing about RoR. It seems twitter failed to scale with RoR. So, I decided to make a new dating site with RoR. My target is to support 100 hits per second (i.e. 8.5 million hits per day) and deliver the content below some benchmark value.

      It is going to be hard. I have no idea about Ruby. It will take a while for me to master Ruby. However, I should be more comfortable with optimizing with it. So, stay tuned.

      Saturday, March 12, 2011

      Monthly water change of fish tank

      I was thinking about setting up an aquarium for my son who is 6 years old for a while. So, I bought a 30 gallon hexagonal fish tank from craigslist for $50, a filter, stand and heater included. What a Steal! I set it up with help of my brother and son at the beginning of the year. The tank is new fully cycled and has 10 gold fish and a plecostomus. I know they do not go together but I had to. That is a different story for some other day.

      Now,  I do water change every month or so. I only change approximately 5 gallon of water. I have a bucket that I only use for this purpose. Before I change the water, I scrub the glass with a scrubber. I then drain the water and try to pick up any waste from the aquarium bed. I am always careful not to disturb the bacteria colony that has set in. As everyone knows, the water would have been really toxic.

      I use tap water conditioner to dechlorinate the water. I slowly pour the water back in the tank till it doesn't overflow. Done!