Posts Tagged ‘Tips and tricks’

Speed-up your virtual machine created with VMware Player

If your virtual machine created with VMware Player becames very slow and takes a long time to complete some operations it’s time to improve its performance!
Close your VM, and open the *.vmx file with a text editor. Then add at the end of the file the following lines:

mainMem.useNamedFile = "FALSE"
sched.mem.pshare.enable = "FALSE"
MemTrimRate=0
MemAllowAutoScaleDown = "FALSE"
prefvmx.useRecommendedLockedMemSize = "TRUE"
prefvmx.minVmMemPct = "100"

Remember to not duplicate the keywords (in case you already have some lines set) otherwise the VM will not start.
The above lines totally reserve the memory requested by the VM to the guest system and avoid to continuosly ask to the host (and so to the swap file) for new memory chunks.

Try yourself and give me a feedback!

PHP Fatal error with PhpMyAdmin and APC

If you are running PhpMyAdmin and APC can happens that you get some errors like these:
PHP Fatal error: Call to undefined function PMA_log_user() in /usr/share/webapps/phpMyAdmin/libraries/common.inc.php on line 914
PHP Fatal error: Call to undefined function PMA_select_language() in /usr/share/webapps/phpMyAdmin/libraries/auth/cookie.auth.lib.php on line 220
PHP Fatal error: Call to undefined function pma_generate_common_url() in /usr/share/webapps/phpMyAdmin/libraries/header_meta_style.inc.php on line 48
PHP Fatal error: Call to undefined function PMA_DBI_connect() in /srv/http/librolandia.it/test/phpmyadmin/libraries/common.inc.php on line 916
PHP Fatal error: Class 'PMA_Error_Handler' not found in /path/to/phpMyAdmin/libraries/common.inc.php on line 58
PHP Fatal error: Call to undefined function PMA_getenv() in /path/to/phpMyAdmin/libraries/common.inc.php on line 143

If this is the case, you need to make some little changes to disable apc in your phpmyadmin virtual host:

Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
      AllowOverride All
      Options FollowSymlinks
      Order allow,deny
      Allow from all
      php_admin_value open_basedir "/srv/:/tmp/:/usr/share/webapps/:/etc/webapps:/usr/share/pear/"
      php_admin_value apc.enabled 0
</Directory>

And also modify your apc filter in php.ini under the APC section:

[APC]
apc.filter="-/usr/share/webapps/phpMyAdmin/.*"

Now restart Apache and you phpMyAdmin should work regularly.

How to use google apps in WordPress on Bluehost

In these days I spent a lot of time looking for a solution of chainging the admin email address in Bluehost and I found a working solution! The problem is that Bluehost use Exim as mail server that is configured to require a valid and registered email address.

This is my scenario:

  • Some domains with mx records pointed to google apps (I will take myprivatedomain.com as example).
  • No mailbox created on Bluehost because I’ve already created them with google apps.
  • myprivatedomain.com with info@myprivatedomain.com as admin email set in Settings -> General.

At this point, every email sent from any comments has this header:

user <user@boxXXX.bluehost.com>

I want to change it in order to have this address in my comments:

info <info@myprivatedomain.com>

These are the steps to follow:

  1. Log-in to Bluehost cpanel and go to Mail -> MX Entry. Here select your host (myprivatedomain.com), add these MX records as in the picture below and make sure to set Remote Mail Exchanger:
    • 1 ASPMX.L.GOOGLE.COM.
    • 5 ALT1.ASPMX.L.GOOGLE.COM
    • 5 ALT2.ASPMX.L.GOOGLE.COM
    • 10 ASPMX2.GOOGLEMAIL.COM
    • 10 ASPMX3.GOOGLEMAIL.COM

  2. Now the e-mail delivery should just works. However, if you want to change From email name, install the mail from plugin and configure it in this way:
    • Sender Name -> YourName
    • User Name -> info
    • Domain Name -> myprivatedomain.com

That’s all! Now try to post a comment and look at your mailbox.

How to transfer an entire website via ftp with recursive lftp

In these days I’ve to transfer some big websites from a server to another and the only way to do this it was an FTP connection because the destination server did not provide any other type of access. Because of the number of files was big (about 12GB) I’ve created a little script to use with lftp opened into a screen session so don’t make me a terminal busy for days.

So I’ve created a script called sendfiles.sh in this way:

set ftp:ssl-allow no
open -u username,password example.com
mirror -c -R /source-path /destination-path
quit

Where the following fields are respectively:

username: user name for ftp access
password: password for ftp access
example.com: ftp destination server
source-path: source path on local server
destination-path: remote path on the ftp (where / is the ftp rootdir)

To run the script is sufficient to open a screen session (if you want to leave the process in background on the source server) and issue this command:

lftp -f sendfiles.sh

MySQL error 1153 in max_allowed_packet

Today I’ve got an anomalous error during a database import on mysql:

ERROR 1153 (08S01) at line 3854: Got a packet bigger than 'max_allowed_packet' bytes

To solve this is sufficient to edit the mysql configuration file (/etc/my.cnf on Linux) and fill a suitable big value for max_allowed_packet. In my case I’ve set 100M.

Restart mysqld daemon and now the import will gone fine!

Script to remove .svn directories from a project

When you want to distribute your own sources without any .svn directories is sufficient to create an export of the project with this command:
svn export svn://path_to_repository projectname

But often I’ve not access to the repository, so I remove any .svn directory by hand.

For a couple of directories is not a problem but today I’ve a big project with hundreds of directory, so I realized a little script to help me:

find . -type d -name .svn -exec rm -r '{}' \;

Hide file and directory in apache disabling browsing

Today I’m happened to disable file and directory browsing on my web server that after my work showed all its content. Shortly, to prohibit that every users can view the content of a directory (if noindex.php/index.html is present) occur a little modifying to configuration file of apache or a new directive in .htaccess.

I’ll show you how to do in both cases…

  1. httpd.conf / virtual-host
    Edit your virtualhost adding these rows:

    <Directory "/home/httpd/html/mydomain/files">
    Options -Indexes
    </Directory>
    
  2. .htaccess
    Add in the .htaccess file this row:

    Options -Indexes

In the first case you need to restart apache server.

Script to remove trailing tilde (~) from temporary files opened with kate

Using kate as text editor, temporary files that have been saved present an annoying trailing tilde that personally I consider useless. I’m used to be careful when I use something like text editor (good vim school!). So I realized this mini script in bash to remove temporary files when I’ve just saved the final document.

#!/bin/bash
rm `find $1 | grep "~$"`

The file above I’ve called rmm (I don’t say why) and I’m put it in /usr/bin/
After written and saved something, I only open a shell, go to source directory and run this command:
$ rmm .

Or run directly this command without moving to source directory: $ rmm /home/matteo/src
This script is trivial and can be obviously improved. If you want to contribute I will be happy to add your improvements.