Linux下编译安装LAMP并分离为多台服务器

1、Linux;操作系统;

2、Apache;网页服务器;

3、MariaDB或MySQL,,数据库管理系统(或者数据库服务器);

4、PHP、Perl或Python,脚本语言;

在编译安装之前我们需要先了解下它们之间分开的工作模式:

上图大致的标出Apache、php和mysql分离各自为单独服务器时的工作模式;下面就直接进行编译安装;首先准备好三个虚拟机。测试机版本:

[Linux86]#lsb_release -aLSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarchDistributor ID: CentOSDescription: CentOS release 6.5 (Final)Release: 6.5Codename: Final

由于其中操作都是插入代码的;所以命令执行过程并没有把代码都贴出来,只贴出最后几行;

一、编译安装Apache2.4.9

1、解决依赖关系:

[Linux86]#yum grouplist#Installed Groups: Additional Development Base Console internet tools Desktop Desktop Platform Development tools #查看包组是否安装 Server Platform Development #查看包组是否安装如未安装;请先安装这两个包组#[Linux86]#rpm -qa pcre-develpcre-devel-7.8-6.el6.x86_64#查看是否安装;未安装需事先安装[Linux86]#lsapr-1.5.0.tar.bz2 apr-util-1.5.3.tar.bz2 httpd-2.4.9.tar.bz2[Linux86]##先安装apr包;解压后进入该目录[Linux86]#pwd/root/program/apr-1.5.0[Linux86]#./configure –prefix=/usr/local/aprconfig.status: executing default commandsconfig.status: include/apr.h is unchangedconfig.status: include/arch/unix/apr_private.h is unchanged #没有报错就继续[Linux86]#make && make install/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config#没有报错就继续安装apr-util包[Linux86]##解压进入目录[Linux86]#./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr/config.status: creating test/Makefileconfig.status: creating include/private/apu_config.hconfig.status: executing default commands[Linux86]#make && make install/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config[Linux86]#都以安装成功

2、编译Apache:

[Linux86]#rpm -qa httpdhttpd-2.2.15-29.el6.centos.x86_64##系统自己本身已安装了httpd2.2版本的;这里编译2.4的;但是老版本不需要卸载;#因为卸载后会造成依赖关系不稳定;且后续安装模块时还是会自动安装上的;#编译是只要不指定到默认路径即可;确保安装前原来的是停止的;且关闭开启自动启动##[Linux86]#./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 –enable-proxy –enable-proxy-fcgi参数可以通过./configure –help查看;开启自己需要的即可#如没有报错直接下一步安装[Linux86]#make && make installmkdir /usr/local/apache/buildInstalling man pages and online manualmkdir /usr/local/apache/manmkdir /usr/local/apache/man/man1mkdir /usr/local/apache/man/man8mkdir /usr/local/apache/manualmake[1]: Leaving directory `/root/program/httpd-2.4.9’#安装完成[Linux86]#

3、配置Apache:

#由于之前的httpd没有卸载;那么可以cp一个启动脚本当目前的httpd脚本;更改下里面的参数#[Linux86]#cp /etc/rc.d/init.d/httpd /etc/rc.d/init.d/httpd24[Linux86]#vi /etc/rc.d/init.d/httpd24# Path to the apachectl script, server binary, and short-form for messages.#以下几个变量定义为目前的路径;并在主配置文件中更改对应的值achectl=/usr/local/apache/bin/apachectlhttpd=${HTTPD-/usr/local/apache/bin/httpd}prog=httpdpidfile=${PIDFILE-/var/run/httpd/httpd.pid}lockfile=${LOCKFILE-/var/lock/subsys/httpd24}RETVAL=0STOP_TIMEOUT=${STOP_TIMEOUT-10}#修改主配置文件[Linux86]#vi /etc/httpd24/httpd.conf# same ServerRoot for multiple httpd daemons, you will need to change at# least PidFile.#ServerRoot “/usr/local/apache”pifile “/var/run/httpd/httpd.pid” #加一行pid文件路径;与脚本文件对应#保存退出[Linux86]#service httpd24 startStarting httpd:[ OK ][Linux86]#ss -tnlStateRecv-Q Send-QLocal Address:PortPeer Address:PortLISTEN0128:::111:::*LISTEN0128*:111*:*LISTEN0128:::80:::*#80端口已监听

到这里Apache已编译安装完成了;也可以在浏览器输入IP地址测试下。

二、编译安装PHP

编译之前都是需要检查开发环境;需要安装的包是否都已安装

[Linux87]#rpm -qa bzip2-devel libmcrypt-devel libxml2-devellibxml2-devel-2.7.6-14.el6.x86_64bzip2-devel-1.0.5-7.el6_0.x86_64libmcrypt-devel-2.5.8-9.el6.x86_64[Linux87]##如未安装;需要先用yum安装上

1、这边是每个服务单独作为一个服务器;所以编译时与放在一台机器上是有分别的;而且也不需要先安装mysql;下面来直接编译PHP

[Linux87]#lsphp-5.4.26.tar.bz2 xcache-3.1.0.tar.bz2[Linux87]#tar xf php-5.4.26.tar.bz2[Linux87]#./configure –prefix=/usr/local/php –enable-fpm –with-config-file-path=/etc –with-config-file-scan-dir=/etc/php.d –with-libxml-dir=/usr –with-openssl –with-zlib –with-bz2 –with-jpeg-dir –with-png-dir –with-freetype-dir –enable-mbstring –with-mcrypt –enable-sockets –with-mysql=mysqlnd –with-mysqli=mysqlnd –with-pdo-mysql=mysqlnd#注意:–with-mysql几个选项都要为mysqlnd;因为mysql服务器单独为另一台机器+——————————————————————–+| License:|| This software is subject to the PHP License, available in this|| distribution in the file LICENSE. By continuing this installation || process, you are bound by the terms of this license agreement.|| If you do not agree with the terms of this license, you must abort || the installation process at this point.|+——————————————————————–+Thank you for using PHP.出现上述字符就说明可以继续安装了;[Linux87]#make && make installInstalling PEAR environment:/usr/local/php/lib/php/[PEAR] Archive_Tar – installed: 1.3.11[PEAR] Console_Getopt – installed: 1.3.1warning: pear/PEAR requires package “pear/Structures_Graph” (recommended version 1.0.4)warning: pear/PEAR requires package “pear/XML_Util” (recommended version 1.2.1)[PEAR] PEAR- installed: 1.9.4Wrote PEAR system config file at: /usr/local/php/etc/pear.confYou may want to add: /usr/local/php/lib/php to your php.ini include_path[PEAR] Structures_Graph- installed: 1.0.4[PEAR] XML_Util- installed: 1.2.1/root/program/php-5.4.26/build/shtool install -c ext/phar/phar.phar /usr/local/php/binln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/pharInstalling PDO headers:/usr/local/php/include/php/ext/pdo/[Linux87]##到这里说明安装成功了;可能会有些报错说某些软件版本太低

我想有一天和你去旅行。去那没有去过的地方,

Linux下编译安装LAMP并分离为多台服务器

相关文章:

你感兴趣的文章:

标签云: