LAMP组合的编译安装(apache2.4+mariadb5.5+php5.6)

安装次序

httpd, MariaDB, php

安装apache2.4

[root@root ~]# yum groupinstall "Development Tools" "Server Platform Develoment
" –y
#安装开发环境
[root@root ~]# yum install pcre-devel –y
#安装pcre
[root@root ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz
#下载apr
[root@root ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
#下载apr-util
[root@root ~]# ls
anaconda-ks.cfg apr-util-1.5.4.tar.gz install.log.syslog
apr-1.5.2.tar.gz install.log
[root@root ~]# tar -xf apr-1.5.2.tar.gz
#安装apr
[root@root ~]# cd apr-1.5.2
[root@root apr-1.5.2]# ./configure --prefix=/usr/local/apr
#为避免覆盖1.3.9版本的apr,我们选择新的路径进行安装
[root@root ~]# tar -xf apr-util-1.5.4.tar.gz
#安装apr-util
[root@root ~]# cd apr-util-1.5.4
[root@root apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr
=/usr/local/apr
#针对于apr做编译
[root@root apr-util-1.5.4]# make && make install
[root@root ~]# groupadd -r apache
[root@root ~]# useradd -r -g apache apache
#添加系统用户和系统组apache
[root@root ~]# yum install pcre-devel–y
#在编译httpd2.4前需要安装pcre
[root@root ~]# wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.20.tar.g
z
#下载httpd2.4
[root@root ~]# tar -xvf httpd-2.4.20.tar.gz
[root@root ~]# cd httpd-2.4.20
[root@root httpd-2.4.20]# ./configure --prefix=/usr/local/apache --sysconf=/etc
/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --w
ith-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enabl
e-modules=most --enable-mpms-shared=all --with-mpm=prefork

涉及到以下参数

--prefix=/usr/local/apache2.4.9 #应用程序安装路径
--sysconfdir=/etc/httpd #配置文件的安装路径
--enable-so #支持DSO动态装载模块
--enable-ssl #要编译启用ssl模块(前提是需要安装openssl-devel)
--enable-cgi #启用CGI模块(默认就启用)
--enable-rewrite #URL重写(把用户访问的URL由服务器自动的改成另外一个URL,
#这是一个非常有用的机制)
--with-zlib #这是一个压缩库(专用于网络传输)
--with-pcre #使用增强的perl正则表达式分析工具(使用这项需要安
#装pcre-devel,pcre:正则表达式分析器)
--with-apr=/usr/local/apr #指明apr的目录(若apr在特殊路径下)
--with-apr-util=/usr/local/apr-util/ #指明apr-util路径(若apr-util在特殊路径下
)
--enable-mpms-shared=all #把所有的mpm模块都编译进来而且是共享模块
--with-mpm=prefork #默认使用的mpm模块
--enable-modules=most(all) #还有很多其他模块,其他的动态可装载模块需要
#编译哪些
#(all:所有都编译,most:编译一些常用的模块)
[root@root httpd-2.4.20]#make && make install
[root@root ~]# /usr/local/apache/bin/apachectl -t
#检查apache主配置文件语法是否有错误
Syntax OK

查看httpd-2.4.20安装目录的内容

[root@Centos ~]# tree -d /usr/local/apache/
/usr/local/apache/
├── bin #存放启动或关闭httpd的脚本文件
├── build
├── cgi-bin #cgi程序文件的存放目录
├── error #发生服务器端错误时返回给客户端的错误页面
│ └── include
├── htdocs #Web页面所在的目录
├── icons #存放httpd的图标文件
│ └── small
├── include #存放头文件
├── logs #httpd的日志文件
├── man #帮助手册
│ ├── man1
│ └── man8
├── manual #httpd的配置手册
│ ├── developer
│ ├── faq
│ ├── howto
│ ├── images
│ ├── misc
│ ├── mod
│ ├── platform
│ ├── programs
│ ├── rewrite
│ ├── ssl
│ ├── style
│ │ ├── css
│ │ ├── lang
│ │ ├── latex
│ │ ├── scripts
│ │ └── xsl
│ │ └── util
│ └── vhosts
└── modules #存放httpd的模块

编译安装后的基本配置:

1.修改httpd的主配置文件,设置其Pid文件的路径:

vim /etc/httpd24/httpd.conf
ServerRoot "/usr/local/apache"
PidFile "/var/run/httpd.pid"
修改PAT H环境变量,让/usr/local/apache/bin目录下的命令都可以执行:
[root@root ~]# vim /etc/profile.d/httpd.sh
#必须要以.sh结尾,并且放在这里可以单独管理,不要的时候可以直接删除,添加如下内容
export PATH=/usr/local/apache/bin:$PATH
[root@root ~]# . /etc/profile.d/httpd.sh #source一下
[root@root ~]# httpd -t #检查是相关命令是否可用了
Syntax OK

2.导出头文件:

[root@root ~]# ln -sv /usr/local/apache/include/ /usr/local/include/httpd
`/usr/local/include/httpd' -> `/usr/local/apache/include/'

3.导出man手册(用vim编辑/etc/man.config):

MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
加上下面这一行
MANPATH /usr/local/apache/man

4.编写服务脚本(因是编译安装,不会自动生成服务脚本)并给其添加执行权限:(vim

/etc/rc.d/init.d/httpd)
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# 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-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
"/etc/rc.d/init.d/httpd" 86L, 2314C 31,1 Top
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# 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-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
"/etc/rc.d/init.d/httpd" 86L, 2314C 31,1 Top
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $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=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start;;
stop)
stop;;
status)
status -p ${pidfile} $httpd
33,5 61%
status)
status -p ${pidfile} $httpd
RETVAL=$?;;
restart)
stop
start;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi;;
reload)
reload;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatu
s
|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
apachectl=/usr/local/apache/bin/apachectl #需要注意这些路径
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}

