编译安装LAMP(两种场景)

编译安装LAMP

场景一:AP组合以模块方式结合(编译PHP作为httpd的模块);进而完成虚拟主机PMA(phpmyadmin)和discuz论坛

场景二:AP组合以fpm方式,PHP独立守护进程运行;进而完成虚拟主机PMA(phpmyadmin)和discuz论坛

==========================场景一============================

拓扑结构:

主机一

网卡1IP为172.20.1.100

网卡2IP为192.168.217.219

在此计算机上编译安装HTTPD 和PHP

主机二IP为192.168.217.128

安装MYSQL

安装顺序HTTPD –> MYSQL –> PHP

HTTPD部分:(192.168.217.129/172.20.1.100)

在172.20.1.100中安装HTTPD:

编译安装httpd2.4 软件包版本是httpd-2.4.20.tar.bz2

安装前,需要检查:

包组:“Development Tools” “Server Platform Development”

软件包:pcre-devel  zlib-devel openssl-devel

yum groupinstall或者yum install之

httpd2.4的安装顺序:apr –> apr-util –> httpd2.4

apr和apr-util安装:

[[email protected] sources]# tar -xf apr-1.5.0.tar.bz2

[[email protected] sources]# tar -xf apr-util-1.5.3.tar.bz2

[[email protected] sources]#cd apr-1.5.0

[[email protected] apr-1.5.0]# ./configure --prefix=/usr/local/apr

[[email protected] apr-1.5.0]# make && make install

[[email protected] apr-1.5.0]# cd ../apr-util-1.5.3

[[email protected] apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

[[email protected] apr-util-1.5.3]# yum install pcre-devel zlib-devel openssl-devel

Httpd2.4安装:

[[email protected] sources]# tar xf httpd-2.4.20.tar.bz2

[[email protected] sources]# cd httpd-2.4.20

[[email protected] httpd-2.4.20]#./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-module=most --enable-mpms-shared=all --with-mpm=prefork

[[email protected] httpd-2.4.20]# make && make install

[[email protected] httpd-2.4.20]# vim /etc/profile.d/httpd.sh

[[email protected] httpd-2.4.20]# cat /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH

[[email protected] httpd-2.4.20]# source /etc/profile.d/httpd.sh

[[email protected] httpd-2.4.20]# cd /usr/local/apache/

[[email protected] apache]# ln -s include/ /usr/include/httpd  \\导出头文件

[[email protected] apache]# vim /etc/man.config

MANPATH /usr/local/apache/man \\新增;帮助文档

[[email protected] httpd24]# vim /etc/httpd24/httpd.conf

User daemon

Group daemon

改为:

User apache

Group apache    \\当然得确保系统中存在这个用户和组

#cd  /etc/rc.d/init.d/

#cp httpd  httpd24         \\本机有httpd文件就从本机复制,本机没有可以到别的机器复制过来

[[email protected] httpd24]# vim /etc/rc.d/init.d/httpd24

修改httpd24中:

apachectl=/usr/local/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/bin/httpd}

pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}

[[email protected] httpd24]# chkconfig --add httpd24

[[email protected] httpd24]# chkconfig httpd24 on

[[email protected] sources]# service httpd24 start

基本上httpd2.4编译安装完毕

MARIADB部分:(192.168.217.128)

192.168.217.128中安装二进制版本的MariaDB:

[[email protected] ~]# tar xf mariadb-5.5.40-linux-x86_64.tar.gz –C /usr/local/mysql  \\解压到/usr/local/mysql或者做软链接都行,但必须要是/usr/local/下

[[email protected] mysql]# mkdir -pv /data/mydata

[[email protected] mysql]# groupadd -r mysql

[[email protected] mysql]# useradd -r -g mysql mysql

[[email protected] mysql]# id mysql

uid=496(mysql) gid=493(mysql) 组=493(mysql)

[[email protected] mysql]# chown root:mysql /usr/local/mysql/*

[[email protected] mysql]# chown -R mysql:mysql /data/mydata/

[[email protected] mysql]# mkdir /etc/mysql

