CentOS 5.5 LAMP环境编译

安装时准备工作

检测是否安装相关编译工具

[root@localhost ~]# rpm -q make
make-3.81-3.el5
[root@localhost ~]# rpm -q gcc
package gcc is not installed
[root@localhost ~]# rpm -q gcc-c++
package gcc-c++ is not installed

检测到未安装gcc和gcc-c++编译器

[root@localhost ~]# yum install gcc
[root@localhost ~]# yum install gcc-c++

检查是否安装apache,mysql,php并进行卸载

[root@localhost ~]# rpm -qa | grep httpd
[root@localhost ~]# yum remove httpd
[root@localhost ~]# rpm -qa | grep mysql
[root@localhost ~]# yum remove mysql
[root@localhost ~]# rpm -qa | grep php
[root@localhost ~]# yum remove php

禁用SElinux

[root@localhost ~]# vi /etc/sysconfig/selinux 
//将selinux改为disabled并重启系统
SELINUX=disabled

删除防火墙规则iptables -F

[root@localhost ~]# iptables -F

简单的解压shell脚本

[root@localhost ~]# vi tar.sh
#!/bin/sh
cd /root
ls *.tar.gz > ls.list
for TAR in `cat ls.list`
do
        tar -zxf $TAR
done
//执行解压脚本
[root@localhost ~]# sh -x tar.sh

安装相应依赖包

标准源码包编译安装步骤

1、解压解包  .tar.gz   tar -zxf

2、./configure  配置

3、make  编译

4、make install  安装、拷贝

libxml2

1)libxml2

[root@localhost ~]# cd libxml2-2.6.30
[root@localhost libxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2/
[root@localhost libxml2-2.6.30]# make
[root@localhost libxml2-2.6.30]# make install

libmcrypt

2)libmcrypt

[root@localhost libxml2-2.6.30]# cd ../libmcrypt-2.5.8
[root@localhost libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt
[root@localhost libmcrypt-2.5.8]# make && make install
//当前目录下面还有个工具需要安装
[root@localhost libmcrypt-2.5.8]# cd libltdl
[root@localhost libltdl]# ./configure --enable-ltdl-install
[root@localhost libltdl]# make && make install

zlib

3)zlib

[root@localhost libmcrypt-2.5.8]# cd ../zlib-1.2.3
//不指定安装路径,防止其他软件无法定位位置
[root@localhost zlib-1.2.3]# ./configure
//可将安装信息定位到文件中 make install > /backup/zlib_20151121.install.log
[root@localhost zlib-1.2.3]# make && make install

libpng

4)libpng

[root@localhost zlib-1.2.3]# cd ../libpng-1.2.31
[root@localhost libpng-1.2.31]# ./configure --prefix=/usr/local/libpng/
[root@localhost libpng-1.2.31]# make && make install

jpeg6

5)jpeg6

[root@localhost libpng-1.2.31]# cd ../jpeg-6b/
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/bin
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/lib
[root@localhost jpeg-6b]# mkdir /usr/local/jpeg6/include
[root@localhost jpeg-6b]# mkdir -p /usr/local/jpeg6/man/man1
[root@localhost jpeg-6b]# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
[root@localhost jpeg-6b]# make && make install

freetype

6)freetype

[root@localhost jpeg-6b]# cd ../freetype-2.3.5
[root@localhost freetype-2.3.5]# ./configure --prefix=/usr/local/freetype/
[root@localhost freetype-2.3.5]# make && make install

autoconf

7)autoconf

[root@localhost freetype-2.3.5]# cd ../autoconf-2.61
//最好不指定安装目录
[root@localhost autoconf-2.61]# ./configure
[root@localhost autoconf-2.61]# make && make install

gd

8)gd

[root@localhost autoconf-2.61]# cd ../gd-2.0.35
//无需指定zlib,让其自动查找
[root@localhost gd-2.0.35]# ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
[root@localhost gd-2.0.35]# make && make install

Apache

9)apache

[root@localhost gd-2.0.35]# cd ../httpd-2.2.9
//无需--with-z=/usr/local/zlib/让其自动查找
[root@localhost httpd-2.2.9]# ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
[root@localhost httpd-2.2.9]# make && make install
//测试apache是否正常
[root@localhost httpd-2.2.9]# /usr/local/apache2/bin/apachectl start
[root@localhost httpd-2.2.9]# ps -le | grep httpd
//设置apache自启动
[root@localhost mysql-5.0.41]# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local

MySQL

10)mysql

