How to permanently raise ulimit 'open files' and MySQL 'open_files_limit'

The default ulimit (maximum) open files limit is: 1024--Which is very low, especially for a web server environment hosting multiple heavy database driven sites.

This ulimit 'open files' setting is also used by MySQL. MySQL automatically sets its open_files_limit to whatever the system's ulimit is set to--at default will be 1024.

NOTE: MySQL can NOT set it's open_files_limit to anything higher than what is specified under ulimit 'open files'--you can set it lower, but not above the 'open files' limit.

Anyhow...

This is how we raise the ulimit

To check the limits:


ulimit -a

You will see something like:

Tags: Linux admin mysql

How to optimize and auto repair all MySQL databases using SSH

Here's a simple command to optimize and auto repair all tables in your MySQL database.


mysqlcheck -uroot -p --auto-repair --optimize --all-databases

This is the same thing as using PHPMyAdmin, however, you don't need to do this one by one for each database, select all tables, and optimize--and not to mention if you wanted to repair a database prior to optimizing, it will take 2x as long.

Tags: mysql Server Linux database

How to move MySQL database -- the simple way

There are plenty of articles about how to move mysql to another directory or partition by telling you to mess with the my.cnf by changing all the references of datadir and socket to the new location.

Example:


[mysqld]
datadir=/new/location
socket=/new/location/mysql.sock

Don't do this... Not only will it waste your time, but likely won't work for half the server setups. Reason being there are other factors at play when you're changing things, it's not only the my.cnf that you have to worry about. For example, if you're using Ubuntu, you may be using AppArmor and you'll also have to specify the new directory in /etc/apparmor.d/usr.sbin.mysqld

Tags: mysql Server Linux database

MySQL dump all databases via mysqldump -- the proper way

Here's a command that properly dumps all databases, in case you wanted to restore a full backup.

For whatever reason, many sites are using improper characters ( ' –– ' , ' – ' ) to display this mysqldump command line--copy pasting will throw up an error stating something like:


mysqldump: Got error: 1049: Unknown database '??extended-insert' when selecting the database

Here is a sample of wrong characters, which appear just fine, but won't work:


mysqldump ––extended-insert ––all-databases ––add-drop-database ––disable-keys ––flush-privileges ––quick ––routines ––triggers > all-databases.sql

or


mysqldump –extended-insert –all-databases –add-drop-database –disable-keys –flush-privileges –quick –routines –triggers > /root/all-databases.sql

Tags: mysql linux server admin

Add "You Save" amount and percentage to Special Price in Magento

In order to display a "You Save" for "Special Price" products in magento--to make it look similar to amazon's price display--you can do the following:

Copy

app/design/frontend/base/default/template/catalog/product/price.phtml

to

app/design/frontend/default/YOURTEMPLATE/template/catalog/product/price.phtml

Then in price.phtml that you just copied, right above:


Insert:



$_savePercent = 100 - round(($_finalPrice / $_price) * 100);
$_saveAmount = number_format(($_price - $_finalPrice), 2);
?>
Tags: magento price display

How to set date and time automatically in CentOS

tzselect

Answer the 3 locations questions. Then create a symlink to your local time.

rm -rf /etc/localtime
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime

The symlink will be according to your time zone--above is just an example.

Now, we check the date and time

date

Time and date should now be properly set.

Tags: Linux date time

Disable IE "compatibility mode" through .htaccess

Internet Explorer "compatibility mode" is that dreadful page icon, inconveniently placed right next to the refresh button/icon.

What it does is turn IE 8 or higher into an outdated browser, so it can properly display really old school websites that were, likely, built using invalid and/or outdated HTML code. It's a horrible feature, that I see no practical use for whatsoever. Plus it's easy to accidentally click it, because it's located a few pixels away from the refresh button--talk about non-intuitive...

Anyhow... 

This is how you disable IE compatability mode on your website.

  In your .htaccess insert the following:

Header set X-UA-Compatible "IE=9; IE=8; IE=7;IE=edge"

Woooo! We're done. That dumb IE compatibility mode icon won't show ever again.

 

Tags: Server apache IE Web Development

How to install XCache 3.0 from source

Alright... So APC has been pretty unstable for me on 2 separate servers running PHP 5.3.x and PHP 5.4.x. So I figured I'd give XCache a try after reading about similar problems with APC.

Anyhow...

Here's how to install XCache 3.X from source on CentOS

Get the latest version of XCache from here: http://xcache.lighttpd.net/#Downloads

Latest version at the time of this writing is XCache 3.0.1


cd /usr/local/src
wget http://xcache.lighttpd.net/pub/Releases/3.0.3/xcache-3.0.3.tar.gz
tar xvfz xcache-3.0.3.tar.gz
cd xcache-3.0.3
phpize
./configure --enable-xcache
make
make install