[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf

[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mydata/

[[email protected] mysql]# vim /etc/mysql/my.cnf

[mysqld]中修改、添加

thread_concurrency = 4 \\CPU核数*2 修改

datadir = /data/mydata \\添加

innodb_file_per_table = on \\添加

[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]# vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

[[email protected] mysql]# source /etc/profile.d/mysql.sh

[[email protected] mysql]# service mysqld start

PHP部分(192.168.217.128/172.20.1.100)

检查所需要的软件包

libxml2-devel libcrypt-devel bzip2-devel

[[email protected] php-5.4.26]# yum install -y libxml2-devel libcrypt-devel bzip2-devel (有些软件可能在epel源中)

[[email protected] htdocs]# cd ~/sources/

[[email protected] sources]# tar xf php-5.4.26.tar.bz2

[[email protected] sources]# cd php-5.4.26

[[email protected] php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-apxs2=/usr/local/apache/bin/apxs --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php.d/

[[email protected] php-5.4.26]# make && make install

[[email protected] php-5.4.26]# mkdir /etc/php

[[email protected] php-5.4.26]# mkdir /etc/php.d

[[email protected] php-5.4.26]# cp php.ini-production /etc/php/php.ini

修改httpd的配置文件:

[[email protected] php-5.4.26]# vim /etc/httpd24/httpd.conf

验证php:

[[email protected] php-5.4.26]# cd /usr/local/apache/htdocs/

[[email protected] htdocs]# vim index.php

<?php

phpinfo();

?>

在页面中有关于时间报错Warning: phpinfo(): It is not safe to rely on the system‘s timezone settings.

解决方法:

[[email protected] htdocs]# vim /etc/php/php.ini

date.timezone = "Asia/Shanghai"

[[email protected] htdocs]# vim /usr/local/apache/htdocs/index.php

<?php

date_default_timezone_set(‘Asia/Shanghai‘);

phpinfo();

?>

问题得到解决

验证php和mysql的结合:

Mysql中创建一个测试账号,也便于登录phpmyadmin和discuz使用

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO ‘testuser‘@‘%‘ IDENTIFIED BY ‘123456‘;

<?php

$link=mysql_connect(‘192.168.217.128‘,‘testuser‘,‘123456‘);

if ($link)

echo "<h1>success...</h1> ";

else

echo "<h1>connect failed</h1>";

mysql_close();

?>

安装xcache加速php,因为虚拟机配置差,安装跟没安装区别不大,效果不明显。。。简单说下步骤:

tar xf xcache-3.1.0.tar.bz2 \\解压

cd xcache-3.1.0 \\进入解压目录

/usr/local/php/bin/phpize \\没有configure文件,需要执行此命令configure就会出现

./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config \\安装步骤

make && make install \\安装步骤

cp xcache.ini /etc/php.d/ \\添加到php的配置文件目录中

vim /etc/php.d/xcache.ini \\编辑以下:

extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so

说明:在make install完成后会有一个提示告诉即 /usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xcache.so的路径,把此绝对路径复制到配置文件中即可

部署虚拟机phpmyadmin和discuz

[[email protected] webroot]# vim /etc/httpd24/httpd.conf

#DocumentRoot "/usr/local/apache/htdocs" \\注释掉

Include /etc/httpd24/extra/httpd-vhosts.conf \\启用

[[email protected] webroot]# vim /etc/httpd24/extra/httpd-vhosts.conf

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot "/webroot/pma/"

ServerName www.aaa.com

ServerAlias aaa.com

ErrorLog "/var/log/www.aaa.com-error_log"

CustomLog "/var/log/www.aaa.com-access_log" common

<Directory "/webroot/pma/">

options none

AllowOverride none

Require all granted

</Directory>

</VirtualHost>

Phpmyadmin的虚拟主机

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot "/webroot/discuz/"

ServerName www.bbb.com

ErrorLog "/var/log/www.bbb.com-error_log"

CustomLog "/var/log/www.bbb.com-access_log" common

<Directory "/webroot/discuz/">

options none

AllowOverride none

Require all granted

</Directory>

</VirtualHost>

Discus的虚拟主机

在本机C:\Windows\System32\drivers\etc\hosts 修改文件解析

172.20.1.100 www.aaa.com aaa.com

172.20.1.100 www.bbb.com bbb.com

Phpmyadmin要连接mysql,因为不在同一台加上,所以要修改配置文件指明mysql的地址

#vim /webroot/pma/libraries/config.default.php

$cfg[‘Servers‘][$i][‘host‘] = ‘192.168.217.128‘; \\修改mysql的IP

Discus的搭建就比较简单

把discuz的包解压后,将upload里的文件放到DocumentRoot中即/webroot/discuz/,然后给于777的权限

===========================场景二==============================

根据场景一的基础上又添加了一台机器

把php安装到此机器上来,过程比较简单,主要步骤:

1、 停用httpd中PHP模块

2、 Httpd虚拟主机中关闭正向代理,把php的请求转发到php服务器

3、 将httpd的虚拟主机DocumentRoot文件复制到php服务器中

为了记录完整的步骤,决定把所有主机还原,然后重做

规划:

主机1安装httpd,IP 172.20.1.100 192.168.217.129

主机2安装MYSQL IP 192.168.130

主机3安装php和xcache,IP 192.168.217.128

192.168.1.100中安装httpd

安装前准备好”Development Tools” “Server Platform Development”包组

pcre-devel zlib-devel openssl-devel等开发包

安装httpd前,编译安装apr和apr-util

[[email protected] sources]# tar xf apr-1.5.0.tar.bz2

[[email protected] sources]# cd apr-1.5.0

[[email protected] apr-1.5.0]# ./configure --prefix=/usr/local/apr

[[email protected] apr-1.5.0]# make && make install

[[email protected] sources]# tar xf apr-util-1.5.3.tar.bz2

[[email protected] sources]# cd apr-util-1.5.3

[[email protected] apr-util-1.5.3]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

[[email protected] apr-util-1.5.3]# make && make install

[[email protected] sources]# tar xf httpd-2.4.20.tar.bz2

[[email protected] sources]# cd httpd-2.4.20

[[email protected] httpd-2.4.20]# ./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-module=most --enable-mpms-shared=all --with-mpm=worker

采用了跟实验一不同的MPM,前者使用了prefork,后者使用了worker模型,这跟编译php有关系(区别),后面会有说明

[[email protected] httpd-2.4.20]# make && make install

安装完最后又告诉我们创建了哪些目录

Installing configuration files

mkdir /etc/httpd24

mkdir /etc/httpd24/extra

mkdir /etc/httpd24/original

mkdir /etc/httpd24/original/extra

Installing HTML documents

mkdir /usr/local/apache/htdocs

Installing error documents

mkdir /usr/local/apache/error

Installing icons

mkdir /usr/local/apache/icons

mkdir /usr/local/apache/logs

Installing CGIs

mkdir /usr/local/apache/cgi-bin

Installing header files

mkdir /usr/local/apache/include

Installing build system files

mkdir /usr/local/apache/build

Installing man pages and online manual

mkdir /usr/local/apache/man

mkdir /usr/local/apache/man/man1

mkdir /usr/local/apache/man/man8

mkdir /usr/local/apache/manual

make[1]: Leaving directory `/root/sources/httpd-2.4.20‘

[[email protected] httpd-2.4.20]# vim /etc/profile.d/httpd.sh

export PATH=/usr/local/apache/bin:$PATH

[[email protected] httpd-2.4.20]# source /etc/profile.d/httpd.sh

将启动程序路径加入到PATH中

[[email protected] httpd-2.4.20]# vim /etc/httpd24/httpd.conf

默认是daemon,修改为apache

[[email protected] httpd-2.4.20]# ln -sv /usr/local/apache/include/ /usr/include/httpd

\\导出头文件

[[email protected] httpd-2.4.20]# vim /etc/man.config

MANPATH /usr/local/apahce/man \\添加帮助文件到系统搜索路径

启动脚本:

-rwxr-xr-x 1 root root 3371 10月 28 22:04 /etc/rc.d/init.d/httpd24

如果本机有自带httpd的话,在此目录下应该会有一个httpd的启动脚本,复制修改下内容即可,如果本机没有,可以从别处复制来

修改部分:(同上)

apachectl=/usr/local/apache/bin/apachectl

httpd=${HTTPD-/usr/local/apache/bin/httpd}

pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}

[[email protected] httpd-2.4.20]# chkconfig --add httpd24

[[email protected] httpd-2.4.20]# chkconfig httpd24 on

[[email protected] httpd-2.4.20]# service httpd24 start

MYSQL:

[[email protected] sources]# tar xf mariadb-5.5.40-linux-x86_64.tar.gz

[[email protected] sources]# mv mariadb-5.5.40-linux-x86_64 /usr/local/mysql

[[email protected] ~]# cd /usr/local/mysql/

[[email protected] mysql]# groupadd -r mysql

[[email protected] mysql]# useradd -r -g mysql mysql

[[email protected] mysql]# mkdir -pv /data/mydata

[[email protected] mysql]# chown -R root:mysql /usr/local/mysql/*

[[email protected] mysql]# chown -R mysql:mysql /data/mydata/

[[email protected] mysql]# mkdir /etc/mysql

[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf

[[email protected] mysql]# vim /etc/mysql/my.cnf

修改[mysqld]中的部分参数:

thread_concurrency = 4 \\修改,一般为CPU核心数*2

datadir = /data/mydata \\添加,数据目录地址

innodb_file_per_table = on \\添加

[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mydata/

初始化mysql

[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysqld

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] mysql]# chkconfig mysqld on

[[email protected] mysql]# vim /etc/profile.d/mysql.sh

export PATH=/usr/local/mysql/bin:$PATH

PHP、xcache

事先安装好libmcrypt-devl “Development Tools” “Server Platform Development”

[[email protected] sources]# tar xf php-5.4.26.tar.bz2

[[email protected] sources]# cd php-5.4.26

[[email protected] php-5.4.26]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-bz2 --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php.d/ --enable-maintainer-zts

跟场景一不同的是,--enable-maintainer-zts (如果httpd使用的是prefork则不用此项,如果是worker或者event则使用此项)

去掉--with-apxs2=/usr/local/apache/bin/apxs  \\apxs作用是把php编程成http的模块,而改成—enable-fpm \\作为独立进程监听在套接字上

[[email protected] php-5.4.26]# make && make install

[[email protected] php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

[[email protected] php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm

[[email protected] php-5.4.26]# chkconfig --add php-fpm

[[email protected] php-5.4.26]# chkconfig php-fpm on

[[email protected] php-5.4.26]# mkdir /etc/{php,php.d}

[[email protected] php-5.4.26]# cp php.ini-production /etc/php/php.ini

[[email protected] php-5.4.26]# vim /usr/local/php/etc/php-fpm.conf

根据实际情况修改:

listen = 192.168.217.128:9000 \\监听地址和端口

pm.max_children = 100 \\最大并发数

pm.start_servers = 10 \\启动时启动进程数量

pm.min_spare_servers = 3 \\最少空闲数量

pm.max_spare_servers = 15 \\最大空闲数量

pid = /usr/local/php/var/run/php-fpm.pid

[[email protected] sources]# tar xf xcache-3.1.0.tar.bz2

[[email protected] sources]# cd xcache-3.1.0

[[email protected] xcache-3.1.0]# /usr/local/php/bin/ph

phar phar.phar php php-cgi php-config phpize

[[email protected] xcache-3.1.0]# /usr/local/php/bin/phpize

[[email protected] xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config

[[email protected] xcache-3.1.0]# make && make install

[[email protected] xcache-3.1.0]# vim /etc/php.d/xcache.ini

172.20.1.100中修改httpd的配置文件

[[email protected] httpd-2.4.20]# vim /etc/httpd24/httpd.conf

启用模块

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

DirectoryIndex index.php index.html

Include /etc/httpd24/extra/httpd-vhosts.conf

#DocumentRoot "/usr/local/apache/htdocs"

[[email protected] httpd-2.4.20]# vim /etc/httpd24/extra/httpd-vhosts.conf

在PHP服务器中(192.168.217.128)解压pma和discuz的文件,过程省略

[[email protected] www]# chmod -R 777 bbs

修改pma中mysql的地址

[[email protected] pma]# vim libraries/config.default.php

$cfg[‘Servers‘][$i][‘host‘] = ‘192.168.217.130‘;

注意:在PHP中解压出的pma和discuz目录结构要在httpd服务器上创建一模一样的结构,否则只能打开.php的内容,而图片则不显示等问题

[[email protected] ~]# rsync -a /web [email protected]:/

时间: 2024-10-07 05:29:50

编译安装LAMP(两种场景)的相关文章

编译安装LAMP[两种结合方式]

本文旨在实践编译安装LAMP环境,搭建Zblog系统,使用Xcache为PHP加速,分离PHP与Apache Server LAMP基础知识 Linux + Apache + MySQL[MariaDB] + PHP[Perl|Pyton] 是一套基础的web环境: Apache有2.2版本,和最新的2.4版本,2.4版本支持Event MPM可用作生产环境,在http2.2中有3种MPM,为不同的进程文件,切换需要重启Apache服务:而2.4中MPM做成了DSO,可动态加载切换: Apach

编译安装LAMP之一

环境:CentOS-6.5-i386-minimal httpd-2.2.27.tar.gz mysql-5.5.38-linux2.6-i686.tar.gz php-5.5.14.tar.gz 编译安装的原则:对于我们来说,需要定制的就直接编译,其余的一切皆yum / apt-get搞定 1.关闭iptables和SELinux [[email protected] ~]# service iptables stop [[email protected] ~]# setenforce 0 2

ubuntu10.04编译安装LAMP

ubuntu10.04编译安装LAMP以及简单wordpress的使用 : http://linuxme.blog.51cto.com/1850814/971631 一.源码安装LAMP 网上有一堆关于介绍lamp的在这里我就不罗嗦了,直接上配置过程 1.apr包的安装 apr简介: The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that

运维工作必备----------编译安装LAMP

1.编译安装介绍 在工作中,基于各种生产环境下,可能yum安装不能满足我们的需求.这个时候我们就得自己动手编译安装软件包,当然只要掌握了技巧,其实编译安装也非常的简单.本文将介绍如何在CentOS 6.7系统下编译安装:httpd-2.4.6 + php-5.6.4 + xcache-3.2.0 + mariadb-5.5.43,编译完成后基于LAMP环境搭建一个Wordpress 和phpMyAdmin. 2.编译安装 2.1 mariadb-5.5.43 准备数据存放的文件系统 新建一个逻辑

linux架构学习第二十七天 编译安装LAMP(php-fpm)

内容: 第一部分:编译安装LAMP(php以模块的方式工作) 第二部分:编译安装LAMP(php以fpm的方式工作) 第一部分: 前面介绍我们知道, apache + php结合的方式大概几种: 第一种:把php编译时直接编译成apache的模块.module模块化的方式进行工作 第二种:CGI.通用网关接口.apache基于CGI跟hph通信 第三种:fastcgi方式,他也是一种协议,在这种模块下他们两个是这样结合的: 本来php是做为一个模块或都是php解析器运行的,不是监听在某个套接字上

编译安装LAMP+phpMyAdmin

一.准备工作 关闭防火墙.selinux,配置yum源,并移出系统已安装的httpd,mysql,php 二.安装apache ttpd-2.4.10需要较新版本的apr和apr-util,因此需要事先对其进行升级.升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包.这里使用源码编译演示. 1.安装apr [[email protected] /]# tar xf apr-1.5.1.tar.bz2 -C /usr/src/ [[email protected] /]# cd /u

fcgi模式下编译安装LAMP+xcache

php的工作模式: php在lamp环境下共有三种工作模式:CGI模式.apache模块.FastCGI模式.CGI模式下运行PHP,性能不是很好.作为apache的模块方式运行,在以前的课程中编译安装lamp已经介绍过了.FastCGI的方式和apache模块的不同点在于:FastCGI方式PHP是一处独立的进程,所有PHP子进程都由PHP的一个叫作php-fpm的组件负责管理:而apache模块化方式运行的PHP,则是apache负责调用PHP完成工作.PHP的FastCGI方式性能要比ap

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/Apache-2.2.25 tar -xzvf ./httpd-2.2.25.tar.gz cd ./httpd-2.2.25 #生成configure ./configure --prefix=/usr/local/apache --with-included-apr --enable-so -

编译安装LAMP之二

在上一篇中,我们已经安装httpd,以及mysql服务.那么接下来,我们将安装php. 我们知道,php工作的模式有三种:cgi, module, fastcgi.通常,apache与php是以模块的方式结合的,鉴于fastcgi的工作模式会有更好的效率,待会儿也会讲解. 一.以模块化的方式编译php, php作为apache的模块被加载 如果我们先前没有安装: libxml2 libxml2-devel bzip2-devel libmcrypt libmcrypt-devel 需要安装这些包