安装前准备,
源码安装LAMP虽然过程比较繁琐,但可以根据自己PHP程序的需要配置相应的环境,非常的灵活。
卸载yum已安装的amp包,
# yum -y remove httpd
# yum -y remove php
# yum -y remove mysql-server mysql
# yum -y remove php-mysql
mkdir -pv /usr/local/src/lamp 安装目录
cd /usr/local/src/lamp
cp /root/Desktop/bao/bao/* ./ 从已经下载的包拷贝到安装目录下
##download apache source code 下载包
wget http://apache.etoak.com/httpd/httpd-2.4.3.tar.gz
wget http://apache.dataguru.cn/apr/apr-1.4.6.tar.bz2
wget http://labs.mop.com/apache-mirror/apr/apr-util-1.5.1.tar.bz2
#######安装apache所需的包及httpd
###apr apache portable Run-time libraries apache可移植运行库
安装apache的时候,如果发现这个rm: cannot remove `libtoolT': No such file or directory 但是libtool已经安装 解决方法:
在执行./configure 之前,先执行:
# autoreconf --force --install
# libtoolize --automake --force
# automake --force --add-missing
tar fvxj apr-1.4.6.tar.bz2
cd apr-1.4.6
./configure --prefix=/usr/local/apr
make && make install
cd ..
tar fvxj apr-util-1.5.1.tar.bz2
cd apr-util-1.5.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
make && make install
cd ..
##configure
tar fvxz httpd-2.4.3.tar.gz
yum install zlib-devel gcc gcc-c++ openssl-devel pcre-devel -y 本地源
cd httpd-2.4.3
./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-module=so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-static-support --enable-static-ab --disable-userdir --with-mpm=prefork --enable-nonportable-atomics --disable-ipv6 --with-sendfile
--prefix=/usr/local/apache2:指定安装目录
--with-included-apr:在编译时强制使用当前源代码中绑定的APR版本
--enable-so:允许运行时加载DSO模块
--enable-deflate=shared:将deflate模块编译为DSO
--enable-expires=shared:将expires模块编译为DSO
--enable-headers=shared:将headers模块编译为DSO
--enable-rewrite=shared:将rewrite模块编译为DSO
--enable-static-support:使用静态连接(默认为动态连接)编译所有二进制支持程序
make && make install
/usr/local/apache2/bin/apachectl -k start 启动apache
##install mysql
cd ..
rpm -ivh cmake-2.6.4-7.el5.i386.rpm 这个是我自己的下载的,也可以./configure进行源码安装
groupadd mysql
useradd -g mysql mysql 添加mysql组与用户
yum install gcc gcc-c++ ncurses-devel libtool openssl-devel -y 本地源安装环境
mkdir -pv /usr/local/mysql/data 数据库目录
tar fzvx mysql-5.5.29.tar.gz
cd mysql-5.5.29
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data/ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DWITH_INNODBBASE_STORAGE_ENGINE=1 \
-DENABLE_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0 \
-DWITH_EMBEDED_SERVER=0
cmake 测试编译环境,如果提示错误可一行一行回车即可,
--prefix=/usr/local/mysql/:指定安装位置
--localstatedir=/usr/local/mysql/data:指定数据库文件位置
--without-debug:禁用调用模式
--with-unix-socket-path=/tmp/mysql.sock:指定sock文件位置
--with-client-ldflags=-all-static:
--with-mysqld-ldflags=-all-static:以纯静态方式编译服务端和客户端
--enable-assembler:使用一些字符函数的汇编版本
--with-extra-charsets=gbk,gb2312,utf8 :gbk,gb2312,utf8字符支持
--with-pthread:强制使用pthread库(posix线程库)
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
##config file edit
vim /etc/my.cnf 修改配置文件
skip-name-resolve=1 添加一行
cp support-files/mysql.server /etc/init.d/mysqlsource #init启动脚本
chmod 755 /etc/init.d/mysqlsource
chown mysql.mysql /usr/local/mysql/ -R 修改权限
sh scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ //初始化数据库
ln -s /usr/local/mysql/bin/* /usr/bin/
ln -s /usr/local/mysql/lib/* /usr/lib/
ln -s /usr/local/mysql/libexec/* /usr/local/libexec
ln -s /usr/local/mysql/share/man/man1/* /usr/share/man/man1
ln -s /usr/local/mysql/share/man/man8/* /usr/share/man/man8
/etc/init.d/mysqlsource start 启动mysql
mysql_secure_installation 设置mysql的密码
###安装php
yum install libxml2-devel bzip2-devel net-snmp-devel curl-devel libpng-devel freetype-devel libjpeg-devel zlib-devel -y 安装解析php网站的字库与图库支持等包;
wget http://lnamp-web-server.googlecode.com/files/libiconv-1.14.tar.gz 下载地址
cd ..
tar fvxz libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/ --with-apr=/usr/local/apr
make && make install
#####下载包的地址####
wget http://lcmp.googlecode.com/files/libmcrypt-2.5.8.tar.gz
wget http://lcmp.googlecode.com/files/mhash-0.9.9.9.tar.gz
wget http://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gz
######libmcrypt-2.5.8.tar.gz
cd ..
tar fvxz libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
yum -y install gcc-c++
./configure && make && make install && /sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install && make && make
######mhash-0.9.9.9.tar.gz
cd ..
cd ..
tar fvxz mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
ln -s /usr/local/lib/* /usr/lib/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/
#####mcrypt-2.6.8.tar.gz
cd ..
tar fvxz mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure && make && make install
##install php
wget http://cn2.php.net/get/php-5.4.11.tar.bz2/from/this/mirror
cd ..
tar fvxj php-5.4.11.tar.bz2
cd php-5.4.11
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-iconv-dir=/usr/local/ --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --with-pcre-regex --with-zlib --with-bz2 --enable-calendar --disable-phar --with-curl --enable-dba --with-libxml-dir --enable-ftp --with-gd --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-mhash --enable-mbstring --with-mcrypt --enable-pcntl --enable-xml --disable-rpath --enable-shmop --enable-sockets --enable-zip --enable-bcmath --with-snmp --disable-ipv6 --disable-rpath --disable-debug --with-apxs2=/usr/local/apache2/bin/apxs
--prefix=/usr/local/php:设置安装路径
--with-apxs2=/usr/local/apache/bin/apxs:编译共享的 Apache 2.0 模块
--with-config-file-path=/etc:指定配置文件php.ini地址
--with-config-file-scan-dir=/etc/php.d:指定额外的ini文件目录
--with-openssl:编译OpenSSL支持
--with-zlib:编译zlib支持
--enable-bcmath:启用BC风格精度数学函数
--with-bz2:BZip2支持
--with-curl:CRUL支持
--enable-ftp:FTP支持
--with-gd:GD支持
--enable-gd-native-ttf:启用TrueType字符串函数
--with-gettext:启用GNU gettext支持
--with-mhash:mhash支持
--enable-mbstring:启用支持多字节字符串
--with-mcrypt:编译mcrypt加密支持
--enable-soap:SOAP支持
--enable-zip:启用zip 读/写支持
--with-iconv=/usr/local/libiconv:iconv支持
--with-mysql=/usr/local/mysql:启用mysql支持
--without-pear:不安装PEAR
####
make ZEND_EXTRA_LIBS='-liconv'
make install 这里是安装php
cp php.ini-production /usr/local/php/etc/php.ini //复制配置文件php.ini
######
vim /usr/local/apache2/conf/httpd.conf
在 /usr/local/apache2/conf/httpd.conf文件中加入php文件类型解析:
Addtype application/x-httpd-php .php
<IfModule dir_module>
DirectoryIndex index.html在这里加上 index.php艾滋
</IfModule>
#########
killall httpd
/usr/local/apache2/bin/apachectl -k start 重启apache
lsof -i:80 查看80端口的状态
cd /usr/local/apache2/htdocs/
vim phpinfo.php添加<?php phpinfo(); ?> 测试
###########################################
ZendOptimizer的作用是分析,优化由Zend 编译器加密产生的代码的程序,对不是Zend编译器加密过的程序,没有必要安装这个。
64位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
32位:http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd /tmp
wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
tar xzf ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
cd /tmp/ZendOptimizer-3.3.9-linux-glibc23-i386/data/5_2_x_comp/
mkdir -p /usr/local/Zend/lib/
cp ZendOptimizer.so /usr/local/Zend/lib
加载zendoptimizer,建立/etc/php.d/zend.ini文件
[zend]
zend_optimizer.optimization_level=15
zend_extension=/usr/local/Zend/lib/ZendOptimizer.so
service httpd restart
##########
eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。 它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍。类似的php加速器有:Xcache,APC等。下面是安装方法:
cd /tmp
wget http://voxel.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.zip
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1
export PHP_PREFIX="/usr/local/php"
$PHP_PREFIX/bin/phpize
./configure -enable-eaccelerator=shared -with-php-config=$PHP_PREFIX/bin/php-config
make && make install
cd /tmp
mkdir eaccelerator
chmod 0777 eaccelerator
加载eAccelerator,创建/ec/php.d/ea.ini文件
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
eaccelerator.shm_size="32"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
service httpd restart