Note the installation path. Example here are my paths:

Tags: XCache APC Linux Server how-to

Drupal .htaccess rewrite with 'www' but not for sub-domains

Say you have your Drupal's .htaccess set "To redirect all users to access the site WITH the 'www.' prefix", and you added a sub-domain, and it came out looking something like http://www.sub.domain.com. So, most people will NOT want the "www" added to the url in this case. So what do you do? Easy.

Use this instead:


# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !^(subdomain1|subdomain2|subdomain3)\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

So what changed? We simply added this line:

Tags: Drupal Linux admin

How to install GEOS on CentOS and directadmin

cd /usr/local/src
wget http://download.osgeo.org/geos/geos-3.4.2.tar.bz2  # go here to find the latest version: http://download.osgeo.org/geos/
tar -xvjf geos-3.4.2.tar.bz2
cd geos-3.4.2
./configure --enable-php; make clean ; make
make install
ldconfig
vi /etc/ld.so.conf

Add the following line if it doesn't already exist

/usr/local/lib

Find the location of the newly installed geos.so

updatedb
locate geos.so

You'll get something like this:

/usr/local/lib/php/extensions/no-debug-non-zts-20090626/geos.so

Add the extension info to your php.ini

vi /usr/local/lib/php.ini

Add the following (somewhere around the rest of your extension, e.g. APC):

For PHP 5.3:

Tags: centos geo Geocoder Geofield Drupal

Upgrade Drupal 6 to Drupal 7 using Drush site-upgrade

Ok... So you decided that it's time to upgrade from Drupal 6 to Drupal 7. It's not going to be easy, but using Drush will make life a little easier.

What this will do is save you the time of manually upgrading Drupal 6 core and drupal 6 modules to Drupal 7 core and drupal 7 modules. Of course likely your site will be broken after the drush site-upgrade, but at least you have the manual job of searching for upgraded modules taken care of.

So, let's begin...

Install latest version of Drush


cd /usr/local/share
# install GIT if not available
yum install git
git clone https://github.com/drush-ops/drush.git drush
ln -s /usr/local/share/drush/drush /usr/local/bin/drush
drush

Tags: Drupal drush

Add memcached Support to Magento

After you successfully install memcached and pecl/memcached (memcached PHP support), you will next want take full advantage of it by enabling native support for memcached in magento.

NOTE: you must have memcached and pecl/memcached already installed. Otherwise your Magento installation will break if you try following this guide.

Ok... now that the warning is out the way. Here's how we do it...

Edit your local.xml


vi ./app/etc/local.xml

Add the following between

Tags: magento memcached Linux

How to set a custom sub-domain path in DirectAdmin

UPDATE: See below, there's an easier way to do this. Plus DirectAdmin's way doesn't seem to be working through the 'Custom HTTPD Configurations' way.... So, just use the way listed below. It's much easier.

*** OLD WAY / start ***
I work with Drupal's Domain Access module a lot. However, if you're using DirectAdmin as your hosting control panel, then making sub-domains will not work with the default setup. DirectAdmin puts the sub-domain into a separate directory, and in order for Domain Access to work with sub-domains on DirectAdmin, this needs to be set as the same directory/path as the top domain.

A simple work around is to login to DirectAdmin as administrator, and go into "Custom HTTPD Configurations".

Here you will paste the following code:

Tags: DirectAdmin Linux Drupal Domain Access

Magento Google Shopping Setup aka Google Base aka Google Content aka Google Merchant

Here's a quick (and hopefully easy) tutorial on how to properly setup Magento with Google Base aka "Google Shopping" or "Google Content" .

I know there is very limited help for Google Base/Shopping for Magento Community Edition 1.6 and 1.7 (and nothing official exists on any lower versions)...

The interested fact is, Magento is knowingly supplying a broken extension with 1.6 and 1.7--i.e. there is no way it will work unless you hack the core code; as we will below.

Hopefully, the community edition will get a working extension soon, just like the Magento Go version.

Anyhow... on to self help!

Tags: magento google

How to install APC on CentOS and DirectAdmin


cd /usr/local/src
mount -o remount,exec,suid /tmp
yum install autoconf
yum install php-pear
yum install php-devel
yum install httpd-devel
yum install pcre-devel
wget http://pecl.php.net/get/APC
tar xvfz APC-VERSION.tgz
cd APC-VERSION
phpize
whereis php-config

This will give you the location of php-config, which you will put after --with-php-config=

Tags: Server PHP APC

Flush or Clear out Exim mail queue

Exim mail queue can get out of control. If your var is on a separate smaller sized partition it can quickly run out of space.

We can see what's using up all that space via:


cd /var
du -sh * | sort -n

and as with Exim, our culprit location should be:


/var/spool/exim/input

So to quickly clear out the exim mail queue we do the following:


cd /var/spool/exim/;rm -rf input msglog;/scripts/eximup --force

