归档文章 (2011-2017)

date
2011/01/13
PHP 是一种在服务器端执行的脚本语言,主要用来制作动态网页以提供浏览器读取,但也可以用来开发命令行脚本程序和用户端的GUI应用程序。PHP 可以在许多的不同种的服务器、操作系统、平台上运行,也可以和许多数据库系统结合。

一、准备工作

系统版本:Ubuntu-10.10-Server-I386
OpenSSL 版本:openssl-1.0.0c (安装方法
OpenSSH 版本:openssh-5.6p1 (安装方法
Apache 版本:httpd-2.2.17 (安装方法
MySQL 5 版本:mysql-5.1.53-linux-i686-glibc23 (安装方法

二、编译安装 GD

GD不是必须的,如果要安装GD,那么 jpeg 库,png 库,zlib 库则是必须的,其余的选择安装。

2.1、编译安装 Zlib

wget http://zlib.net/zlib-1.2.5.tar.gz tar -zxf zlib-1.2.5.tar.gz cd zlib-1.2.5/ ./configure --prefix=/usr/local make && make install

2.2、编译安装 PNG

wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.4.4.tar.gz tar -zxf libpng-1.4.4.tar.gz cd libpng-1.4.4/ ./configure --prefix=/usr/local make && make install

2.3、编译安装 JPEG

wget http://www.ijg.org/files/jpegsrc.v8b.tar.gz tar -zxf jpegsrc.v8b.tar.gz cd jpeg-8b/ ./configure --prefix=/usr/local make && make install

2.4、编译安装 Libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz tar -zxf libiconv-1.13.1.tar.gz cd libiconv-1.13.1/ ./configure --prefix=/usr/local make && make install

2.5、编译安装 FreeType

wget http://nchc.dl.sourceforge.net/project/freetype/freetype2/2.4.3/freetype-2.4.3.tar.bz2 tar -jxf freetype-2.4.3.tar.bz2 cd freetype-2.4.3/ ./configure --prefix=/usr/local make && make install

2.6、编译安装 GD

wget http://www.libgd.org/releases/gd-2.0.36RC1.tar.gz tar -zxf gd-2.0.36RC1.tar.gz cd gd-2.0.36RC1/ ./configure --prefix=/usr/local --with-libiconv-prefix=/usr/local --with-png=/usr/local --with-freetype=/usr/local --with-jpeg=/usr/local make && make install

三、编译安装 PHP 5

3.1、编译安装 LibXML

wget http://xmlsoft.org/sources/libxml2-2.7.8.tar.gz tar -zxf libxml2-2.7.8.tar.gz cd libxml2-2.7.8 ./configure --prefix=/usr/local make && make install

3.2、编译安装 Mhash

wget http://nchc.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2 tar -jxf mhash-0.9.9.9.tar.bz2 cd mhash-0.9.9.9/ ./configure --prefix=/usr/local make && make install

3.3、编译安装 LibMcrypt & Mcrypt

wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz tar -zxf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8/ ./configure --prefix=/usr/local make && make install
如果要编译安装 Mcrypt,那么必须先安装 Mhash 和 LibMcrypt,否则会报错。
wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz tar -zxf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8/ ln -s /usr/local/bin/libmcrypt-config /usr/local/bin LD_LIBRARY_PATH=/usr/local/lib ./configure --prefix=/usr/local make && make install
编译安装 Mcrypt,配置时切勿遗漏了在环境变量 LD_LIBRARY_PATH 中指明库的搜索路径 ,或者按一下方法在 /etc/ld.so.conf 动态链接库文件中添加库的搜索路径。(资料1资料2)。
#编辑,添加共享库路径。 sudo vim /etc/ld.so.conf 添加一行:/usr/local/lib sudo ldconfig //更新ld.so.cache

3.4、安装编译 Curl

wget http://www.libssh2.org/download/libssh2-1.2.7.tar.gz tar -zxf libssh2-1.2.7.tar.gz cd libssh2-1.2.7/ ./configure --prefix=/usr/local make && make install
wget http://curl.haxx.se/download/curl-7.21.2.tar.gz tar -zxf curl-7.21.2.tar.gz cd curl-7.21.2/ ./configure --prefix=/usr/local --with-ssl=/usr/local/ssl --with-libssh2=/usr/local make && make install

3.5、编译安装 php5.3.3

wget http://cn.php.net/distributions/php-5.3.3.tar.gz tar -zxf php-5.3.3.tar.gz cd php-5.3.3/ ./configure --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache/bin/apxs \ --with-mysql=/usr/local/mysql \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --with-jpeg-dir=/usr/local \ --with-png-dir=/usr/local \ --with-zlib-dir=/usr/local \ --with-freetype-dir=/usr/local \ --with-iconv-dir=/usr/local \ --enable-gd-native-ttf \ --enable-gd-jis-conv \ --with-gd=/usr/local \ --with-libxml-dir=/usr/local \ --with-mhash=/usr/local \ --with-mcrypt=/usr/local \ --with-openssl=/usr/local \ --with-curl=/usr/local \ --with-curlwrappers \ --enable-bcmath \ --enable-wddx \ --enable-calendar \ --enable-mbstring \ --enable-ftp \ --enable-zip \ --enable-sockets make && make install

四、将Apache与PHP5相结合

cp php.ini-production /usr/local/php/lib/php.ini vim /usr/local/apache/conf/httpd.conf

4.1、设置php文件后缀

查找”AddType application/x-gzip .gz .tgz”,在下面添加:
AddType application/x-httpd-php .php

4.2、设置apache的默认文件名次序

查找”index.html”,后面添加“index.php”
index.htm index.html index.php

4.3、开启Apache Rewrite 模块

查找”Options FileInfo” 将”AllowOverride none” 改为 “AllowOverride all” //

4.4、关闭非必须的Apache模块

因为前期我将所有模块都编译了,所以现在要关闭暂不需要的模块以节省资源。必须开启的模块如下:
LoadModule authz_host_module modules/mod_authz_host.so LoadModule mime_module modules/mod_mime.so LoadModule autoindex_module modules/mod_autoindex.so LoadModule dir_module modules/mod_dir.so LoadModule alias_module modules/mod_alias.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule php5_module modules/libphp5.so

4.5、编译安装 ZendOptimizer

官方说明最新版的ZendOptimizer-3.3.9只适用于php5.2,不过你用在php5.3倒也不至于出错。
wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz tar -zxf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz cd ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp cp ZendOptimizer.so /usr/local/lib
vim /usr/local/php/lib/php.ini [ZendOptimizer] zend_optimizer.optimization_level=15 zend_extension=/usr/local/lib/ZendOptimizer.so

4.6、重启Apache服务器

httpd -k restart

五、添加 php5 扩展

服务器运行一段时间后,可能需求额外添加某个扩展,这就需要在不重新编译PHP的情况下独立添加扩展。下面以Memcache为例说明。

4.1、编译安装Memcache服务器端 (可选)

因为Memcache用到了libevent这个库用于Socket的处理,所以先安装libevent。(Memcache是什么?Memcache如何安装?
wget http://www.monkey.org/~provos/libevent-1.4.14b-stable.tar.gz tar -zxf libevent-1.4.14b-stable.tar.gz cd libevent-1.4.14b-stable/ ./configure --prefix=/usr/local make && sudo make install
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz tar -zxf memcached-1.4.5.tar.gz cd memcached-1.4.5/ ./configure --prefix=/usr/local --with-libevent=/usr/local make && sudo make install

4.2、编译安装Memcache的PHP扩展

添加扩展一般我们只需到php源码ext目录下找即可,但因为php没有自带Memcache扩展,所以你需要另外下载。
wget http://pecl.php.net/get/memcache-3.0.5.tgz tar -zxf memcache-3.0.5.tgz cd memcache-3.0.5/ sudo /usr/local/php5/bin/phpize ./configure --enable-memcache --with-php-config=/usr/local/php5/bin/php-config make && sudo make install
安装完后会看倒下面提示:Installing shared extensions:/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/
运行memcached: “/usr/local/bin/memcached”,新建php文件检测是否成功:
<?php$mem = new Memcache;$mem->connect("127.0.0.1", 11211);$mem->set('key', 'This is a test!', 0, 60);$val = $mem->get('key');echo $val;?>

4.3、修改php.ini文件

sudo gvim /usr/local/php/lib/php.ini``` ## 将 extension_dir = "./" 改为
extension_dir ="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/" extension=memcache.so
保存退出后,用以下命令检查php配置文件是否正确,然后重启Apache服务器
/usr/local/php5/bin/php -v sudo httpd -k restart

4.3、编译安装 eaccelerator

eaccelerator安装方法同上面基本一致(详细资料
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2 tar jxf eaccelerator-0.9.6.1.tar.bz2 cd eaccelerator-0.9.6.1/ sudo /usr/local/php5/bin/phpize ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config make && sudo make install sudo mkdir /usr/local/cache
修改php.ini文件,在[ZendOptimizer]前面加入下面代码,然后重启apache
[eaccelerator] extension='/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so' eaccelerator.shm_size='32' eaccelerator.cache_dir='/usr/local/cache' eaccelerator.enable='1' eaccelerator.optimizer='1' eaccelerator.check_mtime='1' eaccelerator.debug='0' eaccelerator.filter='' eaccelerator.shm_max='0' eaccelerator.shm_ttl='3600' eaccelerator.shm_prune_period='3600' eaccelerator.shm_only='0' eaccelerator.compress='1' eaccelerator.compress_level='9'

五、安装 phpmyadmin

5.1、安装 phpMyAdmin-3.3.8

wget http://nchc.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.8.1/phpMyAdmin-3.3.8.1-all-languages.tar.gz tar -zxf phpMyAdmin-3.3.8.1-all-languages.tar.gz -C /usr/local/apache/htdocs/ mv /usr/local/apache/htdocs/phpMyAdmin-3.3.8.1-all-languages/ /usr/local/apache/htdocs/phpMyAdmin cd /usr/local/apache/htdocs/phpMyAdmin cp libraries/config.default.php ./config.inc.php

5.2、激活链接表的附加功能

不想出现“链接表的附加功能尚未激活。要查出原因,请点击此处“这样提示就照做吧。
5.2.1.先建立一个名为phpmyadmin的数据库
/usr/local/mysql/bin/mysql -u root -p CREATE DATABASE ```phpmyadmin```;
5.2.2.然后把目录下scripts/create_tables.sql导入到这个库
/usr/local/mysql/bin/mysql -u root -p use phpmyadmin source /usr/local/apache/htdocs/phpMyAdmin/scripts/create_tables.sql
3.编辑config.inc.php配置文件.
vim /usr/local/apache/htdocs/phpMyAdmin/config.inc.php
$cfg['Servers'][$i]['pmadb'] = ''; $cfg['Servers'][$i]['bookmarktable'] = ''; $cfg['Servers'][$i]['relation'] = ''; $cfg['Servers'][$i]['table_info'] = ''; $cfg['Servers'][$i]['table_coords'] = ''; $cfg['Servers'][$i]['pdf_pages'] = ''; $cfg['Servers'][$i]['column_info'] = ''; $cfg['Servers'][$i]['history'] = ''; $cfg['Servers'][$i]['tracking'] = '';
将上面语句改成下面的
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark'; $cfg['Servers'][$i]['relation'] = 'pma_relation';$cfg['Servers'][$i]['table_info'] = 'pma_table_info';$cfg['Servers'][$i]['table_coords'] = 'pma_table_coords'; $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages'; $cfg['Servers'][$i]['column_info'] = 'pma_column_info';$cfg['Servers'][$i]['history'] = 'pma_history'; $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords';$cfg['Servers'][$i]['tracking'] = 'pma_tracking';

5.3、配置文件设置短语密码

同理,不想出现“配置文件现在需要一个短语密码。“这样提示,就照做吧。
编辑config.inc.php配置文件. 修改$cfg[‘blowfish_secret’]的值,其中’abc’为任意值
$cfg['blowfish_secret'] = 'abc';

五、结语

至此,基本的LAMP环境搭建结束了,上述方法同样适用于ubuntu server 和 Debian 。需要说的是目前只是进行了初步的配置,没做任何安全配置,实际部署还请参考其他相关文章。
If you have any questions, please contact me.