Tag Archives: database

How to install PHP GeoIP in Ubuntu

This instructions will install GeoIP over Ubuntu. It is tested over Ubuntu 12.04 LTS.

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

kahwee:~ kahwee$ sudo pear update-channels
Updating channel "doc.php.net"
Channel "doc.php.net" is up to date
Updating channel "pear.php.net"
Channel "pear.php.net" is up to date
Updating channel "pecl.php.net"
Channel "pecl.php.net" is up to date

Continue reading “How to install PHP GeoIP in Ubuntu” »

How to automate GeoIP updates on Linux

This works for Ubuntu, Debian and CentOS distributions. You need a valid license key from MaxMind. This is available as a subscription at a nominal fee.

If you have installed GeoIP successfully, you should have the geoipupdate program. If you don’t, you need the run the following.

Install over Ubuntu or Debian:

sudo apt-get install geoip-bin geoip-database libgeoip-dev

Install over CentOS:

sudo yum install re2c geoip geoip-data geoip-devel

Both libgeoip-dev and geoip-devel are required for compiling PHP’s GeoIP.

Once you run geoipupdate the first time, it tells you about a missing GeoIP file.

root@gladlycode:~# geoipupdate 
Error opening GeoIP Configuration file /etc/GeoIP.conf

Now you copy over from the default file:

mv /etc/GeoIP.conf.default /etc/GeoIP.conf

If you now run geoipupdate, you get the following:

MD5 Digest of installed database is f5c2f7eed9331dcaa99b7a6b4633b684
Invalid UserID

Continue reading “How to automate GeoIP updates on Linux” »

How to use Symfony with existing database

I recently had to start a Symfony2 project using an existing database. Here is a rough guide on how it is done.

Firstly you have to update your app/config/parameter.ini to your existing database:

[parameters]
    database_driver="pdo_mysql"
    database_host="127.0.0.1"
    database_port=""
    database_name="gladlycode"
    database_user="root"
    database_password="root"
    mailer_transport="smtp"
    mailer_host="localhost"
    mailer_user=""
    mailer_password=""
    locale="en"
    secret="0bdc03a00514e9c1595219d165115d532"

My bundle is named GladlyCodeBundle, you will have to rename this. Based on this I do a map of existing database tables into XML format, note that the em dash is 2 dashes due to conversion by WordPress:

php app/console doctrine:mapping:convert xml ./src/Gladly/CodeBundle/Resources/config/doctrine/metadata/orm --from-database --force

You need to change the ‘Gladly/CodeBundle’ part to fit your project as the next step will look to import from the default location.

If you get any errors of this sort:

PHP Fatal error:  Call to a member function getColumns() on a non-object in /Users/kahwee/projects/gladlycode/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php on line 133
PHP Stack trace:
PHP   1. {main}() /Users/kahwee/projects/gladlycode/app/console:0
PHP   2. Symfony\Component\Console\Application->run() /Users/kahwee/projects/gladlycode/app/console:22
...

It could be due to one of your tables not having a primary key. Just assign it the appropriate primary to continue with the import process.

Then I import them with annotations:

php app/console doctrine:mapping:import GladlyCodeBundle annotation

Finally I regenerate them into entities:

php app/console doctrine:generate:entities GladlyCodeBundle

And that’s it. Everything is imported.

Tools of the trade

Every web developer uses his/her set of preferred tools. Here’s mine:

  • Text editor: SublimeText 2, because it loads fast and I swear by its open by file name feature
  • Computer: MacBook Air 13″, a decent screen size with good portability. I like working at cafés and this gadget fits my lifestyle.
  • Browser: Chrome 18 or 19. I lost track of Chrome’s version, comes with Chrome is the excellent debugger I cannot live without.
  • CSS generator: Less, because Less can be compiled by JavaScript on the client side. It’s easy to get started developing.
  • Database engine: MySQL InnoDB.
  • Database browser: Sequel Pro, never found a replacement for this. I’ve been using this for 3 years, by far the best.
  • Revision control: Git or SVN. My vote is to Git but my company is still on SVN.
  • Image editor: Photoshop. Embarrassingly I am one of those that will just launch Photoshop to make PNGs with alpha-transparency. There are probably better tools out there but I can’t get used to them.
  • Programming languages: PHP for web development. JavaScript or Ruby on scripting automation. I still use Expect for a bunch of server-side tasks, I cannot move away from that still.
  • Web server: Apache for development. It’s all because of PHP’s xdebug. My colleagues use .htaccess often too. I use nginx for production usually.
  • Load profiling: Seige, it’s simple and reliable.

Other tools include:

  • LiveReload 2 has been extremely convenient and it has been part of my workflow for months. I never looked back.
  • Bash alias lets me quickly navigate through the trenches of my messy directories. I also use it to pull for Git quickly.

MySQL.com compromised by SQL injection

This day just had to come:

MySQL.com compromised

MySQL.com (the official site for the MySQL database) was compromised via (shocking!) blind SQL injection. A post was sent today to the full disclosure list explaining the issue and dumping part of their internal database structure.

What is worse is that they also posted the password dump online and some people started to crack it already. Some of the findings are pretty bad, like that the password used by the MySQL director of product management is only 4 numbers (6661) and also posted multiple admin passwords for blogs.mysql.com…

MySQL have not said anything about this attack, but we will post more details as we learn more about it.

Source: Sucuri

The irony.

Oracle shuts down open source test servers

Oracle shuts down open source test servers that PostgreSQL uses to test their builds. PostgreSQL is competing with Oracle’s MySQL and Oracle Database.

Oracle shuts down open source test servers

Like most open source platforms, PostgreSQL relies on an army of distributed volunteers. It is volunteers that, for example, operate the PostgreSQL Build farm, a “distributed, automated build and verify system” built by enthusiast Andrew Dunstan.

Oracle has shut down servers Sun Microsystems was contributing to the build farm for open source database software, PostgreSQL, forcing enthusiasts to scramble to find new hosts to test updates to their software on the Solaris operating system.

“It’s a vital piece of the infrastructure for developing PostgreSQL,” Dunstan told iTnews. “Before it existed, if some change we made broke on some platform, it was often weeks or months before we found out about it. Now we know within hours.”

At the start of July, Oracle shut down its three PostgreSQL build farm servers without warning, leaving the PostgreSQL community rushing to find replacements.

Dunstan said he “suspects” Oracle does view PostgreSQL as a competitor. (Source: IT News)

I love to see Oracle post their financial results, they have made quite a bit of cost cutting moves since the acquisition. You can hardly blame them too; they’ve got shareholders to report to. After all, doing too much charity work on open source is partly why Sun Microsystems failed in the first place.

Moved to Rackspace Cloud

A couple of days ago, I encountered a database corruption. One sentence: My access log grew so huge it took up 100% of the disk space; MySQL can no longer write the database files and a few tables got corrupted.

Okay I cheated on the one sentence.

Rackspace Cloud has similar build as Slicehost (my previous host). I moved a few of my blogs over. Currently Slicehost is like an expensive DNS server. That said, Rackspace Cloud is cheaper than Slicehost. Slicehost is a subsidiary of Rackspace. Well anyway, if you do like to use Rackspace and would like to make my day, use my referrer code ‘REF-KW’ without quotations. It gives me some rebate, I think.