I’ve been having some trouble with a server running Tomcat6 on Ubuntu with a Spring/Hibernate set up. It also does some image resizing via Image Magick.
The problems were that the perm gen size for the Hibernate objects was too small and it ended up running out of memory.
No problem, in Ubuntu, the fix was going /etc/default/tomcat6 and editing the JAVA_OPTS variable.
I started off with
That solved the Hibernate problem but I was soon getting out of memory errors for image uploads. I had to add this into the file
JAVA_OPTS="-XX:MaxPermSize=512m -Xms256m -Xmx512m"
Running this gave me some useful feedback about the memory that Java was using.
jmap -heap <pid>
There are some useful resources out there for anyone interested in reading more
Every now and then I need to re-set the PHP upload limits in the PHP ini file.
The obvious setting is
upload_max_filesize = 1024M
The less obvious settings are:
file_uploads = On
I’ve found it easy to forget to change post_max_size which need to be the same or greater than the upload_max_filesize.
Cloning a MySQL database turns out to be quite straightforward.
mysqldump -u admin --password=mypass --lock-tables=false clone_db_name | mysql -u admin --password=mypass import_db_name
I had to export a 7GB database recently using mysqldump.
I started out with the usual export call
mysqldump -u admin -p sugar > sugar_28_may.sql
However, the users complained that they couldn’t access the system while it was being exported.
The culprit was mysqldump’s habit of locking tables to export them. The solution was this
mysqldump -u admin -p --lock-tables=false sugar > sugar_28_may.sql
The other problem I got was this message
mysqldump: Error 2020: Got packet bigger than 'max_allowed_packet' bytes when dumping table `emails_text` at row: 84538
That message meant that I had to wait 15 minutes while the backup went up to 2GB and then the error kicked in.
I checked the max_allowed_packet by running
It turned out the server had a 24MB packet limit. I increased it to 1GB.
mysqldump -u admin -p --max_allowed_packet=1073741824 --lock-tables=false sugar >sugar_28may12.sql
Note that the –max_allowed_packet option on MySQL 5.0xx seems to be max-allowed-packet on MySQL 5.5x. Running mysqldump –help will sort out the correct syntax to use.
I had to set up multiple development sites using the Apache virtual hosting. All were coming back with the dreaded 403 page.
I did a lot of research and nothing seemed to work.
Finally, I found something that did. My virtual hosts were all running within directories that I had set up outside the /Library/Webserver location. I didn’t want to move the directories there and I didn’t want to sym link my directories to there either.
I found a line in the http.conf file
I changed it to
All fine, except that PHP wasn’t allowed to set a session file in /var/tmp.
sudo chown -R kevinsaunders:staff /var/tmp/*
That seemed to fix it all.
Resizing images is often something that any web developer has to do.
This is a bash script which resizes and crops images to a perfect 72×72 square.
# script to resize and crop
for k in `ls *.jpg`
h=`identify -format "%h" $k`
w=`identify -format "%w" $k`
#echo "$k, w:$w, h:$h"
if [ $w -ge $h ]
convert $k -resize x72 -crop 72x72+0+0 "$dir$resume/$k"
convert $k -resize 72x -crop 72x72+0+0 "$dir$resume/$k"
Sometimes it’s better to restart Apache on OSX through the command line..
sudo apachectl restart