And that should do it.

Flush MySQL log-bin data and disable binary log files

If your disk is starting to run out of space due to an excess of mysql-bin.XXXXXXXX files here's what to do to fix that.


vi /etc/my.cnf

under 'log-bin=mysql-bin' (the destination could be different in your my.cnf) put:


expire_logs_days = 10

Change 10 to whatever you're comfortable with.

or you can simply disable the binary log files by uncommenting the line:


# log-bin=mysql-bin

You'll also want to remove all the excessive binary log files like so:


mysql -u root -p -e "PURGE BINARY LOGS BEFORE '2012-02-15 09:00:00';"

TROUBLESHOOTING

In case you can't shutdown mysqld do the following:


pidof mysqld
kill -9 NUMBEROFPROCESS

Tags: Server how-to mysql

How to install Apache Solr 3.x for Drupal 7 or Drupal 6

First we'll need to install Java 1.6 JDK, and be on PHP 5.2 or higher (You can check my PHP installation tutorial here. Also I'm on CentOS.

Install Java 1.6 JDK


yum install java-1.6*

Install Apache Solr

We're going to install Apache Solr into /usr/local/share; however you can install it somewhere else if you'd like (e.g. install it in the root dir / )


cd /usr/local/share

Download Apache Solr. We're going to use the latest version at the time of this writing: Apache Solr 3.5. Look for the latest version here: http://www.apache.org/dyn/closer.cgi/lucene/solr/

Tags: Server Drupal linux server apache solr solr

Magento Google Analytics goals setup

Ok... let's get right into it...

We'll assume you already have google analytics setup and working with magento...

So... we want to add Google Analytics Goals so we can track what people are doing at the different steps of checkout.

Alright... here we go...

  1. Log into your Google Analytics account
  2. Click "Admin" at the top right (of the new version of Google Analytics)
  3. Click the name of your domain
  4. Click "Goals" tab--towards the middle of page
  5. Click one of the non used "+ Goal" links
  6. Now we fill in all the info...

Tags: magento google analytics

How to place drupal blocks anywhere in content.

If you're looking to place a block anywhere inside your content, simply do the following:

go to /admin/build/block

select the block you want to insert into your content to get the proper block references...

e.g. I created a custom views block called "latest_news" which, if you click it's url looks like:
/admin/build/block/configure/views/latest_news-block

so basically, you'll use "views" at the beginning of the function reference and "latest_news-block" at the end:

Drupal 7 method

Menu block

Tags: Drupal blocks

httpd causing high CPU load in CentOS / DirectAdmin

If you did TOP in ssh, and noticed httpd process has a high cpu load, and has been running for a long time (e.g. over 5 minutes) then you might try lowering your MaxRequestsPerChild.


vi /etc/httpd/conf/extra/httpd-mpm.conf

Now change your MaxRequestsPerChild from 1000 to 20...


StartServers 5
MinSpareServers 10
MaxSpareServers 20
ServerLimit 812
MaxClients 812
MaxRequestsPerChild 20


service httpd restart

How to get 3TB HDD to work with NVIDIA nForce motherboards

If you recently tried installing a 3TB Hard Drive on an NVIDIA nForce motherboard you'll notice that only about 1/3 of the drive is recognized by Windows. The fix is quite simple:

1. Download NVIDIA nForce Drivers 15.58 (64bit) , Download NVIDIA nForce Drivers 15.58 (32bit) or later

2. Install the NVIDIA NFORCE 15.58 drivers and reboot your system after the install is done.

3. You're done. Your PC should be able to see the entire 3TB drive (it should be around 2.72TB)

Tags: admin windows HDD

How to fix Traktor not keeping play count or mp3 comment changes

So... Here I was playing sets on my new Traktor S4 on my 2010 iMac, and noticed that Traktor was acting weird--comments were getting erased, ratings were disappearing, play counts weren't being kept. In other words,Traktor's explorer worked on some files and not others.

I tried changing file permissions, reinstalling Traktor, etc... nothing solved the problem... Doing research didn't show me any concrete solutions (e.g. change the play count settings; this didn't work).

Then it occurred to me, I haven't defragmented my Windows PC in over 2 months. And a few weeks before, I had my windows PC sync all my mp3 files to my iMac.

So long story short, the mp3 files were messed up ("garbage at the end of file")...

The solution

Tags: windows traktor native instruments osx

How to uninstall multipletablerates from magento

Multiple Table Rates (aka multipletablerates) was a very popular extension in the magento 1.3 and earlier days... However, after several magento versions this extension basically became completely unstable/buggy (this is normal as it only lists magento 1.1 compatability)... Even so, it still worked on magento 1.3 with a few minor bugs... Then later down the road other extensions came up (mostly paid) that provided similar functionality, plus some, and minus the bugs...

Tags: magento extensions