设为首页 收藏本站
查看: 953|回复: 0

编译安装lamp

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-2-1 10:14:26 | 显示全部楼层 |阅读模式
编译安装软件需要安装开发环境,关闭iptables和selinux
1
# yum groupinstall "Development Tools"  "Server Platform Development"





一、编译安装httpd
httpd2.4需要apr、apr-util依赖包
1.编译安装apr、apr-util
1
2
3
4
5
6
7
8
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
# make && make install
# tar  xf apr-util-1.5.3.tar.bz2
# cd apr-util-1.5.3
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install




2.编译安装httpd
在安装之前需要安装pcre-devel包,因为在编译安装http时会安装pcre,这个包依赖于pcre-devel,系统自带没有pcre-devel这个包
1
2
3
4
5
# yum install pcre-devel
# tar xf httpd-2.4.10.tar.bz2  
# cd httpd-2.4.10
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install




3.启动httpd服务
编译安装的httpd自带有启动脚本:apachectl,所以执行/usr/local/apache/bin/apachectl命令即可启动httpd服务
直接使用apachectl命令需做一下步骤:
1
2
3
4
5
# vim /etc/profile.d/httpd.sh
# .  /etc/profile.d/httpd.sh
# echo $PATH
# cat   /etc/profile.d/httpd.sh
export PATH=/usr/local/apache/bin:$PATH




4.修改httpd的主配置文件 vim  /etc/httpd24/httpd.conf ,添加下行即可:
1
PidFile  "/var/run/httpd.pid"




5.将之前的httpd sysv服务脚本拷贝过来并修改配置文件中的以下数据:
1
2
3
4
5
cp /etc/rc.d/init.d/httpd   /etc/rc.d/init.d/httpd24
# pidfile: /var/run/httpd.pid
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/var/run/httpd.pid}




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/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
        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
  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|fullstatus|graceful|help|configtest}"
  exit 1
esac
  
exit $RETVAL





给脚本执行权限:
1
# chmod +x /etc/rc.d/init.d/httpd24





6.加入服务列表并启动服务:
1
2
3
4
# chkconfig --add httpd24
# chkconfig httpd24 on
# service httpd24 status
# service httpd24 start




二、编译安装mysql
1.新建一个lvm,然后将其挂载到数据库目录下:
1
2
3
4
5
6
7
8
9
# fdisk /dev/sda
# partx -a /dev/sda
# partx -a /dev/sda
# pvcreate /dev/sda5
# vgcreate myvg /dev/sda5
# lvcreate -L 5G -n mylv myvg
# mkfs.ext4 /dev/myvg/mylv
# mkdir -pv /mydata/data
# mount /dev/myvg/mylv /mydata/data




2.新建用户以安全方式运行
1
2
3
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql
# chown -R mysql:mysql /mydata/data




3.安装并初始化mysql
1
2
3
4
5
6
# tar xf mariadb-5.5.43-linux-x86_64.tar.gz  -C /usr/local
# cd /usr/local
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db  --datadir=/mydata/data/ --user=mysql     //初始化数据库




4.为数据库创建主配置文件
1
2
# mkdir /etc/mysql
# cp support-files/my-large.cnf  /etc/my.cnf




5.修改配置文件:添加如下几行,并修改此文件中thread_concurrency的值为你的CPU个数乘以2
1
2
3
datadir = /mydata/data           //数据存放目录
innodb_file_per_table= on       //每个innnodb表使用单个表文件
skip_name_resolve = on        //跳过主机名称解析




6.为mysql提供sysv服务脚本,并添加至服务列表
1
2
3
# cp support-files/mysql.server   /etc/rc.d/init.d/mysqld
# chmod +x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld




7.在配置文件中定义“pid-file”文件路径,否则启动mysql会出现错误
1
2
3
4
vim /etc/my.cnf
pid-file=/mydata/data/mysql.pid
vim /etc/rc.d/init.d/mysqld
mysqld_pid_file_path=/mydata/data




8.输出mysql的man手册至man命令中:
1
2
# vim /etc/man.config   添加下行即可:
MANPATH  /usr/local/mysql/man




9.输出mysql的头文件至系统文件路径/usr/include:
1
# ln -sv /usr/local/mysql/include  /usr/include/mysql





10.输出mysql的库文件给系统库查找路径:
1
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf




重新加载系统库:
1
# ldconfig




11.修改PATH环境变量,让系统可以直接使用mysql的相关命令:
1
2
3
4
vim /etc/profile.d/mysqld.sh
# export PATH=/usr/local/mysql/bin:$PATH
# . /etc/profile.d/mysqld.sh
# service mysqld start




三、编译安装php
1.开始安装php所需依赖环境:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# yum -y groupinstall "Desktop Platform Development"
# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
// libmcrypt-devel  本地光盘没有在epel源里面。其他的是epel源.,编译安装libmcrypt
如何安装epel源?
先安装yum优先级插件:
# yum install yum-priorities
安装epel:
# rpm -Uvh http://mirrors.ustc.edu.cn/fedor ... ease-6-8.noarch.rpm
#rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
导入epel:
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
修改epel配置文件中epel的源级别:加入下行就OK了
priority=11  
创建缓存:
# yum makecache




2.编译安装libmcrypt
1
2
3
4
# tar xf libmcrypt-2.5.7.tar.gz  
# cd libmcrypt-2.5.7
# ./configure --prefix=/usr/local/libmcrypt
# make && make install




3.开始编译安装php:
1
2
3
4
5
6
# tar xf php-5.4.40.tar.bz2
# cd php-5.4.40
# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr -enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt=/usr/local/libcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d  --with-bz2 --enable-maintainer-zts
//msqli:对应mysql另外的一个接口  ,freetype:多种字体 libxml:处理xml的文档 socket:支持socket   apxs:支持http第三方模块   zts:如果之前安装过httpd且模块是prefork则不需要,否则必须安装上去
# make -j     //启用多线程安装(由于php安装比较耗时)
# make install




默认情况下http是不支持php的,所以需要修改配置文件:
1
# cp  /etc/httpd24/httpd.conf /etc/httpd24/httpd.conf.bak




4.为php提供配置文件:
1
# cp  php.ini-production  /etc/php.ini





确认php模块是否加载进来:
QQ截图20160201101415.png

5.编辑apache文件使其支持php:
在文件中添加入下行:
1
2
3
4
DirectoryIndex   index.php  index.html
   
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps




6.重置下httpd服务:
1
# /usr/local/apache/bin/apachectl reload





7.默认测试页面在/usr/local/apache/htdocs,添加一个index.php测试文件:
1
2
3
4
5
6
7
8
9
<?php
      $link = mysql_connect('127.0.0.1','root',' ');
      if ($link)
        echo "Success...";
      else
        echo "Failure...";
        phpinfo();
      mysql_close();
?>




8.测试网页http://hostloaclIP


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-172218-1-1.html 上篇帖子: LAMP之三(编译安装httpd-fpm) 下篇帖子: LNMP下nignx访问php报找不到文件的解决方案
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表