今天完成了在linux下搭建一lamp环境的工作,整个过程实在是痛苦不堪,本以为应该很顺利的,但做的过程中才发现N多细节问题,让人纠结不已。
鉴于此教训实在是惨烈(从昨天下午开始到今天上午结束,持续近一天时间),将整个过程中遇到的问题记录下来,汲取经验教训了。
系统: centOS(64位)
php 5.2.14
一、获取相关开源程序:
1、【适用CentOS操作系统】利用CentOS Linux系统自带的yum命令安装、升级所需的程序库(RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包,进行安装):
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
2、【适用RedHat操作系统】RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包(事先可通过类似“rpm -qa | grep libjpeg”的命令查看所需的RPM包是否存在,通常是“xxx-devel”不存在,需要安装)。RedHat可以直接利用CentOS的RPM包安装,以下是RPM包下载网址:
①、RedHat AS4 & CentOS 4
http://mirrors.163.com/centos/4/os/i386/CentOS/RPMS/
http://mirrors.163.com/centos/4/os/x86_64/CentOS/RPMS/
②、RedHat AS5 & CentOS 5
http://mirrors.163.com/centos/5/os/i386/CentOS/
http://mirrors.163.com/centos/5/os/x86_64/CentOS/
③、RPM包搜索网站
http://rpm.pbone.net/
http://www.rpmfind.net/
④、RedHat AS4 系统环境,通常情况下缺少的支持包安装:
Ⅰ、i386 系统
wget http://blog.s135.com/soft/linux/nginx_php/rpm/i386/libjpeg-devel-6b-33.i386.rpm
rpm -ivh libjpeg-devel-6b-33.i386.rpm
wget http://blog.s135.com/soft/linux/nginx_php/rpm/i386/freetype-devel-2.1.9-1.i386.rpm
rpm -ivh freetype-devel-2.1.9-1.i386.rpm
wget http://blog.s135.com/soft/linux/nginx_php/rpm/i386/libpng-devel-1.2.7-1.i386.rpm
rpm -ivh libpng-devel-1.2.7-1.i386.rpm
Ⅱ、x86_64 系统
wget http://blog.s135.com/soft/linux/nginx_php/rpm/x86_64/libjpeg-devel-6b-33.x86_64.rpm
rpm -ivh libjpeg-devel-6b-33.x86_64.rpm
wget http://blog.s135.com/soft/linux/nginx_php/rpm/x86_64/freetype-devel-2.1.9-1.x86_64.rpm
rpm -ivh freetype-devel-2.1.9-1.x86_64.rpm
wget http://blog.s135.com/soft/linux/nginx_php/rpm/x86_64/libpng-devel-1.2.7-1.x86_64.rpm
rpm -ivh libpng-devel-1.2.7-1.x86_64.rpm
3、【适用CentOS、RedHat及其它Linux操作系统】下载程序源码包:
本文中提到的所有开源软件为截止到2010年07月26日的最新稳定版。
①、从软件的官方网站下载:
mkdir -p /data0/software
cd /data0/software
wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz
wget http://www.php.net/get/php-5.2.14.tar.gz/from/this/mirror
wget http://php-fpm.org/downloads/php-5.2.14-fpm-0.5.14.diff.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.3-m3.tar.gz/from/http://mysql.he.net/
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"
wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"
wget http://pecl.php.net/get/memcache-2.2.5.tgz
wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://pecl.php.net/get/imagick-2.3.0.tgz
②、从blog.s135.com下载(比较稳定,只允许在本站,或者在Linux/Unix下通过Wget、Curl等命令下载以下软件):
mkdir -p /data0/software
cd /data0/software
wget http://blog.s135.com/soft/linux/nginx_php/nginx/nginx-0.8.46.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/php/php-5.2.14.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/phpfpm/php-5.2.14-fpm-0.5.14.diff.gz
wget http://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.3-m3.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/libiconv/libiconv-1.13.1.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/libmcrypt-2.5.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/mcrypt/mcrypt-2.6.8.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/memcache/memcache-2.2.5.tgz
wget http://blog.s135.com/soft/linux/nginx_php/mhash/mhash-0.9.9.9.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/pcre/pcre-8.10.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/eaccelerator/eaccelerator-0.9.6.1.tar.bz2
wget http://blog.s135.com/soft/linux/nginx_php/pdo/PDO_MYSQL-1.0.2.tgz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/ImageMagick.tar.gz
wget http://blog.s135.com/soft/linux/nginx_php/imagick/imagick-2.3.0.tgz
主要 参考:http://blog.s135.com/nginx_php_v6/
(但注意,该篇讲的是nginx + php(fastcgi方式运行),和我这里的mod_php方式还是有所不同,主要是在php编译选项有区别)
二、安装
1、安装mysql:
推荐源码安装
2、httpd(apache):
推荐源码安装
编译安装PHP 5.2.14所需的支持库:
tar zxvf libiconv-1.13.1.tar.gz
cd libiconv-1.13.1/
./configure --prefix=/usr/local
make
make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd http://www.cnblogs.com/
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure
make
make install
cd ../
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
/sbin/ldconfig
./configure
make
make install
cd ../
3、编译 php5.xxx: (mod_php 方式)
tar zxvf php-5.2.14.tar.gz
cd php-5.2.14/
./configure --with-apxs2=/usr/sbin/apxs \
--with-mysql \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php \
--with-zlib \
--with-gettext \
--with-gdbm \
--with-iconv-dir=/usr/local \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-dist /usr/local/webserver/php/etc/php.ini
cd ../
增加下面的东东到httpd.conf里:
Add these directives are in /usr/local/apache/conf/httpd.conf (if already there, verify they are correct):
# Make sure there's only **1** line for each of these 2 directives:
# Use for PHP 4.x:
#LoadModule php4_module modules/libphp4.so
#AddHandler php-script php
# Use for PHP 5.x:
LoadModule php5_module modules/libphp5.so
AddHandler php5-script php
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html php
# PHP Syntax Coloring
# (optional but useful for reading PHP source for debugging):
AddType application/x-httpd-php-source phps
http://dan.drydog.com/apache2php.html 这里有篇安装文档 apache + php (mod_php)
安装好php后,可以写如下一个文件测试下:
将该文件放在http根目录下(具体见httpd.conf里),我的centOS下默认为 /var/www/html/
phpinfo.php :
<?php
phpinfo();
?>
然后直接在浏览器里访问: http://localhost/phpinfo.php ,看是否有phpinfo的页面,可以测试php是否安装成功。
4、安装phpMyAdmin
1、先下载phpMyAdmin安装包:
到国外官方网站http://www.phpmyadmin.net上,点击导航栏上的“DOWNLOADS”链接进入下载页面,选择“all-languages.zip”版本下载到本地,解压;把解压缩文件放到系统指定的虚拟根目录下的phpmyadmin文件夹里(可自定义文件夹名),如flymorn的本地存放位置是D:\www\phpmyadmin里。
官方的文档:
http://www.phpmyadmin.net/documentation/Documentation.html#setup
创建phpmyadmin里的config.inc.php文件,写入如下内容。
(在 /phpmyadmin/libraries/ 下也有config.inc.php文件,phpMyAdmin会首先加载 libraries/config.default.php ,然后再加载 /phpmyadmin 下的config.inc.php 文件)
<?php
$cfg['blowfish_secret'] = 'ba17c1ec07d65003'; // use here a value of your choice
$i=0;
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
?>
5、重启http服务。
sudo /etc/init.d/httpd restart
访问: http://localhost/phpmyadmin
如果一切正常,则可以看到phpmyadmin的页面。
出错问题&解决方法:
1:
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1
解决方法:我安装了libtool.i386还是不能解决
所以再安装个libtool-ltdl-devel.i386
2、
转载本站文章请注明,转载自:扶凯[http://www.php-oa.com]
本文链接: http://www.php-oa.com/2008/03/28/php-make.html
好久没有编译安装过php了,为了玩nginx.没法子,编译一次来测试.我加的编译的参数是:
- # ./configure –prefix=/usr/local/php –with-config-file-path=/etc –with-gd –enable-gd-native-ttf –with-mysql –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir –enable-xml –disable-debug –disable-rpath –enable-discard-path –enable-safe-mode –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –enable-fastcgi –enable-force-cgi-redirect –enable-mbstring –with-mcrypt
没想到老是出下面的错
checking for mysql_close in -lmysqlclient… no
checking for mysql_error in -lmysqlclient… no
configure: error: mysql configure failed. Please check config.log for more information.
google很久,都讲下面的答案,晕,这种也叫答案,那我不是还要重新编译一次mysql.这个php就很麻烦了.这个一定不对.
网查找说:安装PHP的时候没有指定一下mysql的安装目录。但是我已经指定了,所以这个说法是错误的,其实主要原因是 mysql-level没有装,也就是mysql的版本不对,应该换
mysql-max-5.0.21版本(包含所有mysql相关内容的软件包)
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.so when searching for -lmysqlclient
/usr/bin/ld: skipping incompatible /usr/lib/mysql/libmysqlclient.a when searching for -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
collect2: ld returned 1 exit status
configure: failed program was:
#line 59854 "configure"
#include "confdefs.h"
在看看config.log提示的错….哦.原来是版本有问题.想起我的系统都是X86的,lib都是64位的.所以解决方法很容易.
这个libmysqlclient.a library 是在 /usr/lib64/mysql, 不是在 /usr/lib/mysql.
所以可以做下面的方法来解决
- #export LDFLAGS=-L/usr/lib64/mysql
OR
请将Makefile里面的
-L/usr/lib/mysql
改为
-L/usr/lib64/mysql
3、
make: *** [sapi/cli/php] Error 1 解决办法
ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':
/home/king/php-5.2.13/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1
[root@test php-5.2.13]# vi Makefile
在安裝 PHP 到系统中时要是发生「undefined reference to libiconv_open'」之类的错误信息,那表示在「./configure 」沒抓好一些环境变数值。错误发生点在建立「-o sapi/cli/php」是出错,没給到要 link 的 iconv 函式库参数。
解决方法:
编辑Makefile 大约77 行左右的地方: EXTRA_LIBS = ..... -lcrypt 在最后加上 -liconv,例如: EXTRA_LIBS = ..... -lcrypt -liconv 然后重新再次 make 即可。
或者用另一种办法
make ZEND_EXTRA_LIBS='-liconv'
ln -s /usr/local/lib/libiconv.so.2 /usr/lib64/
小结:被这个配置给搞得头痛不已,在配置过程中总是出错,看着别人博客里的介绍,总是和自己所遇到的情况有所出入。真正最后定下来的方法还真是有所区别。所以,尽量首选官方的安装文档,这样是最靠谱的。其次才是在网上搜这些教程之类的。(当然,我这篇文章也是这样,仅供参考,具体的情况还是得靠自己选择)。另外,就是整理文档出来,是一件很有意义的事,在让自己回顾知识的同时,也能和别人分享。