Archive for the ‘Command Line’ Category

Redhat – Sort log file by date

Sunday, February 12th, 2012

$ ls -l -r –sort=time

Change ssh login folder

Tuesday, January 10th, 2012

After you ssh into server:
$ vi /etc/passwd

You should see something similar to
bloom:x:502:503::/var/www/vhosts:/bin/bash
devuser:x:48:505::/home/devuser:/bin/bash
bloomcom:x:503:506::/var/www/vhosts:/bin/bash

Just change the part where is says: /var/www/vhosts
to whatever folder you want

Get the current size of your hard drives

Saturday, January 7th, 2012
$ df -h ( hit enter )

Will return something similar to:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda5             128G   80G   47G  64% /
/dev/sda2             2.0G  264M  1.6G  15% /tmp
/dev/sda1              99M   23M   71M  25% /boot
tmpfs                  16G     0   16G   0% /dev/shm

Get the 50 largest files from your server

Saturday, January 7th, 2012
After logging in to your server via ssh:
 $ find / -type f -printf "%s %h/%f\n" | sort -rn -k1 | head -n 50 | awk '{ print $1/1048576 "MB" " " $2}' ( hit enter )

Apache – current open processes

Saturday, January 7th, 2012

Using terminal

$ ps ax | grep httpd | wc -l

Magento Install: Mysql Error – SQLSTATE[HY000] [2002]

Saturday, January 7th, 2012

Edit PHP config file: /etc/php.ini

$ sudo nano /etc/php.ini

Do a search for pdo_mysql_default

In nano, type <control button> and press W

type in pdo_mysql_default and hit enter

Change to

 pdo_mysql.default_socket=/tmp/mysql.sock

Restart apache:

$ sudo apachectl restart

Installing mcrypt into Mac OSX 10.7

Saturday, January 7th, 2012

Taken from http://craigwaterman.com/2011/07/21/adding-mcrypt-to-php-on-os-x-10-7-lion/ but cleaned up a few potential gotchas:

This is a guide for those who need to install (or re-install) mcrypt under PHP in OS X 10.7 (Lion).

You’ll need the following:

  • PHP Source Code—Lion seems to ship with 5.3.6, you can get that here. You should double-check your version with phpinfo() just in case.
  • libmcrypt 2.5.8 (yes, it really is from 2007). that’s here. I grabbed the bz2 version.
  • Xcode 4.1 – supported on Lion; it’s available on the Mac App Store. You’ll still need an Apple Developer account to download the post-install updates.
  • A place to uncompress and compile everything, move your php and libmcrypt downloads here.
    • I usually use a directory in under my home named Source. In this case, I’m putting everything in a Lion specific folder: /Users/sushi/Source/lion/
Now we need to uncompress our sources:
$ cd ~/Source/lion ( hit enter )
$ tar xvfj libmcrypt-2.5.8.tar.bz2 ( hit enter )
$ tar xvfz php-5.3.6.tar.gz ( hit enter )

Let’s configure libmcrypt for installation:

$ cd libmcrypt-2.5.8 ( hit enter )
$ MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
LDFLAGS='-O2 -arch i386 -arch x86_64' \
CXXFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
./configure --disable-dependency-tracking ( hit enter )

If you get some errors, try removing a few items:

$ MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common' \
LDFLAGS='-O2' \
CXXFLAGS='-O2 -fno-common' \
./configure --disable-dependency-tracking ( hit enter )

Now let’s build and install libmcrypt itself.

 

$ make ( hit enter )
$ sudo make install ( hit enter )

You can run make -j8 if you’re on a Quad-Core i7 and are curious how much it speeds up compilation, it makes no difference for installing mcrypt.

With libmcrypt ready to use, we need to compile the php extension for it.

$ cd ~/Source/lion/php-5.3.6/ext/mcrypt ( hit enter )
$ /usr/bin/phpize ( hit enter )
MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
LDFLAGS='-O2 -arch i386 -arch x86_64' \
CXXFLAGS='-O2 -fno-common -arch i386 -arch x86_64' \
./configure --with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config ( hit enter )

( You might have to hit enter again to make it execute )

If you get some errors try removing a few things like we did above:

MACOSX_DEPLOYMENT_TARGET=10.7 CFLAGS='-O2 -fno-common' \
LDFLAGS='-O2' \
CXXFLAGS='-O2 -fno-common' \
./configure --with-php-config=/Developer/SDKs/MacOSX10.7.sdk/usr/bin/php-config ( hit enter )

$ make ( hit enter ) $ sudo make install ( hit enter )

Everything should be ready to hook up at this point, we’ll need to update /etc/php.ini to tell php to load the extension.

Verify that /etc/php.ini exists. If you’ve never worked with it before, or have just upgraded to Lion, you’ll need to copy php.ini.default to php.ini with:

# skip this step if /etc/php.ini already exists.
$ sudo cp /etc/php.ini.default /etc/php.ini ( hit enter )

Update php.ini and tell php to load our newly compiled mcrypt.so

$ sudo nano /etc/php.ini ( hit enter )

Add the following to the end of the file, then save and exit:

extension=mcrypt.so

Now restart Apache:

$ sudo apachectl graceful ( hit enter )
OR
$ sudo apachectl stop ( hit enter )
THEN
$ sudo apachectl start ( hit enter )

OR using Macs typical user interface:

  • Open System Preferences
  • Select Sharing
  • Uncheck and re-check “Web Sharing”—this restarts the web server.
    • For some reason my Web Sharing was unchecked even though Apache was already running, if this happens to you, just “check/uncheck/check” to make sure it’s actually restarted.

Verify in your phpinfo() that mcrypt is really there, it should look like this:

And that should be it

Magento log not working

Monday, December 19th, 2011

To fix your Magneto log: Mage::log() that is not logging you need to change the update the permissions for the magento var folder.

$ cd magento/location/on/server ( hit enter )

$ chmod -R 777 var/ ( hit enter )

That will prevent Magento from trying to use a default setting: /var/tmp//magento/var

Took me 2 hours, but hopefully this saves someone else from the same pain I had.

 

Count items in a folder

Thursday, December 15th, 2011

$ find folder/to/count/ -type f | wc -l ( hit enter )

Get a folder size via command line

Wednesday, December 14th, 2011

$ du -h /foldertogetsizeof ( hit enter )

To get the size of the folder you are in:
$ du -h ( hit enter )