您的位置:首页 > 运维架构 > Linux

CentOS6.5-x86_64平台LAMP配置

2014-12-30 00:44 405 查看
一、LAMP简介
LAMP是一组用来构建动态网站的免费开源的软件,其中:
L(Linux):是一个开源的操作系统;
A(Apache):是一个开源的Web应用软件;
M(Mysql):是一个开源的数据库管理系统软件;
P(PHP/Perl/Python):是用来执行Web动态请求的开源工具,本文中是用的是PHP。
二、安装前的工作
1、安装最基本的编译工具gcc、gcc-c++
# yum -y install gcc gcc-c++
2、清空iptables的规则链,以防导致有些服务无法访问
# iptables -F
# iptables -X
# iptables -Z
# service iptables save
3、调整selinux到premissive或者disable
# setenforce 0
# sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
三、编译安装Apache
首先安装apr、apr-util,apr是可移植运行库,目的是为大多数的平台提供一个公共的统一的操作函数接口。
1、下载apr-1.5.1.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.1.tar.gz

2、下载apr-util-1.5.4.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz

3、编译安装apr-1.5.1.tar.gz、apr-util-1.5.4.tar.gz
(1)编译安装apr

# tar xf apr-1.5.1.tar.gz

# cd apr-1.5.1
# ./configure --prefix=/usr/local/apr #指定安装目录为/usr/local/apr
如果出现如下错误:
config.status: executing libtool commands
rm: cannot remove `libtoolT': No such file or directory
解决办法:
打开 configure,把 $RM “$cfgfile”那行删除掉,重新再运行 ./configure --prefix=/usr /local/apr
# make ; make install
(2)编译安装apr-util

# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make ; make install
(3)编译安装apache
下载httpd-2.4.10.tar.gz
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.gz
# tar xf httpd-2.4.10.tar.gz
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-modules=all \
--enable-cache=static \
--enable-file-cache=static \
--enable-cache-disk=static \
--enable-ssl=static \
--enable-so
编译参数说明:
--enable-modules=all #指定静态编译所有模块
--enable-mods-shared=all #指定动态编译所有模块
--enable-cache=static #指定静态编译该模块
--enable-so #动态加载选项,表示可以在配置文件中动态加载自己编译的模块
注意:当--enable-modules=all和--enable-mods-shared=all两个参数都存在的时候,除非以
--enable-[module]=static的方式特别指定为静态编译,否则所有模块都会以动态编译。
如果出现如下错误:
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
因为Apache的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法。需要安装两个安装包pcre
和pcre-devel。第一个安装包提供编译版本的库,而第二个提供开发阶段的头文件和编译项目的源
代码。

解决办法:
# yum -y install pcre pcre-devel
或者下载pcre-8.34.tar.gz源码包编译安装
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
如果出现如下错误:
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures

解决办法:
# yum install openssl-devel

解决完所有的依赖关系后重新执行上述./configure,参数同上,然后
# make ; make install
(4)验证Web服务
执行如下命令启动Web服务:
# /usr/local/apache/bin/apachectl start
# echo "export PATH=$PATH:/usr/local/apache/bin" >> ~/.bashrc #修改PATH变量,将 apachectl的路径包含进PATH中
# source ~/.bashrc #重新读取~/.bashrc
# apachectl restart #成功
也可以执行如下方法启动:
# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
# chmod +x /etc/init.d/httpd
# vim /etc/init.d/httpd #编辑该文件加入高亮显示的两行文件
#!/bin/sh
#
# chkconfig: 345 10 90
# description: Activates/Deactivates Apache Web Server.
# Licensed to the Apache Software Foundation (ASF) under one or more
# service httpd restart #既可用此方法控制http服务

执行如下命令验证Web服务是否成功启动:
# netstat -tnlp | grep ":80"
tcp 0 0 :::80 :::* LISTEN 57802/httpd
本机访问Web服务:
# curl http://127.0.0.1

<html><body><h1>It works!</h1></body></html>
至此Apache编译安装完成。
四、编译安装Mysql
本次安装使用Mysql的通用二进制格式包安装 mysql-5.5.41-linux2.6-x86_64.tar.gz
安装前先安装libaio和libaio-devel两个包,libaio是Linux下的一个异步非阻塞接口,它提供了异 步非阻塞方式来读写文件的方式,读写效率比较高,Mysql依赖这两个包。 # yum install libaio libaio-devel 安装Mysql: # tar xf mysql-5.5.41-linux2.6-x86_64.tar.gz -C /usr/local/ # cd /usr/local # ln -s mysql-5.5.41-linux2.6-x86_64/ mysql # groupadd -g 306 mysql #创建mysql组,指定GID为306
# useradd -r -u 306 -g 306 mysql #创建mysql账号,指定UID也为306 # cd mysql #切换到mysql目录
# chown -R mysql.mysql . #将目录中所有文件的属主属组改为mysql
# ./scripts/mysql_install_db --user=mysql #以mysql的身份初始化mysql # chown -R root.mysql . #将目录中所有文件的属主改为root # chown -R mysql data/ #将数据库目录属主改为mysql # cp ./support-files/my-large.cnf /etc/my.cnf #拷贝主配置文件到/etc下命名为my.cnf # ./bin/mysqld_safe --user=mysql & # cp ./support-files/mysql.server /etc/init.d/mysqld #拷贝控制脚本到/etc/init.d下 # service mysqld restart #重启mysql # netstat -tnlp | grep ":3306" #检查mysql是否启动 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 60458/mysqld # /usr/local/mysql/bin/mysqladmin -u root password "123456" #创建管理员账号 安装mysql是可以参考mysql源文件目录中的INSTALL-BINARY文件 至此mysql安装完毕五、编译安装PHP 安装PHP需要依赖gd、libmcrypt、libxml2,而gd需要依赖libpng、jpeg、libXpm、freetype、 zlib、fontconfig所以 需要先安装libpng、jpeg、freetype、fontconfig、zlib、libXpm等软件包,在此使用yum安装: # yum -y install libpng libpng-devel #gd库的png支持(图片显示) # yum -y install zlib zlib-devel #支持zlib(压缩和解压缩) # yum -y install freetype freetype-devel #freetype支持(字体) # yum -y install jpeg jpge-devel #gd库的jpeg支持(图片显示) # yum install fontconfig fontconfig-devel #gd库的fontconfig(字体相关的程序库) # yum install libXpm libXpm-devel #gd库的Xpm支持(图片显示) 1、编译安装gd # ./configure --prefix=/usr/local/gd \ --with-png \ --with-freetype \ --with-jpeg \ --with-fontconfig \ --with-Xpm # make ; make install 2、安装libxml2 # yum install libxml2 libxml2-devel #解析XML文档的函数库 3、安装libmcrypt 下载libmcrypt-2.5.7.tar.gz wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
# tar xf libmcrypt-2.5.7.tar.gz
# cd libmcrypt-2.5.7 # ./configure --prefix=/usr/local/libmcrypt # make ; make install 4、编译安装PHP (1)下载php-5.6.4.tar.gz wget http://cn2.php.net/get/php-5.6.4.tar.gz/from/this/mirror
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-libxml-dir \
--with-openssl \
--with-zlib-dir \
--with-pcre-dir \
--with-gd \ --with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-xpm-dir \
--with-freetype-dir \
--enable-mbstring \
--with-mcrypt=/usr/local/libmcrypt \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-soap \
--enable-sockets \ 部分配置选项说明: --with-apxs2=/usr/local/apache/bin/apxs
apxs功能是使用mod_so中的LoadModule指令,加载指定模块到apache,要求apache要打开 --enable-so模块 --with-config-file-path=/etc #配置文件路径,指定php.ini文件 --with-config-file-scan-dir=/etc/php.d #php其它配置文件的存放路径
--with-mysqli=/usr/local/mysql/bin/mysql_config #mysqli文件路径,优化支持 --enable-mbstring #多字节,字符串的支持 --enable-sockets #打开套接字的支持 --enable-soap #打开soap协议的支持 # make ; make install # cp php.ini-production /etc/php.ini #拷贝配置文件到/etc下,命名为php.ini # mkdir /etc/php.d #创建php其它配置文件的目录 (2)更改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
AddType application/x-httpd-php-source .phps 找到如下行: DirectoryIndex index.html 修改为: DirectoryIndex index.html index.php 保存退出。 重启Web服务: # service httpd restart 编辑/usr/local/apache/htdocs/index.html,增加如下内容,并重命名为index.php # vim /usr/local/apache/htdocs/index.html <?php phpinfo(); ?> # mv /usr/local/apache/htdocs/index.html /usr/local/apache/htdocs/index.php 客户端验证,出现下图,则配置成功。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: