| FreeBSD Server Administration | ![]() |
There is really no any reason to continue using PHP 4 and MySQL 4 except being lazy. The upgrade was quite smooth and took about 1.5 hours including compiling time.
Upgrade MySQL 4.0.27 to MySQL 5.0.51a
This guide explained it very well, just follow it.
Note:
1. mysql_upgrade will repair tables automatically when needed.
2. After running mysql_upgrade, mysql server should be restarted.
3. mysql_upgrade can be executed more than one time with the '-f' option. e.g. if you see lots of errors during mysql_upgrade, you may want to make sure all tables are OK.
Upgrading PHP 4.4.8 to 5.2.5
I started with this guide, but I didn't use portupgrade for such major upgrades. Anyway, it's basically the same, list all PHP related packages, delete them first, install them manually.
Note:
1. It seems that lang/php5-extensions has included all PHP related packages, just check those you required.
2. Apache configuration file needs some changes:
DirectoryIndex: I simply replaced 'php4' with 'php5'
AddType: Added the following lines:
<IfModule mod_php5.c>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
</IfModule>
Posted by FreeBSD Newbie at 01:53 PM | Comments (0)
To enable image (JPEG/PNG) manipulation for PHP, install gd extension from ports:
# cd /usr/ports/graphics/php4-gd
# make install clean
# apachectl graceful
If a PHP script needs gd module but can't find it, it will display the following error:
Fatal error: Call to undefined function: imagecreatefromjpeg()
P.S. A simple problem could be troublesome for newbies if they can't find the right web pages. When searching the solution to the above error, a FreeBSD user may be led to a Linux page which states that PHP must be recompiled with gd support. But this is not applicable for FreeBSD system. Hopefully, after I blog this problem, Google will lead them to this post, so that they can enable gd support for PHP within minutes without touching the main PHP installation.
Posted by FreeBSD Newbie at 10:53 PM | Comments (8)
Upgrading PHP may affect installed PHP modules. For example, a PHP script reported the following error after I upgraded PHP:
PHP Warning: Unknown(): Unable to load dynamic library '/usr/local/lib/php/20020429/xml.so' - Shared object "libexpat.so.5" not found, required by "xml.so" in Unknown on line 0
Reinstalling /usr/ports/textproc/php4-xml fixed it.
Posted by FreeBSD Newbie at 01:21 AM | Comments (0)
I tried Mambo a while ago and it's always causing a fatal error "httpd exited on signal 11".
Finally I took the time to upgrade all vulnerable packages reported by portaudit and gave Mambo another try, the latest version 4.5.3 seems to work well.
The version numbers of involved packages:
apache-1.3.34_4
php4-4.4.2_1
mysql-server-4.0.26
I didn't install Mambo via ports, for PHP scripts, I prefer manual installation. Since we usually need to customize the script a lot, ports will only make the upgrade more complicated.
Posted by FreeBSD Newbie at 01:00 AM | Comments (0)
My security run output of today contains lots of error messages like:
pid 90742 (httpd), uid 80: exited on signal 11
pid 90896 (httpd), uid 80: exited on signal 11
It looks like a serious problem, then I searched the Internet immediately, here is a helpful discussion. Although there are no definite answers, the possible reasons can be summarized as:
1. Hardware problems, the most common one.
2. Vulnerable version of Apache, PHP or other Apache modules.
3. Buggy scripts.
Regarding my server
1. Hardware problems
This server has been running well for several months, unlikely to be the case.
2. Vulnerable version of Apache or its modules
Normally I can ignore this since I monitor the packages closely with portaudit. But recently Apache did have a known vulnerability. I ignored the upgrade because it shouldn't affect my installation.
This only affects installations where Apache is used as HTTP proxy in combination with the following web servers.
3. Buggy scripts
I did install mambo yesterday and it has a very weird problem, admin login doesn't work. There are many similar bug reports without solutions on their support forum, which is very unusual for a popular CMS, IMO. I debugged the script as I wrote in a previous post, it turned out that the login script ended at a PHP function "session_start()", it didn't give any error message, just like calling "die()". Then I made a test, signal 11 error happened every time I made a login.
Now the problem is clear, I removed mambo.
Posted by FreeBSD Newbie at 02:05 PM | Comments (1)
When something strange happens to a third-party PHP script, I often have no idea where to start to fix the problems. I find PHP code debugging is an effective way even the error message may suggest a system configuration problem.
How to find the problem
Turn on register_globals and display_errors in the php_ini file, these two variables are not recommended for production system due to the security concern, though. If this doesn't give enough information, try debugging into the code with echo() or logging function. Some scripts use templates and aren't easy to print the output directly, logging to a file may be necessary in this case.
A simple logging function
function logInfo($msg)
{
$filename = 'log.txt';
$handle = fopen($filename, 'a');
$msg = date("H:i:s")." ".$msg."\r\n";
fwrite($handle, $msg);
fclose($handle);
}
A weird example
A phpBB forum which has been running well suddenly popped up an error message whenever I tried to login: "Connection was refused". I tried to set all file attributes to 777, re-upload all files, but neither worked. I also posted the problem on phpBB's support forum, but didn't get any response. Finally I started to debug into the code with the above logging function to see what really happened. By tracing the script step by step, I found the problem was that I accidentally set the cookie using secure path in the admin control panel, phpBB redirected to https with header() function after successful login, the problem was fixed by modifying the Database record.
Posted by FreeBSD Newbie at 03:15 PM | Comments (0)
Sometimes I login to the server only for running a simple command, such as uptime. It can be more convenient to do this with a simple PHP page, for example, the following code will display the the output of uptime command:
<?php passthru("uptime"); ?>
For more details about how to execute Unix/Linux command in PHP, please refer to PHP online manual.
Posted by FreeBSD Newbie at 11:59 PM | Comments (0)
This is probably very simple, but I could spend hours on it if I'm not lucky.
1. PHPbb displays a blank page if register_globals is disabled.
2. If a crob job executes PHP pages, the working directory is important.
For example:
59 23 * * * /home/account_name/www/sample.php
If get problems, try
cd /home/account_name/www/
59 23 * * * ./sample.php
Posted by FreeBSD Newbie at 07:45 AM | Comments (0)
In my last post, I wrote: "PHP doesn't need any configuration if installed with pkg_add", well, this is not accurate, I found several php scripts worked weird, that reminded me of the famous parameter register_globals. It's off by default, pkg_add doesn't create php.ini, if you want to enable register_globals, you have to create a php.ini and modify the configuration, then restart Apache.
# cp /usr/local/etc/php.ini-recommended /usr/local/etc/php.ini
In PHP documentation, there is no configuration guide specially for FreeBSD, there are two related sections: OpenBSD and Unix installation, they both use different place for php.ini.
Update: I deleted the comments of this post accidentally and lost some useful information.
The easiest way to know where to put php.ini is creating a php file like below and check the output, the key for php.ini is "Configuration File (php.ini) Path"
<?php phpinfo(); ?>
Posted by FreeBSD Newbie at 09:52 PM | Comments (1)