//编译mysql前,先需安装编译工具ncurses
[root@localhost httpd-2.2.9]# cd ../ncurses-5.6
[root@localhost ncurses-5.6]# ./configure --with-shared --without-debug --without-ada --enable-overwrite
[root@localhost ncurses-5.6]# make && make install
//创建用户组和用户
[root@localhost ncurses-5.6]# groupadd mysql
[root@localhost ncurses-5.6]# grep mysql /etc/group
mysql:x:501:
[root@localhost ncurses-5.6]# useradd -g mysql mysql
[root@localhost ncurses-5.6]# grep mysql /etc/passwd
mysql:x:501:501::/home/mysql:/bin/bash
//编译msyql
[root@localhost ncurses-5.6]# cd ../mysql-5.0.41
[root@localhost mysql-5.0.41]# ./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
[root@localhost mysql-5.0.41]# make && make install
//生成配置文件
[root@localhost mysql-5.0.41]# cp support-files/my-medium.cnf /etc/my.cnf
//创建mysql数据库授权表
[root@localhost mysql-5.0.41]# /usr/local/mysql/bin/mysql_install_db --user=mysql
//修改权限
[root@localhost mysql-5.0.41]# chown -R root /usr/local/mysql
[root@localhost mysql-5.0.41]# chown -R mysql /usr/local/mysql/var
[root@localhost mysql-5.0.41]# chgrp -R mysql /usr/local/mysql
//启动mysql
[root@localhost mysql-5.0.41]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 11042
//检测mysql是否启动成功
[root@localhost mysql-5.0.41]# ps -le | grep mysqld
[root@localhost mysql-5.0.41]# netstat -an | grep 3306
//设置密码
root@localhost mysql-5.0.41]# /usr/local/mysql/bin/mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('root');
Query OK, 0 rows affected (0.00 sec)
//设置mysql自动启动
[root@localhost mysql-5.0.41]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
//同时改变所有者和所属组
[root@localhost mysql-5.0.41]# chown root.root /etc/rc.d/init.d/mysqld 
[root@localhost mysql-5.0.41]# chmod 755 /etc/rc.d/init.d/mysqld
//纳入到chkconfig体系中
[root@localhost mysql-5.0.41]# chkconfig --add mysqld
//查看在每个运行级别的启动状态
[root@localhost mysql-5.0.41]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
//更改启动级别
[root@localhost mysql-5.0.41]# chkconfig --levels 245 mysqld off
[root@localhost mysql-5.0.41]# chkconfig --list mysqld
mysqld          0:off   1:off   2:off   3:on    4:off   5:off   6:off

PHP

11)php

[root@localhost php-5.2.6]# cd ../php-5.2.6
[root@localhost php-5.2.6]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
[root@localhost php-5.2.6]# make && make install
//复制配置文件
[root@localhost php-5.2.6]# cp php.ini-dist /usr/local/php/etc/php.ini
//编辑apache配置文件
[root@localhost php-5.2.6]# vi /etc/httpd/httpd.conf
//搜索AddType添加
 Addtype application/x-httpd-php .php .phtml
//重新启动apache
[root@localhost php-5.2.6]# /usr/local/apache2/bin/apachectl restart
//测试脚本
[root@localhost php-5.2.6]# vi /usr/local/apache2/htdocs/phpinfo.php
<?php
        phpinfo();
?>
//访问显示版本信息,解析php正确

zend加速器

12)zend加速器

[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]# cd ../ZendOptimizer-3.2.6-linux-glibc21-i386
[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]# ./install.sh
//输入php.ini的配置文件地址
/usr/local/php/etc

phpmyadmin

13)phpmyadmin

[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]# cp -a /root/phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpmyadmin
[root@localhost ZendOptimizer-3.2.6-linux-glibc21-i386]# cd /usr/local/apache2/htdocs/phpmyadmin/
[root@localhost phpmyadmin]# cp config.sample.inc.php config.inc.php[root@localhost phpmyadmin]# vi config.inc.php
//更改配置文件认证方式$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'http';

安装curl拓展

14)安装curl拓展

[root@localhost ~]# cd curl-7.19.6
[root@localhost curl-7.19.6]# ./configure --prefix=/usr/local/curl
[root@localhost curl-7.19.6]# make && make install
//进入php源程序目录中的ext目录中的curl
[root@localhost curl-7.19.6]# cd ../php-5.2.6/ext/curl/
//调用phpize程序生成编译,配置文件
[root@localhost curl]# /usr/local/php/bin/phpize
[root@localhost curl]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-curl=/usr/local/DIR
//出错:configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
//其实就是curl的dev包没有安装, 解决方案:
[root@localhost curl]# yum -y install curl-devel
//安装完后再进行编译安装
[root@localhost curl]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-curl=/usr/local/DIR
[root@localhost curl]# make && make install
//php下创建ext目录并将编译好的扩展拷到该目录
[root@localhost curl]# mkdir /usr/local/php/ext
[root@localhost curl]# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/curl.so /usr/local/php/ext/
//php配置文件修改php拓展库目录
[root@localhost curl]# vi /usr/local/php/etc/php.ini
extension_dir = "/usr/local/php/ext"
extension=curl.so
//执行命令时,php会去检测配置文件是否正确
[root@localhost curl]# /usr/local/php/bin/php -v
//重启apache,查看模块是否存在
[root@localhost curl]# /usr/local/apache2/bin/apachectl restart
[root@localhost curl]# /usr/local/php/bin/php -m | grep curl
curl

 

posted on 2017-06-28 16:27  gimin  阅读(137)  评论(0)    收藏  举报