博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

搭建LAMP环境(三)

Posted on 2009-06-17 14:25  Leey  阅读(460)  评论(0编辑  收藏  举报

编译安装PHP,MYSQL,Apache

1。下载软件:

#wget http://apache.etoak.com/httpd/httpd-2.2.11.tar.gz
#wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.35.tar.gz/from/ftp://ftp.jaist.ac.jp/pub/mysql/
#wget http://cn2.php.net/get/php-5.2.9.tar.bz2/from/cn.php.net/mirror

ZendOptimizer 下载地址:http://www.zend.com/en/products/guard/downloads

2。编译安装MYSQL

#tar zxvf  mysql-5.1.35.tar.gz

#cd  mysql-5.1.35

# ./configure \
"--prefix=/usr/local/mysql" \
"--localstatedir=/var/lib/mysql" \
"--with-comment=Source" \
"--with-server-suffix=-Comsenz" \
"--with-mysqld-user=mysql" \
"--without-debug" \
"--with-big-tables" \
"--with-charset=gbk" \
"--with-collation=gbk_chinese_ci" \
"--with-extra-charsets=all" \
"--with-pthread" \
"--enable-static" \
"--enable-thread-safe-client" \
"--with-client-ldflags=-all-static" \
"--with-mysqld-ldflags=-all-static" \
"--enable-assembler" \
"--without-isam" \
"--without-innodb" \
"--without-ndb-debug"

#make

#make install


附上mysql字符集设置表

SHOW CHARACTER SET;
+----------+-----------------------------+---------------------+
| Charset  | Description                 | Default collation   |
+----------+-----------------------------+---------------------+
| big5     | Big5 Traditional Chinese    | big5_chinese_ci     |
| dec8     | DEC West European           | dec8_swedish_ci     |
| cp850    | DOS West European           | cp850_general_ci    |
| hp8      | HP West European            | hp8_english_ci      |
| koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    |
| latin1   | cp1252 West European        | latin1_swedish_ci   |
| latin2   | ISO 8859-2 Central European | latin2_general_ci   |
| swe7     | 7bit Swedish                | swe7_swedish_ci     |
| ascii    | US ASCII                    | ascii_general_ci    |
| ujis     | EUC-JP Japanese             | ujis_japanese_ci    |
| sjis     | Shift-JIS Japanese          | sjis_japanese_ci    |
| hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   |
| tis620   | TIS620 Thai                 | tis620_thai_ci      |
| euckr    | EUC-KR Korean               | euckr_korean_ci     |
| koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    |
| gb2312   | GB2312 Simplified Chinese   | gb2312_chinese_ci   |
| greek    | ISO 8859-7 Greek            | greek_general_ci    |
| cp1250   | Windows Central European    | cp1250_general_ci   |
| gbk      | GBK Simplified Chinese      | gbk_chinese_ci      |
| latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   |
| armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci |
| utf8     | UTF-8 Unicode               | utf8_general_ci     |
| ucs2     | UCS-2 Unicode               | ucs2_general_ci     |
| cp866    | DOS Russian                 | cp866_general_ci    |
| keybcs2  | DOS Kamenicky Czech-Slovak  | keybcs2_general_ci  |
| macce    | Mac Central European        | macce_general_ci    |
| macroman | Mac West European           | macroman_general_ci |
| cp852    | DOS Central European        | cp852_general_ci    |
| latin7   | ISO 8859-13 Baltic          | latin7_general_ci   |
| cp1251   | Windows Cyrillic            | cp1251_general_ci   |
| cp1256   | Windows Arabic              | cp1256_general_ci   |
| cp1257   | Windows Baltic              | cp1257_general_ci   |
| binary   | Binary pseudo charset       | binary              |
| geostd8  | GEOSTD8 Georgian            | geostd8_general_ci  |
| cp932    | SJIS for Windows Japanese   | cp932_japanese_ci   |
| eucjpms  | UJIS for Windows Japanese   | eucjpms_japanese_ci |
+----------+-----------------------------+---------------------+

 

 

# useradd mysql
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql .
# chown -R mysql /var/lib/mysql
# cp share/mysql/my-huge.cnf /etc/my.cnf
# cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# /etc/rc.d/init.d/mysqld start

# bin/mysql -u root password "password_for_root"

3.编译安装Apache

# cd /usr/local/src
# tar xjvf httpd-2.2.3.tar.bz2
# cd httpd-2.2.3
# ./configure \
"--prefix=/usr/local/apache2" \
"--enable-module=so" \
"--enable-deflate=shared" \
"--enable-expires=shared" \
"--enable-rewrite=shared" \
"--enable-static-support" \
"--enable-static-htpasswd" \
"--enable-static-htdigest" \
"--enable-static-rotatelogs" \
"--enable-static-logresolve" \
"--enable-static-htdbm" \
"--enable-static-ab" \
"--enable-static-checkgid" \
"--disable-userdir"
# make
# make install
# echo '/usr/local/apache2/bin/apachectl start ' >> /etc/rc.local

 4。编译安装PHP

# cd /usr/local/src
# tar xjvf php-5.2.0.tar.bz2
# cd php-5.2.0
# ./configure \
"--prefix=/usr/local/php" \
"--with-apxs2=/usr/local/apache2/bin/apxs" \
"--with-config-file-path=/etc" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir=/usr/local/libxml2" \
"--with-gd=/usr/local/gd2" \
"--enable-gd-native-ttf" \
"--with-jpeg-dir" \
"--with-png-dir" \
"--with-bz2" \
"--with-freetype-dir" \
"--with-iconv-dir" \
"--with-zlib-dir" \
"--enable-mbstring" \
"--disable-ipv6" \ # IPv6 离我们还好远,暂时不用它
"--disable-cgi" \   # 出于安全考虑,禁用 CGI 支持
"--disable-cli"     # 出于安全考虑,禁止编译出 php Command Line Shell 命令
# make
# make install
# cp php.ini-dist /etc/php.ini

configure时候出现了错误
“configure: error: libpng.(a|so) not found.”

需要逐一检查freetype,libjpeg,libpng

步骤如下:

1、检查freetype是否安装
#rpm -qa | grep freetype
没有的话编译freetype 下载地址:http://www.freetype.org/index2.html
#./configure --prefix=/usr/local/freetype
#make && make install 即可,没有花头
2、检查libjpeg是否安装
#rpm -qa | grep libjpeg
没有的话编译libjpeg 下载地址:http://www.ijg.org/files/
我也没装libjpeg,下载好开始编译
jpegsrc.v6b.tar.gz
#tar -xzvf jpegsrc.v6b.tar.gz
#cd jpeg-6b/
#./configure --prefix=/usr/local/jpeg --enable-shared
#make && make install
最后一步make install 出错:
/usr/bin/install -c -m 644 jconfig.h /usr/local/jpeg/include/jconfig.h
/usr/bin/install: cannot create regular file `/usr/local/jpeg/include/jconfig.h': No such file or directory
make: *** [install-headers] Error 1
/usr/bin/install: cannot create regular file `/usr/local/jpeg/lib/libjpeg.so.62.0.0': No such file or directory
/usr/bin/install: cannot create regular file `/usr/local/jpeg/bin/cjpeg': No such file or directory
make: *** [install-lib] Error 1
。。。自己去新建目录。。。
#mkdir -p /usr/local/jpeg/include
#mkdir -p /usr/local/jpeg/lib
#mkdir -p /usr/local/jpeg/bin
#mkdir -p /usr/local/jpeg/man/man1
OK再编译就成功了
3、检查是否安装了libpng
#rpm -qa libpng
没有的话编译libpng 下载地址:http://www.libpng.org/pub/png/libpng.html
#./configure --prefix=/usr/local/png
#make && make install

全部安装完毕之后

php configure参数 调整如下:

#./configure \
"--prefix=/usr/local/php" \
"--with-apxs2=/usr/local/apache2/bin/apxs" \
"--with-config-file-path=/etc" \
"--with-mysql=/usr/local/mysql" \
"--with-libxml-dir=/usr/local/libxml2" \
"--with-gd=/usr/local/gd2" \
"--enable-gd-native-ttf" \
"--with-jpeg-dir=/usr/local/jpeg" \
"--with-png-dir=/usr/local/png" \
"--with-bz2" \
"--with-freetype-dir=/usr/local/freetype" \
"--with-iconv-dir" \
"--with-zlib-dir" \
"--enable-mbstring" \
"--disable-ipv6" \
"--disable-cgi" \
"--disable-cli"

 

5。安装Zend Optimizer# cd /usr/local/src


# tar xzvf ZendOptimizer-3.2.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.2.0-linux-glibc21-i386/install.sh
安装Zend Optimizer过程的最后不要选择重启Apache。

 6.整合Apache与PHP

# vi /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
AddType application/x-httpd-php .php
AddOutputFilterByType DEFLATE text/html text/plain text/xml

找到:
<IfModule dir_module>
    DirectoryIndex index.html index.html.var
</IfModule>
将该行改为
<IfModule dir_module>
    DirectoryIndex index.html index.htm index.php
</IfModule>

找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf
去掉前面的“#”号,取消注释,设置相关的模块配置文件。

修改完成后保存退出。
# /usr/local/apache2/bin/apachectl restart

 

7. 查看确认L.A.M.P环境信息,提升 PHP 安全性

# echo '#!/usr/local/php/bin/php \
<?php \
     phpinfo(); \
     ?>' > /usr/local/php/phpinfo.php
# chmod 755 /usr/local/php/phpinfo.php
# /usr/local/php/phpinfo.php > /usr/local/php/phpinfo
# more /usr/local/php/phpinfo
检查phpinfo中的各项信息是否正确。

确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性。
# vi /etc/php.ini
   找到:
   disable_functions =
   设置为:
   disable_functions = phpinfo,passthru,exec,system,popen,chroot,escapeshellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status,ini_restore

后,重新启动 Apache 服务即可。