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

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

需要的源码包到主机宝贝1号FTP服务器下载

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

开始安装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相关的内容你可能也喜欢

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/222636.html<

(0)
运维的头像运维
上一篇2025-04-15 14:24
下一篇 2025-04-15 14:25

相关推荐

  • 个人主题怎么制作?

    制作个人主题是一个将个人风格、兴趣或专业领域转化为视觉化或结构化内容的过程,无论是用于个人博客、作品集、社交媒体账号还是品牌形象,核心都是围绕“个人特色”展开,以下从定位、内容规划、视觉设计、技术实现四个维度,详细拆解制作个人主题的完整流程,明确主题定位:找到个人特色的核心主题定位是所有工作的起点,需要先回答……

    2025-11-20
    0
  • 社群营销管理关键是什么?

    社群营销的核心在于通过建立有温度、有价值、有归属感的社群,实现用户留存、转化和品牌传播,其管理需贯穿“目标定位-内容运营-用户互动-数据驱动-风险控制”全流程,以下从五个维度展开详细说明:明确社群定位与目标社群管理的首要任务是精准定位,需明确社群的核心价值(如行业交流、产品使用指导、兴趣分享等)、目标用户画像……

    2025-11-20
    0
  • 香港公司网站备案需要什么材料?

    香港公司进行网站备案是一个涉及多部门协调、流程相对严谨的过程,尤其需兼顾中国内地与香港两地的监管要求,由于香港公司注册地与中国内地不同,其网站若主要服务内地用户或使用内地服务器,需根据服务器位置、网站内容性质等,选择对应的备案路径(如工信部ICP备案或公安备案),以下从备案主体资格、流程步骤、材料准备、注意事项……

    2025-11-20
    0
  • 如何企业上云推广

    企业上云已成为数字化转型的核心战略,但推广过程中需结合行业特性、企业痛点与市场需求,构建系统性、多维度的推广体系,以下从市场定位、策略设计、执行落地及效果优化四个维度,详细拆解企业上云推广的实践路径,精准定位:明确目标企业与核心价值企业上云并非“一刀切”的方案,需先锁定目标客户群体,提炼差异化价值主张,客户分层……

    2025-11-20
    0
  • PS设计搜索框的实用技巧有哪些?

    在PS中设计一个美观且功能性的搜索框需要结合创意构思、视觉设计和用户体验考量,以下从设计思路、制作步骤、细节优化及交互预览等方面详细说明,帮助打造符合需求的搜索框,设计前的规划明确使用场景:根据网站或APP的整体风格确定搜索框的调性,例如极简风适合细线条和纯色,科技感适合渐变和发光效果,电商类则可能需要突出搜索……

    2025-11-20
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注