阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

201次阅读
没有评论

共计 8137 个字符,预计需要花费 21 分钟才能阅读完成。

什么是 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 环境已经好了。

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

到此,整个 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

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计8137字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中