原来在web上不能写方式打开文件,也不能通过unix套接字连接数据库,另外的机子同样安装没问题.用rpm装也不行.还有,不知如何能用GD,看php的编译选项是带了的,但不起作用.就用源码编译,似乎装了apache就已经可写了.把php装好,什么都有了.
先编译apache2,并安装 ./configure --prefix=/usr/local/apache --enable-module=most --enable-shared=max --enable-so 再编译freetype2和libpng,以启用GD,这两个都简单, 然后再编译php4.3.11, ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --enable-calendar --enable-force-cgi-redirect --enable-gd-imgstrttf --enable-gd-native-ttf --enable-inline-optimization --enable-magic-quotes --enable-memory-limit --with-bz2 --with-ftp --with-png-dir=/usr --with-xml --with-zlib=yes --with-gd=yes --enable-mbstring --with-png-dir=/usr --with-ttf --with-freetype-dir=/usr/local --enable-ctype --enable-dbase --enable-ftp --with-ftp --with-gdbm --with-gettext --with-tiff-dir=/usr 这个已经自动在 /usr/local/apache/conf/httpd.conf里加入了php4支持. LoadModule php4_module modules/libphp4.so AddType application/x-httpd-php .php .phtml 记得,/usr/lib/httpd/modules/libphp4.so是FC3自带的php4.3.9的,不要用了.然后 cp ./php.ini-dist /usr/local/lib/php.ini 建立一个放session的目录,比如 mkdir /tmp/session,并chmod 777 /tmp/session, session.sav_path = /tmp/session 在apache增加虚拟主机支持
NameVirtualHost *:80/usr/local/lib/php.ini <VirtualHost *:80> ServerAdmin webmaster@www.my.com DocumentRoot /var/www/www.my.com/ ServerName www.my.com ErrorLog logs/www.my.com-error_log CustomLog logs/www.my.com-access_log common </VirtualHost>
加入默认页
DirectoryIndex index.html index.html.var index.php 用/usr/local/apache/bin/apachectl start启动,用phpinfo观察, 写一个测试gd的脚本, <?php function make_seed() { list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000); } // 生成 4 位随机数 mt_srand(make_seed());
$number = ''; $number_len = 4; $stuff = '120129109381209573475647863012381290137092174826578631203182308120128390217421075'; $stuff_len = strlen($stuff) - 1; for ($i = 0; $i < $number_len; $i++) { $number .= substr($stuff, mt_rand(0, $stuff_len), 1); } // 把随机数存入 session $_SESSION['VERIFY_CODE'] = $number; // 生成验证码图片 $img_width = 40; $img_height = 18; $img = imageCreate($img_width, $img_height); ImageColorAllocate($img, 0x6C, 0x74, 0x70); $white = ImageColorAllocate($img, 0xff, 0xff, 0xff); $ix = 5; $iy = 2; for ($i = 0; $i < $number_len; $i++) { imageString($img, 3, $ix, $iy, $number[$i], $white); $ix += 8; } // 输出图片 header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG)); imagepng($img); imagedestroy($img); ?> 再发一个简单点的,就是太黑了,要改才行,
<?php /* * Filename: authimg.php * Author: hutuworm * Date: 2003-04-28 * @Copyleft hutuworm.org */ //生成验证码图片 Header("Content-type: image/PNG"); srand((double)microtime()*1000000); $im = imagecreate(62,20); $black = ImageColorAllocate($im, 0,0,0); $white = ImageColorAllocate($im, 255,255,255); $gray = ImageColorAllocate($im, 200,200,200); imagefill($im,68,30,$gray); while(($authnum=rand()%100000)<10000); //将四位整数验证码绘入图片 imagestring($im, 5, 10, 3, $authnum, $black); for($i=0;$i<200;$i++) //加入干扰象素 { $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); } ImagePNG($im); ImageDestroy($im); ?> 看到图片,说明成功了,再测试一下可写文件不, <?php $tmpfile='/var/www/www.gy12345.com/shop/1.txt'; echo "will open file<br>"; $fp=fopen($tmpfile, "w"); if($fp) { flock($fp, LOCK_EX); fwrite($fp,' dddd'); flock($fp, LOCK_UN); fclose($fp); echo "ok"; } else{ echo 'open fail'; } ?> 可以再测试一下smarty模板和数据库连接
|