LAMP漫长编译安装

传说中的LAMP :Linux+Apache+MySQL+Python/Perl/PHP,Linux上安装方式:RPM和源码安装,源码安装要依赖包安装,可以定制安装

首先安装编译工具

yum install gcc
yum install gcc-c++
      1、httpd-2.4.16       2、php-5.6.11      3、mysql-5.6.20      4、libxml2-2.6.30       5、libmcrypt-2.5.8       6、zlib-1.2.3      7、libpng-1.2.31      8、jpeg-6b       9、freetype-2.4.0      10、autoconf-2.61       11、gd-2.0.35       12、ncurses-5.9     13、apr-1.5.2       apr-util-1.5.4

(这些可以在网上下载最好是最新版本的,也可以在http://pan.baidu.com/s/1jGs26sY下载;基本顺序Apache>MySQL>PHP)

先来安装Apache,首先安装Apr、Apr-util;Apr是Apache可移植运行库,可以让Apache跨操作系统安装(相当于一个虚拟机);Apr-util是给Apr提供接口。

1、安装Apr:
        ./configure --prefix=/usr/local/apr
	make 
	make install
2、安装Apr-util:
        ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
        make 
        make install
先装pcre-devel:yum install pcre-devel
3、安装httpd:               
        ./configure --prefix=/usr/local/apache/ \  #指定安装路径
        --sysconfdir=/etc/httpd/ \                 #指定配置文件路径
        --with-apr=/usr/local/apr \                #添加Apr  
        --with-apr-util=/usr/local/apr-util \      #Apr接口
        --disable-userdir \                        #不支持建立用户
        --enable-so \                              #添加支持dso模式
        --enable-rewrite=shared \                  #支持重写功能
        --enable-static-support                    #支持静态模式
        make
        make install
4、将Apache添加到系统服务:
        cp /usr/local/apache/bin/apachectl   /etc/init.d/httpd
        vim /etc/init.d/httpd
            #chkconfig:2345    85    15   设置启动级别,开机启动序号,关机关闭序号
            #description:apache
5、设置开机启动:
        chkconfig --add httpd
        chkconfig --level 35 httpd on     可以设置开机启动级别
        chkconfig httpd on
6、添加PATH路径:
        vim /etc/profile.d/httpd.sh
            export PATH=$PATH:usr/local/apache/bin
        source /etc/profile.d
测试service httpd start

安装MySQL5.5(直接解压缩就可以用)

1、解压缩:
        tar zxvf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local
        ln -sv mysql-5.5.28-linux2.6-i686    mysql      创建软连接,保留MySQL版本号,以便查看
2、创建mysql组和用户:
        groupadd -r -g 300 mysql      指定为系统用户组,不能登录到系统
        useradd -g 300 -r -u 300 mysql
        chown -R mysql:mysql /usr/local/mysql  
3、初始化:(如果你修改了数据存放路径,就要在/etc/my.cnf里修改)
        scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
4、设置开机启动:
        cp support-files/mysql.server /etc/init.d/mysqld   
        chmod 755 /etc/init.d/mysqld
        chkconfig mysqld on
5、配置文件:(根据操作系统实际内存,选择配置文件大小)
        cp support-files/my-medium.cnf  /usr/local/mysql/my.cnf
6、加入PATH路径:
        vim /etc/profile   
              PATH=$PATH:/usr/local/mysql/bin 
              export PATH 
        source /etc/profile
测试service mysqld start


安装PHP:(安装PHP要依赖很多库,libxml2、gd、zlib、libpng、freetype、jpegsrc、autoconf等)
1、安装libxml2(扩展标记语言库)
	cd libxml2-2.6.30
	./configure --prefix=/usr/local/libxml2/ 
 	make
        make install
2、安装libmcrypt(实现加密功能的库)
	 ./configure --prefix=/usr/local/libmcrypt/
                cd libltdl
                ./configure--enable-ltdl-install
                 make&&make install
         make
	 make install
3、安装zlib(互联网通用压缩库,如果是64位系统:#vim Makefile      改CFLAGS=-O3  -fPIC)
	cd zlib-1.2.3
	./configure
	make&&make install
4、安装libpng(png格式图片)
	cd libpng-1.2.31
	./configure --prefix=/usr/local/libpng/
	make&&make install
5、安装jpeg(jpeg格式图片)
	先创建目录:
	mkdir /usr/local/jpeg6  
	mkdir /usr/local/jpeg6/bin  
	mkdir /usr/local/jpeg6/lib  
	mkdir /usr/local/jpeg6/include  
	mkdir -p /usr/local/jpeg6/man/man1
	cd jpeg-6b/
	./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
	make&&make install
6、安装freetype(自由字体)
	cd freetype-2.4.0
	./configure --prefix=/usr/local/freetype/
	make&&make install
***安装时可能会报错。是因为libtool版本太低,所以下载最新版本:
       cd libtool-2.2.6
       ./configure
       make
       make install
然后进行下面两步;最后返回再编译安装,就没有报错了。
       cp /usr/local/share/libtool/config.sub ./
       cp /usr/local/share/libtool/config.guess ./ 
7、安装autoconf
	cd autoconf-2.61
	./configure  
	make&&make install
8、安装gd(安装最新版本)
	cd gd-2.1.0
	./configure --prefix=/usr/local/gd/ --with-png=/usr/local/libpng --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
	make&&make install
9、安装php:
        ./configure --prefix=/usr/local/php/ \
        --with-config-file-path=/usr/local/php/etc/ \
        --with-apxs2=/usr/local/apache/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/gd \
        --with-mcrypt=/usr/local/libmcrypt  \
        --enable-soap  \
        --enable-mbstring=all \
        --enable-sockets
        若出现***-deve直接用yum install 安装
        make&&make install
10、配置文件
        cp php.ini-development  /usr/local/php/etc/php.ini
        vim /etc/httpd/httpd.conf修改
        AddType application/x-httpd-php .php
        Directory  index.php
        vim /usr/local/apache/htdocs/index.html
        <?php
        phpinfo();
        ?>;
        在浏览器中http://localhost/index.php出现PHP版本介绍安装成功



(configure,用来生成 Makefile,为下一步的编译做准备,后加上参数来对安装进行控制;./configure    --prefix=/usr/local/libxml2/       指定安装位置;make 是一个命令工具,它解释 Makefile 中的指令(应该说是规则);make 是编译过程,make install 是安装过程。--enable-static    #生成静态链接库     --enable-shared    #生成动态链接库,可以共享 make&&make install(--with-jpeg
     #该软件依赖的程序或库,指定jpeg的程序路径)
补:安装mysql5.6以上版本
        新增mysql用户和用户组:
        groupadd mysql
        useradd -r -g mysql mysql
        新建目录和数据库目录
        mkdir -p /usr/local/mysql
        mkdir -p /usr/local/mysql/data
        mysql 5.6以上的版本要用cmake安装
        cmake要下载安装 或者 yum install cmake
        ./configure --prefix=/usr/local/cmake
        make&&make  install

        cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_USER=mysql 
        make&&make install 
        使用脚本安装
        cd /usr/local/mysql
        scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql  
        cp support-files/my-medium.cnf  /usr/local/mysql/my.cnf  复制配置文件
        chown -R mysql:mysql /usr/local/mysql   更改权限
        cp support-files/mysql.server /etc/init.d/mysqld   
        chmod 755 /etc/init.d/mysqld
      
        将mysql加入PATH路径
        vim /etc/profile   
              PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH  
              export PATH 
        source /etc/profile
        service mysqld start能启动就安装好了
        设置开机启动chkconfig mysqld on
这一路编译确实不是很容易,但是学到了很多。。。。。。。多谢:参考http://blog.csdn.net/ihelloworld/article/details/7003394

posted @ 2015-07-24 17:22  ImLiFeLong  阅读(101)  评论(0编辑  收藏  举报