当前位置:Gxlcms > PHP教程 > Linux下PHP开发环境搭建-php,mysql,apache

Linux下PHP开发环境搭建-php,mysql,apache

时间:2021-07-01 10:21:17 帮助过:20人阅读

原文url: http://blog.sina.com.cn/s/blog_4b029ef301007xky.html

软件安装列表

zlib.

mysql

php

http

libpng

freetype

jpegsrc

libxml

我都采用源代码安装,因为这样比较灵活,能自己指定安装目录并配置参数,或者进行特性的选取与优化。

说明:所有的包都安装在/data目录下。

(1):
安装zlib
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure --prefix=/data/zlib
make
make install
然后在/etc/ld.so.conf中添加
/data/zlib/lib
保存,执行ldconfig -v
(2)mysql installing.
#groupadd mysql
#useradd -g mysql mysql
# vi /home/mysql/.bash_profile
添加
export PATH=$PATH:/data/mysql/bin
保存后,进入安装包所在目录,先安装Mysql
解压缩:
tar -zxvf mysql-5.0.45.tar.gz
cd mysql-5.0.45

接着要进行configure配置,在以前我只是制定了prefix没有设置字体编码,结果PHP后来不支持汉字编码,只好重新安装
才发现这个问题要注意,而且我们已经安装了zlib,就可以给mysql来指明zlib的位置
[root@cme_box mysql-5.0.45]# ./configure --prefix=/data/mysql --with-zlib-dir=/data/zlib/ --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8
make
make install
同样,在/etc/ld.so.conf中添加一行
/data/mysql/lib/mysql
保存,执行ldconfig -v
#./scripts/mysql_install_db
#chown -R root /data/mysql
#chown -R mysql /data/mysql/var
#chgrp -R mysql /data/mysql
# cp support-files/my-medium.cnf /etc/my.cnf
#/data/mysql/bin/mysqld_safe &
下来再init.d中设置mysql的自启动。
# cp support-files/mysql.server /etc/init.d/mysql
cd /etc/rc3.d
ln -s ../init.d/mysql S85mysql
ln -s ../init.d/mysql K85mysql
cd ../rc5.d/
ln -s ../init.d/mysql S85mysql
ln -s ../init.d/mysql K85mysql
cd ../init.d
chmod 755 mysql
然后reboot查看mysql是否启动。
(3)安装apache
tar -zxvf httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/data/httpd/ --enable-so --enable-cgi --with-z=/data/zlib
make
make install
cp /data/httpd/bin/apachectl /etc/init.d/httpd
cp: overwrite `/etc/init.d/httpd'? y
cd /etc/rc3.d
rm -fr K15httpd
cd /etc/rc5.d
rm -fr K15httpd
cd /etc/rc3.d
ln -s ../init.d/httpd K85httpd
ln -s ../init.d/httpd S85httpd
cd /etc/rc5.d
ln -s ../init.d/httpd K85httpd
ln -s ../init.d/httpd S85httpd
chmod 755 /etc/init.d/httpd
(4)安装GD库
首先,我们要安装各个图形库的支持,包括libpng, libjpeg,ttf等。
1)libpng
tar -zxvf libpng-1.2.23.tar.gz
./configure --prefix=/data/libpng
make
make install
然后将libpng的路径(/data/libpng/lib)加到/etc/ld.so.conf下,执行ldconfig -v
能看到
/data/libpng/lib:
libpng.so.3 -> libpng.so.3.23.0
libpng12.so.0 -> libpng12.so.0.23.0
这一项。说明安装成功。
2)freetype
tar -zxvf freetype-2.1.10.tar.gz
cd freetype-2.1.10
./configure --prefix=/data/freetype
make
make install
then add the path of freetype(/data/freetype/lib) to /etc/ld.so.conf and run command "ldconfig -v",we can get
the output
/data/freetype/lib:
libfreetype.so.6 -> libfreetype.so.6.3.8
3)jpeg
tar -zxvf jpegsrc.v6b.tar.gz
./configure --prefix=/data/jpeg --enable-shared
make
make install
提示:/usr/bin/install: cannot create regular file `/data/jpeg/include/jconfig.h': No such file or directory
nnd,在CU上查到了,原来是安装程序没有权限在/data下自己创建目录,需要手动创建
当我创建include目录后,提示lib目录不存在,创建lib目录后,又提示man/man1目录不存在,那就挨个创建吧。
cd /data/jpeg
mkdir include lib man bin
mkdir man/man1
然后make install就OK了。
然后在/etc/ld.so.conf中添加一行 /data/jpeg/lib,执行命令 ldconfig -v,可以看到
/data/jpeg/lib:
libjpeg.so.62 -> libjpeg.so.62.0.0
4)安装fontconfig

tar -zxvf fontconfig-2.5.0.tar.gz

cd fontconfig-2.5.0
./configure --prefix=/data/fontconfig --with-freetype-config=/data/freetype/bin/freetype-config

make

make install

cd /data/fontconfig/lib

pwd >> /etc/ld.so.conf

ldconfig -v | grep fontconfig

安装GD
tar -zxvf gd-2.0.33.tar.gz
./configure --prefix=/data/gd --with-png=/data/libpng --with-freetype=/data/freetype --with-jpeg=/data/jpeg --with-fontconfig=/data/fontconfig

(在以前没有加fontconfig的时候,会报这个错,但是2008-12-15日加了fontconfig后,却没有报错,一路make,make install很顺利,不过还是要写上,以防再遇到:make时系统提示找不到png.h,手动修改makefile
在CPPFLAGS = 行末加上 -I/data/libpng/include
在CFLAGS = -g -O2 行末加上
-DHAVE_JPEG -DHAVE_LIBTTF -DHAVE_PNG
修改为
CFLAGS = -g -O2 -DHAVE_JPEG -DHAVE_LIBTTF -DHAVE_PNG
)

然后
make
make install
(4)安装libxml
tar -zxvf libxml2-2.6.11.tar.gz
./configure --prefix=/data/xml --with-zlib=/data/zlib
make
make install
然后把xml的库路径【 /data/xml/lib/】添加到/etc/ld.so.conf文件中保存后执行ldconfig -v
看到
/data/xml/lib:
libxml2.so.2 -> libxml2.so.2.6.11
添加gd的库路径[/data/gd/lib]到etc/ld.so.conf文件,执行ldconfig -v
(5)安装php
tar -zxvf php-5.2.4.tar.gz
./configure --prefix=/data/php --with-zlib-dir=/data/zlib --with-mysql=/data/mysql --with-apxs2=/data/httpd/bin/apxs --with-config-file-path=/data/php --with-gd --enable-sysvmsg --enable-sockets --enable-sysvshm --enable-sysvsem --enable-gd-native-ttf --with-ttf=/usr/lib --with-jpeg-dir=/data/jpeg --with-png-dir=/data/libpng --with-iconv --with-libxml-dir=/data/xml
make
make install

cp php.ini-dist /data/php/php.ini


(6)在http.conf中设置php支持。
vi /data/httpd/conf/http.conf

# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so
下添加一行
AddType application/x-httpd-php .php
并将

DirectoryIndex index.html

修改为

DirectoryIndex index.php index.html

设置默认主页为index.php
然后在/data/php/php.ini中添加一行
default_charset = "gb2312"
保存
service httpd restart
进行测试
在 /data/httpd/htdocs/下建立index.php
写入内容为 保存
打开页面输入url地址
http://192.168.x.x/
就能看到phpinfo的输出了。
如果想修改http的默认根目录,或者说你不想把自己的文件放在/data/httpd/htdoc目录下
可以修改httpd.conf中的
DocumentRoot "/data/httpd/htdoc"为
DocumentRoot "/cme/web"


然后还要给新的目录加上能执行的权限
chmod +x /cme
chmod +x /cme/web
重启服务 service httpd restart
就OK了。

人气教程排行