5.启动服务并测试:

[root@root ~]#vi /etc/sysconfig/iptables #iptables添加80端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80-j ACCEPT
[root@root ~]# service httpd start

测试

1.png

6.设置开机启动:

[root@root ~]# chkconfig httpd on
[root@root ~]# chkconfig –list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

安装mariadb

[root@root ~]# groupadd -r mysql
[root@root ~]# useradd -r mysql -g mysql
[root@root ~]# id mysql
uid=496(mysql) gid=494(mysql) groups=494(mysql)
[root@root~]#wget https://downloads.mariadb.org/interstitial/mariadb-5.5.36/kvm
-bintar-centos5-amd64/mariadb-5.5.36-linux-x86_64.tar.gz/from/http%3A//archive.
mariadb.org/
[root@root]# tar -zxvf mariadb-5.5.36-linux-x86_64.tar.gz -C /usr/local
[root@root ~]# cd /usr/local
[root@root local]# ls
bin games include lib64 mariadb-5.5.36-linux-x86_64 share
etc gnupg lib libexec sbin src
[root@root local]# ln -sv mariadb-5.5.36-linux-x86_64 mysql
[root@root local]# ll
drwxr-xr-x. 13 root root 4096 May 13 06:53 mariadb-5.5.36-linux-x86_64
[root@root local]# cd mysql/
[root@root mysql]# chown -R root:mysql ./*
[root@root mysql]# ls scripts/
mysql_install_db
[root@root ~]# scripts/mysql_install_db --help
--basedir=path #mysql安装目录
--datadir=path #数据存放位置
--user=user_name #以哪个用户的身份安装
[root@root mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/mysq
l-data/

初始化mysql

[root@root mysql]# ls support-files/ #查看服务脚本mysql.serve
binary-configure magic my-medium.cnf mysql.server
config.huge.ini my-huge.cnf my-small.cnf ndb-config-2-no
de.ini
config.medium.ini my-innodb-heavy-4G.cnf mysqld_multi.server SELinux
config.small.ini my-large.cnf mysql-log-rotate solaris
[root@root mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
root@root mysql]# chkconfig --add mysqld
[root@root mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
root@root mysql]# mkdir /etc/mysql
[root@root mysql]# pwd
/usr/local/mysql
[root@root mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
[root@root mysql]# vim /etc/mysql/my.cnf
thread_concurrency = 8 #并行线程数,cpu*2
datadir=/mydata/mysql-data/ #修改data路径
innodb_file_per_table #暂不解释
skip_name_resolve = on #跳过名称反解,直接识别ip
[root@root mysql]# service mysqld start
Starting MySQL.. SUCCESS!
[root@root mysql]# ss -tnl
0 50 *:3306 *:* #3306端口处于监听状态

安装php

[root@root ~]# wget http://cn2.php.net/distributions/php-5.6.23.tar.gz
[root@root ~]# tar -zxvf php-5.6.23.tar.gz -C /usr/local/
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
#配置epel源
[root@root ~]# yum install bzip2-devel libmcrypt-devel libxml2-devel –y
[root@root ~]# cd /usr/local/php-5.6.23/
[root@root ~]#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openss
l --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-free
type-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --en
able-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcryp
t --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-b
z2 --enable-maintainer-zts
--enable-mbstring #多字节字符串支持
--with-freetype-dir #支持freetype字体格式
--with-jpeg-dir #支持jpeg图片格式
--with-png-dir #支持png图片格式
--enable-sockets #支持与sockets通信
--with-apxs2=/usr/local/apache/bin/apxs #把php编译成apache的模块
--with-mcrypt #支持加密解密库
--enable-maintainer-zts #编译成zts模块,event,worker模式使用
[root@root php-5.6.23]#make -j 4 && make install
[root@root php-5.6.23]# cp php.ini-production /etc/php.ini #为php提供配置文件
[root@root php-5.6.23]# cd /etc/httpd24/
[root@root httpd24]# cp httpd.conf {,.bak}
[root@root httpd24]# vim httpd.conf #编辑apache配置文件httpd.conf,使apache支持p
hp
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.php index.html #定位至DirectoryIndex index.html修改
[root@root httpd24]# service httpd restart
[root@root httpd24]# cd /usr/local/apache/
[root@root apache]# ls
bin build cgi-bin error htdocs icons include logs man manual modules
[root@root apache]# cd htdocs/
[root@root htdocs]# mv index.html index.php
[root@root htdocs]# vim index.php

2.png

测试

3.png

[root@root htdocs]# service mysqld stop

4.png

原创文章,作者:Net17_得得,如若转载,请注明出处:http://www.178linux.com/20830

(0)
上一篇 2016-06-29 14:29
下一篇 2016-06-29 14:29

相关推荐

  • xen虚拟机实时迁移

    前言:  xen虚拟机提供了一种类似于heartbeat高可用方案,在保证也不中断的业务情况下实现虚拟机迁移技术。在保证虚拟机上的服务正常的情况下将运行中的Domain迁移到其他机器上,实现xen虚拟机的高可用。 一、实验准备:  (1)各个测试机之间时间要同步  (2)node3提供iscsi网络共享存储  (4)n…

    Linux干货 2015-08-27
  • shell脚本编程基础

    shell脚本编程基础以及一些基本的逻辑运算知识和shell的配置用户环境。

    2017-11-26
  • shell脚本参数练习

    1、写一个脚本,判断当前系统上所有用户的shell是否为可登陆shell(即用户的shell不是/sbin/nologin),分别这两类用户的个数;通过字符串比较来实现; !/bin/bash # login_user=0 nologin_user=0 for i in $(cat /etc/passwd | cut -d : -f 7);do if [ $…

    2017-09-17
  • find查找命令及压缩

    文件查找     在文件系统上查找符合条件的文件;     文件查找: locate, find         非实时查找(数据库查找): locate    &nbs…

    Linux干货 2016-08-18
  • DNS服务器之理论基础

    一、什么是DNS     DNS全称为Domain Name System,即域名系统,其作用就是将我们经常使用的“网址”解析为IP地址。     在互联网上通信需要借助于IP地址,但人类对于数字的记忆能力远不如文字,那么将IP地址转换成容易记忆的文字是个好办法,可是计算机只能识…

    Linux干货 2015-04-29
  • 用户管理相关

    安全3A:     资源分配:       authentication:认证       authorization 授权       accouting|audition 审计 用户分为(centos7):   管理员:root 0 &…

    Linux干货 2017-02-25