在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

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

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