编译安装lamp环境
httpd 2.4.9 + mysql-5.5.33 + php-5.4.29编译安装过程:
准备好以下安装包:
mysql-5.5.33-linux2.6-x86_64.tar.gz
apr-util-1.5.3.tar.bz2
httpd-2.4.9.tar.bz2
phpMyAdmin-4.0.5-all-languages.zip
xcache-3.0.3.tar.bz2
一、安装mysql-5.5.33
1、准备数据存放的文件系统
新建一个逻辑卷,并将其挂载至特定目录
这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为mysql数据的存放目录
# fdisk /dev/sda
分一个sda3的主分区20G,调整为8e Linux LVM格式
# kpartx -l /dev/sda
# kpartx -af /dev/sda
# partx -a /dev/sda
验证
# cat /proc/partitions
创建逻辑卷
# pvcreate /dev/sda3
创建名为Myvg的卷组
# vgcreate myvg /dev/sda3
创建10G的逻辑卷mylv
# lvcreate -L 10G -n mylv myvg
格式化
# mke2fs -t ext4 /dev/myvg/mylv
创建挂载点
# mkdir -p /data/mydata
改变属主数组
# chown -R mysql.mysql /data/mydata
vim /etc/fstab
/dev/myvg/mylv /data/mydata ext4 defaults,noatime 0 0
挂载
# mount -a
验证是否挂载成功
# mount
2、新建用户以安全方式运行进程:
# groupadd -r mysql
# useradd -g mysql -r -s /sbin/nologin mysql
验证
# id mysql
3、安装并初始化mysql-5.5.33
# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mysql-5.5.33-linux2.6-x86_64 mysql
# cd mysql
# chown -R root:mysql ./*
# scripts/mysql_install_db --datadir=/data/mydata --user=mysql
4、为mysql提供主配置文件:
# cd /usr/local/mysql
# cp support-files/my-large.cnf /etc/my.cnf
并修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /data/mydata
5、为mysql提供sysv服务脚本:
# cd /usr/local/mysql
# cp support-files/mysql.server /etc/init.d/mysqld
添加至服务列表:
# chkconfig --add mysqld
# chkconfig mysqld on
验证
# chkconfig --list mysqld
而后就可以启动服务测试使用了
# service mysqld start
# ss -tnl
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径:
编辑/etc/man.config,添加如下行即可:
MANPATH /usr/local/mysql/man
7、输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
# ln -sv /usr/local/mysql/include /usr/include/mysql
8、输出mysql的库文件给系统库查找路径:
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
或者
# vim /etc/ld.so.conf.d/mysql.conf
加入如下内容:
/usr/local/mysql/lib
而后让系统重新载入系统库:
# ldconfig
9、修改PATH环境变量,让系统可以直接使用mysql的相关命令
# vim /etc/profile.d/mysql.sh
加入如下内容
export PATH=/usr/local/mysql/bin:$PATH
# chmod +x /etc/profile.d/mysql.sh
# /etc/profile.d/mysql.sh
若无法加入环境变量则:
vim /etc/profile
在最后一行加入
export PATH=/usr/local/mysql/bin:$PATH
mysql进入数据库
删除匿名的用户,并设置密码
通过在用户家目录下创建隐藏文件的方法,可以免去输入密码
vim ./mysql.conf
[mysql]
host=localhost
user=root
password=pass
二、编译安装apache
1、解决依赖关系
httpd-2.4.9需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。这里选择使用编译源代码的方式进行
(1) 编译安装apr
先解决依赖关系
# yum install -y pcre-devel
# tar xf apr-1.5.0.tar.bz2
# cd apr-1.5.0
# ./configure --prefix=/usr/local/apr
configure: error: no acceptable C compiler found in $PATH
# ./configure --prefix=/usr/local/apr
需要安装gcc编译器
# yum install -y gcc*
# make && make install
(2) 编译安装apr-util
# 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-2.4.9
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
报错:checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
# yum install -y openssl-devel
再次配置
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --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
补充:
(1)构建MPM为静态模块
在全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本 时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 ./httpd -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。
(2)构建 MPM 为动态模块
在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用--enable-mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令内容可以选择不同的MPM。
3、修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd/httpd.conf,添加如下行即可(否则报错
# service httpd restart
Stopping httpd: [FAILED]
Starting httpd: httpd (pid 49863) already running
[ OK ]):
PidFile "/var/run/httpd.pid"
4、提供SysV服务脚本/etc/rc.d/init.d/httpd
vim /etc/rc.d/init.d/httpd24
内容如下:
#!/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
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd24
加入服务列表:
# chkconfig httpd24 on
# chkconfig --add httpd24
# chkconfig --list httpd24
加入环境变量中
vim /etc/profile.d/httpd24.sh
export PATH=/usr/local/apache/bin:$PATH
# chmod +x /etc/profile.d/httpd24.sh
启动服务报错如下:
httpd: apr_sockaddr_info_get() failed for centossz008
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
解决办法:
(1)可以设定httpd.conf文件中的 ServerName,如下:ServerName localhost:80
(2)在 /etc/hosts 中填入自己的主机名称 centossz008,如下:127.0.0.1 centossz008 (计算机名)
发现继续报错
# cd /usr/local/apache/logs
# tail error_log
接下来就可以启动apache服务进行测试了。
service httpd24 start
三、编译安装php-5.4.26
1、解决依赖关系:
请配置好yum源(可以是本地系统光盘)后执行如下命令:
查询yum安装组列表
yum grouplist
查询组信息
yum groupinfo "Desktop Platform Development"
# yum groupinstall -y "Desktop Platform Development"
# yum -y install bzip2-devel libmcrypt-devel
安装 libmcrypt-devel 报错:
解决方法:
# yum install epel-release //扩展包更新包
# yum update //更新yum源
# yum install -y libmcrypt-devel
2、编译安装php-5.4.26
# tar xf php-5.4.26.tar.bz2
# cd php-5.4.26
# ./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 --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
说明:
1、这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
2、如果使用PHP5.3以上版本,为了链接MySQL数据库,可以指定mysqlnd,这样在本机就不需要先安装MySQL或MySQL开发包了。mysqlnd从php 5.3开始可用,可以编译时绑定到它(而不用和具体的MySQL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
# ./configure --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd
# make
# make install
或 # make && make install
为php提供配置文件:
# cp php.ini-production /etc/php.ini
3、 编辑apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf
1、添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
2、定位至DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用
# service httpd24 restart
php连接mysql数据库的测试脚本
<?php
$link = mysql_connect('localhost','root','mysql');
if($link){
echo 'success';
}else{
echo 'fail';
}
?>
打印fail
通过观察,表的密码没有问题,原来是当时设置密码没有刷新权限
mysql> flush privileges;
访问脚本显示success,关闭数据库(service mysqld stop)重新运行脚本,打印fail
# service mysqld start
打印success
至此lamp环境搭建OK
编译安装lamp环境的更多相关文章
- CentOS6.5下编译安装LAMP环境
LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架.该框架能够满足大流量.大并发量的网站需求:当然.也可以直接使用高性能的服务器.高性能的负载均衡硬件以及CDN ...
- CentOS 6.3编译安装LAMP环境笔记
转载地址:http://www.jb51.net/article/54969.htm 最近抽空在虚拟机上测试成功了LAMP各个最新版本的整合编译安装,算是把之前的博文整合精简,以下内容均在CENTOS ...
- centos6.7下编译安装lamp环境
编译C源代码: 前提:提供开发工具及开发环境 通过“包组”提供开发组件,CentOS 6: "Development Tools", "Server Platform D ...
- 源码编译安装LAMP环境及配置基于域名访问的多虚拟主机
实验环境及软件版本: CentOS版本: 6.6(2.6.32.-504.el6.x86_64) apache版本: apache2.2.27 mysql版本: Mysql-5.6.23 php版本 ...
- shell脚本编译安装LAMP环境
#filename lamp.sh#version Centos6.7;apache2.4.23;mariadb-5.5.40;php5.5.38#data 2016/09/28#mail 23853 ...
- Centos7源码编译安装LAMP环境
参考地址:https://www.linuxidc.com/Linux/2018-03/151133.htm
- ubuntu10.04编译安装LAMP
ubuntu10.04编译安装LAMP以及简单wordpress的使用 : http://linuxme.blog.51cto.com/1850814/971631 一.源码安装LAMP 网上有一堆关 ...
- CentOS 6编译安装lamp,并分别安装event模块方式和FPM方式的PHP
任务目标: 编译安装LAMP 要求(1) 安装一个模块化的PHP 要求(2) 安装一个FPM的PHP 注意PHP需要最后一个安装,因为需要前两者的支持. 所以这里的安装次序为 1.httpd 2.Ma ...
- CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25
所需源码包: /usr/local/src/Apache-2.2.25/httpd-2.2.25.tar.gz 编译安装 Apache2.2.25 #切换到源码目录 cd /usr/local/src ...
随机推荐
- 【POJ3349】snowflakes
这是一道可以练习哈希表的模板题.关于哈希表的操作均有涉及. 哈希函数的选取是这道题的关键.这道题的关键字是一个长度为6的序列,并且序列与开始顺序.时钟顺序均无关. 因此,采用哈希函数\(H[x]=\S ...
- (转)Java transient关键字使用小记
背景:最近在看java底层的源码实现,看到一个关键字,不是很熟悉,专门做个记录. 原文出处:http://www.importnew.com/21517.html#comment-637072 哎,虽 ...
- jar文件放在桌面上双击启动不了,但放在其它任何文件夹里都可以双击启动
今天本来是想尝试一下Java Network Launching Protocol (JNLP,java网络加载协议) 的,写了一个简单的窗口程序,打包成jar保存到桌面上,双击等了半天没显示出来. ...
- MUI 拍照或选取照片上传作为头像
1.第一种方法是用H5来实现的 HTML: <label> <input style="opacity: 0;" type="file" ac ...
- 无法SSH服务器的解决过程(openssh-daemon is stopped)
公司某台服务器不知为何无法ssh连接上,进入现场查看: 1.执行netstat -atnlp|grep ssh,没有找到ssh端口 2.执行ps aux|grep ssh,没找到相关进程 3.执行se ...
- Date对象常用方法
年月日: var oDate = new Date() //年 oDate.getFullYear(); //月 返回的月份要+1才正常 oDate.getMonth()+1: //日 oDate.g ...
- webStorm2018激活的方法
问题 激活 webstorm 2018 最新版 解决步骤 License server:http://im.js.cn:8888
- Linux 命令详解(五)cp 命令两个高效的用法
cp 命令两个高效的用法http://mp.weixin.qq.com/s/j7h-MayR0kCxfufWx0FtrA
- python学习笔记8--面向对象编程
一.面向对象编程 面向对象--Object Oriented Programming,简称oop,是一种程序设计思想.在说面向对象之前,先说一下什么是编程范式,编程范式你按照什么方式来去编程,去实现一 ...
- Python XML操作
XML(可扩展性标记语言)是一种非常常用的文件类型,主要用于存储和传输数据.在编程中,对XML的操作也非常常见. 本文根据python库文档中的xml.etree.ElementTree类来进行介绍X ...