你好,游客 登录 注册 搜索
背景:
阅读新闻

在CentOS6.5系统下编译安装LAMP(httpd2.4+MySQL5.6+PHP5.4)

[日期:2016-06-13] 来源:Linux社区  作者:Linux [字体: ]

什么是LAMP
LAMP指的是Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案。

需要的源码包到Linux公社1号FTP服务器下载

------------------------------------------分割线------------------------------------------

FTP地址:ftp://ftp1.linuxidc.com

用户名:ftp1.linuxidc.com

密码:www.linuxidc.com

在 2016年LinuxIDC.com\6月\在CentOS6.5系统下编译安装LAMP(httpd2.4+MySQL5.6+PHP5.4)\

下载方法见 http://www.linuxidc.com/Linux/2013-10/91140.htm

------------------------------------------分割线------------------------------------------

开始安装httpd

#安装前准备
yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel
 
#解压
tar zxvf apr-1.5.0.tar.gz
tar zxvf apr-util-1.5.3.tar.gz
tar zxvf httpd-2.4.7.tar.gz
 
#改名
mv apr-1.5.0 apr
mv apr-util-1.5.3 apr-util
 
#移动
mv apr apr-util httpd-2.4.7/srclib/
 
#进入httpd目录
cd httpd-2.4.7
 
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --with-z --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support --enable-authn-dbm=shared --enable-cache --enable-file-cache --enable-mem-cache --enable-disk-cache --enable-mods-shared=all --enable-ssl --enable-cgi
 
#编译安装httpd2.4
make && make install
 
#编辑httpd.conf
vi /etc/httpd/httpd.conf
 
#找到下面这句
#ServerName www.example.com:80
 
#改成
ServerName localhost:80
 
#iptables添加80端口
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80-j ACCEPT
 
#重启iptables
service iptables restart
 
####################################启动脚本开始######################################################
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: 2345 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server
# implementing the current HTTP standards.
### END INIT INFO
 
# Source function library.
./etc/rc.d/init.d/functions
 
if[-f /etc/sysconfig/httpd ];then
./etc/sysconfig/httpd
fi
 
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
 
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
 
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
 
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
 
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure. So we just do it the way init scripts
# are expected to behave here.
start(){
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL =0]&& touch ${lockfile}
return $RETVAL
}
 
# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
# httpd parent to SIGKILL any errant children.
stop(){
echo -n $"Stopping $prog: "
killproc -p ${pidfile}-d ${STOP_TIMEOUT} $httpd
RETVAL=$?
echo
[ $RETVAL =0]&& rm -f ${lockfile} ${pidfile}
}
reload(){
echo -n $"Reloading $prog: "
if! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null;then
RETVAL=6
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
# Force LSB behaviour from killproc
LSB=1 killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
if[ $RETVAL -eq 7];then
failure $"httpd shutdown"
fi
fi
echo
}
 
# See how we were called.
case"$1"in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $httpd >&/dev/null;then
stop
start
fi
;;
force-reload|reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
RETVAL=2
esac
 
exit $RETVAL
#######################################启动脚本结束#####################################################
 
#把上面的启动脚本添加到/etc/init.d
vi /etc/init.d/httpd
 
#赋予执行权限
chmod 755/etc/init.d/httpd
 
#设置环境变量
vi /etc/profile
 
#在末尾添加以下内容
PATH=/usr/local/apache/bin:$PATH
export PATH
 
#让刚才的修改生效
source /etc/profile
 
#启动httpd
service httpd start
 
#开机启动
chkconfig httpd on
开始安装mysql

#解压mysql
tar zxvf mysql-5.6.16.tar.gz
 
#进入mysql目录
cd mysql-5.6.16
 
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql_data -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
 
#编译安装mysql5.6
make && make install
 
#新建一个mysql用户
useradd -s /sbin/nologin mysql
 
#新建一个数据目录
mkdir -p /data/mysql_data
 
