nainai1 发表于 2015-11-15 15:25:04

CentOS 6.0下搭建LAMP环境详细步骤

1、确认搭建LAMP所需要的环境是否已经安装
# rpm -q make gcc gcc-c++ zlib-devel libaio备注:安装libpng时候需要zlib-devel             安装mysql时候需要libaio2、如果没安装则yum安装# yum install make gcc gcc-c++ zlib-devel libaio -y3、由于要使用编译安装,所以查看httpd、mysql、php是否安装,如果安装则卸载# rpm -q httpd mysql php //查看是否安装卸载的方法: netatat -tnl //查看是否开启80端口
         rpm -e httpd-2.* //卸载httpd,如果有连带关系,加上 --nodeps 强制卸载

4、编译安装libxml2注:libxml2是一个xml的c语言版的解析器,不仅支持c语言,还支持c&#43;&#43;、php、Pascal、Ruby、Tcl等语言的绑定# pwd/tmp/LAMP# tar -zxvf libxml2-2.7.8.tar.gz# cd ./libxml2-2.7.8# ./configure--prefix=/usr/local/libxml2/# make;make install5、编译安装libmcrypt注:libmcrypt是加密算法扩展库。支持DES, 3DES, RIJNDAEL, Twofish, IDEA, GOST, CAST-256,ARCFOUR, SERPENT, SAFER&#43;等算法。# pwd/tmp/LAMP# tar -zxvf libmcrypt-2.5.8.tar.gz# cd ./libmcrypt-2.5.8# ./configure--prefix=/usr/local/libmcrypt/# make;make install6、编译安装zlib注:zlib是提供数据压缩用的函式库# pwd/tmp/LAMP# tar -zxvf zlib-1.2.5.tar.gz# cd ./zlib-1.2.5# ./configure--prefix=/usr/local/zlib/# make ; make install7、编译安装libpng# pwd/tmp/LAMP# tar -zxvf libpng-1.5.4.tar.gz# cd ./libpng-1.5.4#./configure --prefix=/usr/local/libpng/--enable-shared# make ; make install8、编译安装jpeg# pwd/tmp/LAMP# tar -zxvf jpegsrc.v8c.tar.gz# cd ./jpeg-8c/# mkdir /usr/local/jpeg/(创建jpeg软件的安装目录)# mkdir /usr/local/jpeg/bin/(创建存放命令的目录)# mkdir /usr/local/jpeg/lib/(创建jpeg库文件所在目录)# mkdir /usr/local/jpeg/include/(创建存放头文件目录)# mkdir -p /usr/local/jpeg/man/man1(建立存放手册的目录)# ./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static(建立共享库使用的GNU的libtool和静态库使用的GNU的libtool)# make ; make install9、编译安装freetype# pwd/tmp/LAMP# tar -zxvf freetype-2.4.6.tar.gz# cd ./freetype-2.4.6# ./configure --prefix=/usr/local/freetype/ --enable-shared# make ;make install10、      编译安装autoconf# pwd/tmp/LAMP# tar -zxvf autoconf-2.68.tar.gz# cd ./autoconf-2.68# ./configure# make ; make install11、      编译安装GD# pwd/tmp/LAMP# tar -zxvf gd-2.0.35.tar.gz# cd ./gd-2.0.35# ./configure --prefix=/usr/local/gd/ --with-zlib=/usr/local/zlib/ --with-jpeg=/usr/local/jpeg/ --with-png=/usr/local/libpng/ --with-freetype=/usr/local/freetype/# make ; make install12、      安装apache# pwd/tmp/LAMP# tar -zxvf httpd-2.2.19.tar.gz# cd ./httpd-2.2.19# ./configure --prefix=/usr/local/apache/ --enable-so --enable-rewrite# make ; make install# /usr/local/apache/bin/apachectl start#cp /usr/local/apache/bin/apachectl /etc/init.d/httpd# chmod &#43;x /etc/init.d/httpd# chkconfig --add httpd注意:如果提示service httpd does not support chkconfig错误解决办法:编辑/etc/rc.d/init.d/httpd在文件第二行加入         #chkconfig:2345 10 90         #description:Activates/Deactivates Apache Web Server# chkconfig --level 2345 httpd on# service httpd restart开机自动启动apache的另一种方法:修改/etc/rc.local文件# vim /etc/rc.local在文件中添加/usr/local/apache/bin/apachectl start13、      编译安装mysql# pwd/tmp/LAMP# tar -zxvf mysql-5.5.15-linux2.6-x86_64.tar.gz# cd ./mysql-5.5.15-linux2.6-x86_64# groupadd mysql# useradd -r -g mysql mysql(创建mysql用户,并将用户指定至mysql组)# cd /usr/local/# ln -s /tmp/LAMP/mysql-5.5.15-linux2.6-x86_64 mysql# cd ./mysql/# chown -R mysql .(将该目录的用户权限全部更改为mysql用户)# chgrp -R mysql .(将该目录的用户组全部改为mysql用户组)# ./scripts/mysql_install_db --user=mysql(将mysql目录的数据库使用权限指定为mysql)# chown -R root .# chown -R mysql data# cp support-files/my-medium.cnf/etc/my.cnf(将当前目录下的配置文件拷贝到系统配置文件下,并更名为my.cnf)# cp support-files/mysql.server/etc/init.d/mysqld# chmod &#43;x /etc/init.d/mysqld# chkconfig --add mysqld# chkconfig --level 345 mysqld on# service mysqld restart# /usr/local/mysql/bin/mysqladmin -u root password '123456'(设置root用户登录mysql的密码)# /usr/local/mysql/bin/mysql -u root –p(进入并访问mysql数据)Enter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 2Server version: 5.5.15-log MySQL Community Server (GPL)Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.mysql>(成功登录mysql)14、      编译安装php# pwd/tmp/LAMP# tar -zxvf php-5.3.7.tar.gz# cd ./php-5.3.7#./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg/ --with-freetype-dir=/usr/local/freetype/--with-gd-dir=/usr/local/gd/--with-zlib-dir=/usr/local/zlib/--with-mcrypt=/usr/local/libmcrypt/--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-soap --enable-mbstring=all --enable-sockets# make ; make install# cp php.ini-development /usr/local/php/lib/php.ini#vim /usr/local/php/lib/php.ini //这里需要将register_globals=Off更改on模式,还有时间格式改为本地15、      更改apache的配置文件,达到解析php文件的目的    # vim /usr/local/apache/conf/httpd.conf AddType application/x-compress .Z AddType application/x-gzip .gz .tgz Addtype application/x-httpd-php .php .phtml   Addtype application/x-httpd-php-source .phps添加上面绿色内容,表示apache服务中可以解析php格式文件接下来要检查apache目录下生成的php动态连接库文件,在目录/usr/local/apache/modules,找到是否存在 libphp5.so文件16、   验证   # vim /usr/local/apache/htdocs/index.php   添加内容为<?php    echo phpinfo();?>在客服端验证,出现下图说明php搭建成功         版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: CentOS 6.0下搭建LAMP环境详细步骤