重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本文小编为大家详细介绍“64位CentOS6.0下怎么搭建LAMP环境”,内容详细,步骤清晰,细节处理妥当,希望这篇“64位CentOS6.0下怎么搭建LAMP环境”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
衡水ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:028-86922220(备注:SSL证书合作)期待与您的合作!1、确认搭建lamp所需要的环境是否已经安装
[root@centos6 ~]# rpm -q make gcc gcc-c++ zlib-devel libaio
备注:安装libpng时候需要zlib-devel
安装mysql时候需要libaio
2、如果没安装则yum安装
[root@centos6 ~]# yum install make gcc gcc-c++ zlib-devel libaio -y
3、由于要使用编译安装,所以查看httpd、mysql、php是否安装,如果安装则卸载
[root@centos6 ~]# rpm -q httpd mysql php
4、编译安装libxml2
注:libxml2是一个xml的c语言版的解析器,不仅支持c语言,还支持c++、php、pascal、ruby、tcl等语言的绑定
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf libxml2-2.7.8.tar.gz
[root@centos6 lamp]# cd ./libxml2-2.7.8
[root@centos6 libxml2-2.7.8]# ./configure --prefix=/usr/local/libxml2/
[root@centos6 libxml2-2.7.8]# make;make install
5、编译安装libmcrypt
注:libmcrypt是加密算法扩展库。支持des, 3des, rijndael, twofish, idea, gost, cast-256, arcfour, serpent, safer+等算法。
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf libmcrypt-2.5.8.tar.gz
[root@centos6 lamp]# cd ./libmcrypt-2.5.8
[root@centos6 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/
[root@centos6 libmcrypt-2.5.8]# make;make install
6、编译安装zlib
注:zlib是提供数据压缩用的函式库
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf zlib-1.2.5.tar.gz
[root@centos6 lamp]# cd ./zlib-1.2.5
[root@centos6 zlib-1.2.5]# ./configure --prefix=/usr/local/zlib/
[root@centos6 zlib-1.2.5]# make ; make install
7、编译安装libpng
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf libpng-1.5.4.tar.gz
[root@centos6 lamp]# cd ./libpng-1.5.4
[root@centos6 libpng-1.5.4]#
./configure --prefix=/usr/local/libpng/ --enable-shared
[root@centos6 libpng-1.5.4]# make ; make install
8、编译安装jpeg
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf jpegsrc.v8c.tar.gz
[root@centos6 lamp]# cd ./jpeg-8c/
[root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/(创建jpeg软件的安装目录)
[root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/bin/(创建存放命令的目录)
[root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/lib/(创建jpeg库文件所在目录)
[root@centos6 jpeg-8c]# mkdir /usr/local/jpeg/include/(创建存放头文件目录)
[root@centos6 jpeg-8c]# mkdir -p /usr/local/jpeg/man/man1(建立存放手册的目录)
[root@centos6 jpeg-8c]#
./configure --prefix=/usr/local/jpeg/ --enable-shared --enable-static(建立共享库使用的gnu的libtool和静态库使用的gnu的libtool)
[root@centos6 jpeg-8c]# make ; make install
9、编译安装freetype
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf freetype-2.4.6.tar.gz
[root@centos6 lamp]# cd ./freetype-2.4.6
[root@centos6 freetype-2.4.6]#
./configure --prefix=/usr/local/freetype/ --enable-shared
[root@centos6 freetype-2.4.6]# make ;make install
10、 编译安装autoconf
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf autoconf-2.68.tar.gz
[root@centos6 lamp]# cd ./autoconf-2.68
[root@centos6 autoconf-2.68]# ./configure
[root@centos6 autoconf-2.68]# make ; make install
11、 编译安装gd
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf gd-2.0.35.tar.gz
[root@centos6 lamp]# cd ./gd-2.0.35
[root@centos6 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/
[root@centos6 gd-2.0.35]# make ; make install
12、 安装apache
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf httpd-2.2.19.tar.gz
[root@centos6 lamp]# cd ./httpd-2.2.19
[root@centos6 httpd-2.2.19]#
./configure --prefix=/usr/local/apache/ --enable-so --enable-rewrite
[root@centos6 httpd-2.2.19]# make ; make install
[root@centos6 lamp]# /usr/local/apache/bin/apachectl start
[root@centos6 lamp]#
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
[root@centos6 lamp]# chmod +x /etc/init.d/httpd
[root@centos6 ~]# 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
[root@centos6 ~]# chkconfig --level 2345 httpd on
[root@centos6 lamp]# service httpd restart
开机自动启动apache的另一种方法:
修改/etc/rc.local文件
# vim /etc/rc.local
在文件中添加/usr/local/apache/bin/apachectl start
13、 编译安装mysql
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf mysql-5.5.15-linux2.6-x86_64.tar.gz
[root@centos6 lamp]# cd ./mysql-5.5.15-linux2.6-x86_64
[root@centos6 mysql-5.5.15-linux2.6-x86_64]# groupadd mysql
[root@centos6 mysql-5.5.15-linux2.6-x86_64]# useradd -r -g mysql mysql(创建mysql用户,并将用户指定至mysql组)
[root@centos6 mysql-5.5.15-linux2.6-x86_64]# cd /usr/local/
[root@centos6 local]# ln -s /tmp/lamp/mysql-5.5.15-linux2.6-x86_64 mysql
[root@centos6 local]# cd ./mysql/
[root@centos6 mysql]# chown -r mysql .(将该目录的用户权限全部更改为mysql用户)
[root@centos6 mysql]# chgrp -r mysql .(将该目录的用户组全部改为mysql用户组)
[root@centos6 mysql]# ./scripts/mysql_install_db --user=mysql(将mysql目录的数据库使用权限指定为mysql)
[root@centos6 mysql]# chown -r root .
[root@centos6 mysql]# chown -r mysql data
[root@centos6 mysql]# cp support-files/my-medium.cnf /etc/my.cnf(将当前目录下的配置文件拷贝到系统配置文件下,并更名为my.cnf)
[root@centos6 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@centos6 mysql]# chmod +x /etc/init.d/mysqld
[root@centos6 mysql]# chkconfig --add mysqld
[root@centos6 mysql]# chkconfig --level 345 mysqld on
[root@centos6 mysql]# service mysqld restart
[root@centos6 mysql]#
/usr/local/mysql/bin/mysqladmin -u root password '123456'(设置root用户登录mysql的密码)
[root@centos6 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 2
server 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 its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or 'h' for help. type 'c' to clear the current input statement.
mysql>(成功登录mysql)
14、 编译安装php
[root@centos6 lamp]# pwd
/tmp/lamp
[root@centos6 lamp]# tar -zxvf php-5.3.7.tar.gz
[root@centos6 lamp]# cd ./php-5.3.7
[root@centos6 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
[root@centos6 php-5.3.7]# make ; make install
[root@centos6 php-5.3.7]#
cp php.ini-development /usr/local/php/lib/php.ini
#vim /usr/local/php/lib/php.ini
//这里需要将register_globals=off更改on模式,还有时间格式改为本地
15、 更改apache的配置文件,达到解析php文件的目的
[root@centos6 ~]# 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、 验证
[root@centos6 ~]# vim /usr/local/apache/htdocs/index.php
添加内容为
echo phpinfo();
?>
读到这里,这篇“64位CentOS6.0下怎么搭建LAMP环境”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注创新互联行业资讯频道。