Archive for the Web Development Category
How to install MySQL Server, PHP and Apache on a Mac
These instructions lead you thru the installation of the latest LAMP Stack on MacOS X Snow Leopard.
1 – Download the installation image from MySQL website here. Then double-click to mount and open the disk image.
2 – Install MySQL Server by double clicking the package “mysql-5.1.*****.pkg” and follow the menu, accepting the default values, unless you want to change something and know exactly what you’re doing.
3 – Install MySQL Startup Item by double-clicking the package “MySQLStartupitem.pkg” and follow the menu.
4 – Install MySQL Preference Pane by double-clicking the file “MySQL.prefPane” and follow the menu. This item will simplify the management of your SQL Server. You can now use the “System Preferences” panel to start and stop the database server.
5 – Enable the php module in your apache config file. You might know that Snow Leopard already ships with Apache 2.2 and PHP 5.3, but it needs a couple of tweaks to make it work smoothly. So, open /etc/apache2/httpd.conf and search for “php5_module”. Remove the comment (#) in front of the line, save and close the file, then restart apache (sudo apachectl restart)
Installing true-type (ttf) Fonts in Ubuntu
Installing true-type fonts in Ubuntu is an easy task. With literally thousands of free fonts available on the Internet, (from sites such as 1001 Free Fonts or DaFont), who could resist to add that extra spice to their documents or websites.
Ready? Here we go!
First, find and download your desired fonts into ~/Downloads/fonts. You may have to create that directory first. Then extract them and copy to the system fonts directory as follows:
cd /usr/share/fonts/truetype
sudo mkdir customFonts
cd customFonts
sudo cp ~/Downloads/fonts/*.ttf .
sudo chown root.root *.ttf
sudo mkfontdir
cd ..
fc-cache
And that’s it. If you had your favourite graphics program open during this process, you’ll likely need to restart it to see the added fonts.
Have fun!
Install JSON PHP Extension on CentOs / RedHat
I had numerous requests for info and questions relating to JSON extension in CentOS. To enable these functions in RedHat and CentOs 5, the process is really simple and fast.
NOTE: As of PHP 5.2, json extension is now standard. If you’re running PHP 5.2 or later, or like to upgrade instead, you can skip this!
- Ensure you have the necessary dependecies (php, php-pear, php-devel, gcc, make):
- $ sudo yum install gcc make
- $ sudo yum install php php-pear php-devel
- Use PECL (PHP Extension Community Library) to download the json package:
- $ sudo pecl download json
- Use PEAR (PHP Extension and Application Repository) to extract and install the extension:
- $ sudo pear install json-1.2.1.tgz
- Create a file in
/etc/php.dcalled “json.ini”, and add the following lines:- ; php-json extension
- extension=json.so
- Restart apache (gracefully if you’re running a live site:
- $ sudo service httpd restart (apachectl graceful)
- Check for availability by creating an info.php file in the web root with the following line:
- <?php phpinfo(); ?>
- Load info.php in your browser and check for JSON. You now should be all set, but if it doesn’t appear, verify all of the above steps very carefully.
ImageMagick from the command line
ImageMagick is such a cool and powerful tool to manipulate images, it’s a real shame if you don’t make use of it during your web design or photo album creation. From resizing, compositing and converting all types of file types, it’s list of usability cases is endless. It’s free and available for almost every operating system.
If you don’t have it on your system yet, here is the imagemagick download location. You might also have it in your repository, check your package manager as it might be as simple as calling “sudo apt-get install imagemagick” (on Ubuntu) or “sudo yum install imagemagick” (on Red Hat/CentOs).
Here is a small compilation of command-line tools (by no means a complete list). The list of available commands is actually sheer endless, you’ll be amazed by how powerful this application is.
imagemagick resize
convert image.gif -resize 128×128 resized_image.gif
imagemagick crop
convert image.gif -crop 240×360 cropped-image.gif (add’l params for crop location: 240×360+10+10)
imagemagick rotate
convert image.gif -rotate 90 rotated-image.gif
imagemagick mirror
convert image.gif -flop mirrored-image.gif
There are many more, actually way too many to list them all here. Have a look at the official ImageMagick usage page for a complete list of image manipulation actions.
How To Create A WordPress Plugin Or Widget
This is a very simple Tutorial to create a Partner Links plugin.
A WordPress plugin is a snippet of code that extends on the functionality of WordPress, which can add to the inner workings such as an SEO extension for example, or it can add visual elements to the site, like a Facebook link. Widgets allow these code segments to be quickly and easily enabled or disabled within predefined areas such in newer themes, like a sidebar.
Prior to WP version 2, modifications and addons had to be hard coded into the source code or the theme. With today’s version and the ability to add plugins, we have a modular system of adding and removing functionality. This also makes upgrades a lot easier.
Here I show you how to create a very simple plugin, then enable it as a widget.
A simple WordPress plugin
Let’s create a new file in plugin inside your wordpress directory. Call it anything you like, I will use myplugin.php. Then we’ll add some code that creates partner links in your sidebar:
<?php
/*
Plugin Name: My Plugin
Plugin URI: http://articles.itecsoftware.com/
Description: Partner Links WordPress Plugin
Author: Peter
Version: 1.0
Author URI: http://articles.itecsoftware.com/
*/
function partnerLinks() {
echo “<h2>Partner Links</h2>”;
}
?>
Code inside /* */ are called comments, and in this case are used by WordPress to display information to the webmaster or whoever installs and configures it. The function partnerLinks will display the title, nothing more at this point. Save the file and you now should have a new plugin visible in the WordPress plugin section.
Nginx and memcached module
Memcache is traditionally used as a module inside server side scripts, such as PHP, ASP, ColdFusion and others. And it’s doing a terrific job, as long as it’s implemented correctly.
But if we look under the hood of the actual Memcache application, and I’m not talking about the PHP or ASP extension, but rather the executable that’s running as a daemon under linux, for example, it is a rather simple database like application running in memory. Now there are two basic actions that need to be performed to use it, one is writing info into memcache, the other is reading it. In a typical scenario, there are many reads for one write, that’s the whole point, isn’t it. But what if we can isolate the reading from the server side scripts, and let a small high speed module do that for us.
Auto Create Thumnails The Easy Way
Ever wondered it there is an easy way to resize your images or quickly create thumbnails from your favorite pictures?
Search no more, the awesome little utility ImageMagick does it for you.
Install it using your package manager, most of them should have it in their repository.
sudo apt-get install imagemagick
Once installed, this command will create tumbnails for all JPG’s in the current directory, 200 pixel wide/high on the longest side. Eg. if your image is in landscape layout, it’ll be 200 pixel wide, in portrait format it’ll be 200 pixel high.
for file in *.jpg ; do convert -resize 200 “$file” t”$file”; done
That’s it. Simply change 200 to the size of your liking, or change the extension if your images are in gif, png or any other image format.
INSERT IF NOT EXISTS in MySql
INSERT IGNORE is the syntax that does mimic INSERT IF NOT EXISTS, as there is no direct command as stated in the title, at least not in the current release of MySql.
The statement INSERT IGNORE (and to some extent REPLACE INTO) does essentially the same thing, inserting a record if that given record does not exists.
See the following samples:
Web Site Tuning – Speed up your web pages
Ever wonder why some sites take forever to load while others appear in a snap? Let alone the associated user experience. It’s just more fun browsing a site that loads fast. And since Google now rates Adsense weight by load times, it makes more sense than ever to ensure that our pages load as fast as possible.
Especially with high performance websites, page load times are of highest concern. Not only user experience is directly affected, but bandwidth and hardware costs are often directly related to it. Yahoo did a marvelous job researching the elements that affect page loads and in response created the utility yslow.
Eclipse Ganymede and PDT 2.0 for PHP Development
With the release of Eclipse Ganymede, the IDE has become even better. I remember using Zend Studio for Eclipse 6.0.1 for about two weeks, after giving up and moving over to Netbeans 6.5. Too many issues with the debugging part, constant exceptions and a sizable slow down when working on web pages just got me too frustrated.
Now Ganymede is out for a while, but I just haven’t given it a change until now. And I’m positively surprised. While still fairly slow and lagging wile editing html/css content, gone are the countless exceptions, the cumbersome, seemingly endless installation procedure and also xDebug integrates quite nicely with the IDE. There are still a few caveats during the install, especially on a 64 bit environment.
Install Subversion on 1and1 Hosting Provider
There is just no better solution than having your source code available to you over the internet, when working on several projects at different location. I am using and1 as my hosting provider, and it I could have my repository for all source code there as well, I could work anywhere and have access to the latest code, check history, compare different versions and so on.Here is the outline that I have gone thru in the quest of setting up Subversion hosted on 1and1:
(more…)