#赋予权限
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql_data
 
#进入到mysql安装目录
cd /usr/local/mysql/scripts/
 
#执行以下命令,初始化数据库
./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql_data --user=mysql
 
#在CentOS6.5系统的最小安装完成后,在/etc目录下会存在一个my.cnf,需要将此文件更名为其他的名字,如:/etc/my.cnf.old,否则,该文件会干扰源码安装的MySQL的正确配置,造成无法启动。
mv /etc/my.cnf /etc/my.cnf.old
 
#复制我们需要的my.cnf到etc下
cp /usr/local/mysql/my.cnf /etc/
 
#复制启动脚本到/etc/init.d
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
 
#iptables添加3306端口
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306-j ACCEPT
 
#重启iptables
service iptables restart
 
#启动mysql
service mysqld start
 
#开机启动mysql
chkconfig mysqld on
 
#设置环境变量
vi /etc/profile
 
#在末尾添加以下内容
PATH=/usr/local/mysql/bin:$PATH
export PATH
 
#让刚才的修改生效
source /etc/profile
 
#初始化mysql的一些设置
mysql_secure_installation
 
#回车
Enter current password for root (enter for none):
 
#y,设置mysql的root密码
Set root password?[Y/n] y
 
#以下都yes
Remove anonymous users?[Y/n] y
Disallow root login remotely?[Y/n] y
Remove test database and access to it?[Y/n] y
Reload privilege tables now?[Y/n] y
 
ThanksforusingMySQL!
开始安装php

#解压php
tar zxvf php-5.4.25.tar.gz
 
#进入解压出来的php目录
cd php-5.4.25
 
./configure --prefix=/usr/local/php --with-config-file-path=/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql --with-mysqli --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-gd --with-zlib-dir --with-mcrypt --enable-soap --enable-mbstring=all --enable-sockets --enable-ftp --enable-zip --with-gettext
 
#编译安装php5.4
make && make install
 
#设置环境变量
vi /etc/profile
 
#在末尾添加以下内容
PATH=/usr/local/php/bin:$PATH
export PATH
 
#让刚才的修改生效
source /etc/profile
 
#复制配置文件到etc目录
cp /usr/src/php-5.4.25/php.ini-production /etc/php.ini
 
#修改默认时区
vi /etc/php.ini
date.timezone =Asia/Shanghai
 
#让httpd支持php解析
vi /etc/httpd/httpd.conf
 
#找到这行
AddType application/x-gzip .gz .tgz
 
#添加这一句
AddType application/x-httpd-php .php
 
#找到以下这句,在后面添加index.php
DirectoryIndex index.html
 
DirectoryIndex index.html index.php
 
#最后添加一个测试文件到/usr/local/apache/htdocs/phpinfo.php,看看httpd能否输出php页面
如果能看到以下页面,说明你的lamp环境已经好了。

到此,整个lamp环境就编译安装完成了。

下面关于LAMP相关的内容你可能也喜欢

LAMP平台安装Xcache和Memcached加速网站运行  http://www.linuxidc.com/Linux/2015-06/118835.htm 

CentOS 7下搭建LAMP平台环境  http://www.linuxidc.com/Linux/2015-06/118818.htm

CentOS 6.5系统安装配置LAMP(Apache+PHP5+MySQL)服务器环境 http://www.linuxidc.com/Linux/2014-12/111030.htm

Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境  http://www.linuxidc.com/Linux/2014-10/107924.htm

Ubuntu 14.10 下安装 LAMP 服务图文详解  http://www.linuxidc.com/Linux/2014-12/110082.htm

LAMP结合NFS构建小型博客站点  http://www.linuxidc.com/Linux/2015-08/121029.htm

CentOS7下安装部署LAMP环境  http://www.linuxidc.com/Linux/2016-04/130653.htm

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-06/132271.htm

linux
相关资讯       编译安装LAMP 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款