Optimize your hosting server
A quick info of how you can optimize your hosting server if you are using a LAMP (Linux Apache Mysql PHP) environment.
I am keeping the info for reference, I will also try to update it but please not that’s not a complete list. Please comment if you have any opinions
1. use php as a fcgi module not as a dso module for apache
2. compile apache with mpm (Multi-Processing Module) worker that is capable to serve a large number of requests with less system resources than a process-based server.
3. use php eaccelerator it’s proven to be faster than apc and other cache systems
tweak it based on http://eaccelerator.net/wiki/Settings
that’s basically it
now some configuration parameters:
1. don’t use SymLinksIfOwnerMatch in your httpd.conf a lstat system call is made for each directory and it’s not cached
2. Tune MinSpareServers and MaxSpareServers so that Apache need not spawn more than 4 child processes per second (Apache can spawn a maximum of 32 child processes per second). When more than 4 children are spawned per second, a message will be logged in the ErrorLog.
to be continued…
Error while loading shared libraries: libmm.so.14
As the title say, that’s an error message which I received when trying to compile a php version with mm as a ./configure option.
fixing it is as easy as checking debug.log in your php source directory, searching where the php is looking for libraries (mine was in /usr/local/lib64) and than just creating a symlink for libmm.so.14 to /usr/local/lib64
Don’t have libmm at all? Go to http://www.ossp.org/pkg/lib/mm/ and install the library.
Update: apparently in php.ini you need to uncomment the session save path directive as otherwise the default path is / which triggers a permission error. Because of this the mm session handler does not get registered with php
A fastcgid and cpanel story
I wanted to get fastcgid running on cpanel/whm, so I went to easyApache and selected to compile apche with fastcgid support and php with fastcgi support, but guess what – it wasn’t working! they just ignored the settings and php was compiled without fastcgi in it.
So back to the beggining, dreaming of my lost time figuring out what the heck was wrong with whm/cpanel/easyapache I turned to plan B.
I recompiled apache still with easyapache from whm but without php. Further more I also choosed MPM worker module to improve the way static content is served. (!!! mpm worker is not compatible with PHP as an apache module)
Next step I compiled php from source – see my other article regarding compiling php from source and checking what I used as ./configure command.
Finally I went to httpd.cnf -> on my system was on /usr/local/apache/conf and added the following lines:
AddHandler fcgid-script .php
Options +ExecCGI
FCGIDWrapper /usr/local/php5-fcgi/bin/php-cgi .php
Make sure you change the path of the fcgid wrapper to fit your php directory you have just compiled.
Restart apache and that’s it.
Note: you need to learn how to optimize fcgid config variables and because mpm worker was also installed, it’s corresponding configuration variables as well. But till you do, the default will be just fine.
Install php from source – custom path
Hey guys,
Recently I wanted to give php 5.3.1 a go but without interferring with my current setup, so I choosed to run it as fcgi.
In order to do that I wanted to compile php from source, enabling the modules I needed (gd with jpg support), bmath, pdo, pdo_mysql (for magento) and so on
here we go:
1. go to php site and download your version
2. upload to your server and unarchive it somewhere ![]()
3. go using putty or something similar to where are the files extracted, enter the source directory
4. I used this command, change it per your needs:
./configure --enable-bcmath --enable-calendar --enable-fastcgi --disable-cli --enable-ftp --enable-gd-native-ttf --enable-libxml --enable-magic-quotes --enable-mbstring --enable-soap --enable-sockets --prefix=/usr/local/php5.2.12-fcgi --with-curl=/opt/curlssl/ --with-gd --with-jpeg-dir=/usr/lib --with-png-dir=/usr/lib --with-libdir=lib64 --with-mm --with-mcrypt=/opt/libmcrypt/ --with-mysql=/usr --with-mysql-sock=/var/lib/mysql/mysql.sock --with-mysqli=/usr/bin/mysql_config --with-openssl=/usr --with-openssl-dir=/usr --with-zlib --with-zlib-dir=/usr --enable-pdo --with-pdo-sqlite --with-sqlite --with-pdo-mysql=/usr --with-pdo-sqlite --enable-zend-multibyte --with-freetype-dir=/usr --with-gettext --with-ttf --enable-force-cgi-redirect --enable-sysvsem --enable-sysvshm
5. make
6. make install
make sure you rename and copy the development php.ini to the lib/php.ini
Install pdo_mysql – no recompiling php
I googled till 4 AM to check how can I enable/install pdo_mysql for magento without the need to reinstall php – as all posts pointed I should do
finally I get it working
From here I started:
1. I already had pdo
2. I hadn’t pdo_mysq;
so back to work (as root):
1. Download PDO_MYSQL from http://pecl.php.net/package/PDO_MYSQL
2. upload it to your server
3. run export PHP_PREFIX="/usr/local/php/"
4. run $PHP_PREFIX/bin/phpize
4. run ./configure '--with-pdo-mysql=shared,/usr' !! /usr was where my mysql was installed (not where the data of mysql are!)
5. make
6. make install
7. in your php.ini
8. add
extension_dir = "/usr/local/php/extensions/no-debug-non-zts-20060613"
extension=pdo_mysql.so
9. restart apache
Install eaccelerator from scratch – Centos
1. download the source code and upload it to your server
2. execute
export PHP_PREFIX="/usr/local/php/"
where /usr/local/php/ is my path to where php is installed
3. $PHP_PREFIX/bin/phpize
4. ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
5. make
6. make install
7. now go to php.ini and include this code:
zend_extension="/usr/local/php5.2.12-fcgi/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="128"
eaccelerator.cache_dir="/tmp/eacc-php5.2.12-fcgi"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter="*.php"
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="7200"
eaccelerator.shm_prune_period="7200"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="8"
eaccelerator.keys = "shm"
eaccelerator.sessions = "shm"
eaccelerator.content = "shm"
make sure you change the extension path above to fit your php extension directory
8. restart apache
Overlength date field error in prestashop
Recently I got this error when trying to send emails in prestashop.
An email was bouncing back and it contained the following message:
This message has been rejected because it has
an overlength date field which can be used
to subvert Microsoft mail programs
After a lot of headaches and a cofee
I manage to detect what was wrong:
Presta uses in the email class a variable $templateVars
this was like:
$templateVars = array(
‘{date_facturare}’ =>
‘Nume Firma: ‘.$invoice->company.’<br>’.
‘Cod fiscal: ‘.$invoice->tax_code.’<br>’.
‘Registrul Comertului: ‘.$invoice->reg_data.’<br>’.
‘IBAN: ‘.$customer->iban.’<br>’,
‘CNP: ‘.$invoice->cnp.’<br>’,
‘{firstname}’ => $customer->firstname,
‘{lastname}’ => $customer->lastname, …
However the problem was because of a , instead of .
'IBAN: '.$customer->iban.'<br>',
should have been:
'IBAN: '.$customer->iban.'<br>'.
Because of the wrong “,”, $templateVars[0] was taking a long value and apparently Swift Mailer was appending it to the header date of the email hence the error with the overlength date field.
Restart apache when server load is too big
Some times one of the hosting servers is going crazy with load of over 200 crashing the server eventually.
The load is because of a strange php script that I can not find it for now. Anyway if you want to restart apache when your server load is too big and to receive an email when this happens here you go:
#!/bin/bash
MAXLOAD="5"
L05="$(uptime | gawk -F"load average: " '{ print $2 }' | gawk -F", " '{ print $1 }')"
if [ $(echo "$L05 > $MAXLOAD"|bc) -eq 1 ]
then
unlink /tmp/message.txt
MESSAGE="/tmp/message.txt"
echo "restarting apache" >> $MESSAGE
/bin/mail -s "big load $L05" "myemail" < $MESSAGE
/etc/init.d/httpd restart
fi
feel free to add it to your cron job
Cakephp – JsController could not be found
Recently I wanted to test the ajax capabilities from cakePHP and after setting up the links to prototype.js and scriptaculous.js just as shown on cakePHP website, I’ve noticed the ajax is not working.
In the javascript error console I noticed the error:
JsController could not be found
The problem was that I thought cake will include the above js files automatically from it’s core libraries. Of course it doesn’t so to solve the problem just download prototype.js and scriptaculous.js and place them in the js directory inside webroot
That’s it!
GoDaddy 500 Internal Server Error – Windows Shared hosting

Today I needed to move some sites to a different server. A wordpress and an old oscommerce. The server was a windows server from godaddy – the hosting was a shared one
After setting up the database and the files I run into this error:
500 Internal Server Error
› Continue reading