使用源代码包实现LAMP构架模型

    在前一篇博文中使用rpm包实现了LAMP构架模型,在这篇博文中将使用源代码编译的形式实现这个经典的LAMP web构建。

    php同httpd结合有3种方式,这里用到2种:1,做为httpd的模块,被加载使用。2.php以独立守护进程形式存在,同httpd之间使用fastcgi结合在一起。下文通过2个使用场景展现这2中结合方式。
   一定要注意编译的先后次序,php一定要放在最后进行编译。

实验环境:

主机
IP地址
角色
Test01.lijun.com
192.168.100.1/24

承载LAMP构建,在不同的场景中分别实现如下的虚拟主机:

1)提供phpmyadmin web形式管理数据库。

2)提供Discuz论题。

Server.lijun.com
192.168.100.100/24
测试主机,对web站点进行测试

1.编译安装httpd
    1.1)解决依赖关系
       httpd-2.4.x 需要的apr和apr-util均在1.4.0之上,但是centos 6.6 自带的apr和apr-util 均为1.3.9,
因此需要事先对其进行升级。

[lijun@Test01 source]$ rpm -qa | grep apr
apr-util-1.3.9-3.el6_0.1.x86_64
apr-1.3.9-5.el6_2.x86_64
[lijun@Test01 source]$

   (1):编译安装apr和apr-util:

[lijun@Test01 source]$ tar -xf apr-1.5.0.tar.bz2                           
[lijun@Test01 source]$ cd apr-1.5.0                                        
[lijun@Test01 apr-1.5.0]$ ./configure --prefix=/usr/local/apr && make
[lijun@Test01 apr-1.5.0]$sudo make install
[lijun@Test01 apr-1.5.0]$ ls /usr/local/apr
bin  build-1  include  lib
[lijun@Test01 apr-1.5.0]$

   (2):编译安装apr-util:

[lijun@Test01 source]$ tar -xf apr-util-1.5.3.tar.bz2
[lijun@Test01 source]$ cd apr-util-1.5.3
[lijun@Test01 apr-util-1.5.3]$ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make
[lijun@Test01 apr-util-1.5.3]$ sudo make install
[lijun@Test01 apr-util-1.5.3]$ ls /usr/local
apr  apr-util  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[lijun@Test01 apr-util-1.5.3]$

   (3):使用系统光盘安装pcre-devel:

[lijun@Test01 source]$ sudo mount -r /dev/sr0 /media/
[lijun@Test01 source]$ sudo rpm -ivh /media/Packages/pcre-devel-7.8-6.el6.x86_64.rpm
warning: /media/Packages/pcre-devel-7.8-6.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Preparing...                ########################################### [100%]
   1:pcre-devel             ########################################### [100%]
[lijun@Test01 source]$

   
   1.2)编译安装httpd-2.4.10.tar.bz2

[lijun@Test01 source]$ tar -xf httpd-2.4.10.tar.bz2
[lijun@Test01 source]$ cd httpd-2.4.10
[lijun@Test01 httpd-2.4.10]$ ./configure --prefix=/usr/local/apache2410 \
--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=prefork
[lijun@Test01 source]$ make
[lijun@Test01 source]$ sudo make install
[lijun@Test01 httpd-2.4.10]$ ls /usr/local/apache2410/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
[lijun@Test01 httpd-2.4.10]$

   
   1.3 )修改PATH路径,导出头文件,添加man手册

[lijun@Test01 httpd-2.4.10]$ sudo vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache2410/bin:$PATH
:wq
[lijun@Test01 httpd-2.4.10]$ sudo ln -sv /usr/local/apache2410/include /usr/include/http
"/usr/include/http" -> "/usr/local/apache2410/include"
[lijun@Test01 httpd-2.4.10]$ sudo vim /etc/man.config
MANPATH /usr/local/apache2410/man
:wq

2 安装mariadb 二进制程序包

[lijun@Test01 source]$ sudo tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
[lijun@Test01 source]$ ls /usr/local
apache2410  apr-util  etc    include  lib64    mariadb-5.5.43-linux-x86_64  share
apr         bin       games  lib      libexec  sbin                         src
[lijun@Test01 source]$ sudo ln -s /usr/local/mariadb-5.5.43-linux-x86_64/  /usr/local/mysql 
[lijun@Test01 source]$ cd /usr/local/mysql
[lijun@Test01 mysql]$sudo groupadd -r mysql
[lijun@Test01 mysql]$sudo useradd -g mysql -r mysql
[lijun@Test01 mysql]$sudo chown -R root:mysql mariadb-5.5.43-linux-x86_64
[lijun@Test01 mysql]$sudo chown -R mysql:mysql mariadb-5.5.43-linux-x86_64/data/
[lijun@Test01 mysql]$sudo mkdir /etc/mysql/
[lijun@Test01 mysql]$sudo cp /usr/local/mysql/support-files/my-medium.cnf /etc/mysql/my.cnf
[lijun@Test01 mysql]$ sudo /usr/local/mysqlscripts/mysql_install_db --user=mysql --defaults-file=/etc/mysql/my.cnf
[lijun@Test01 mysql]$sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[lijun@Test01 mysql]$sudo chmod +x /etc/init.d/mysqld
[lijun@Test01 mysql]$ sudo touch /etc/profile.d/mysql.sh
[lijun@Test01 mysql]$ sudo vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
:wq
[lijun@Test01 mysql]$ sudo ln -s /usr/local/mysql/include /usr/include/mysql
[lijun@Test01 mysql]$ sudo vim /etc/man.config
MANPATH /usr/local/mysql/man
:wq


场景一:设定虚拟主机,提供phpamdin的登录(此场景下要求php编译为httpd的模块使用)
  

  3.编译安装php
   3.1)安装依赖的组件:libxml2-devel,  bzip2-devel

[lijun@Test01 source]$sudo yum -y install bzip2-devel  libxml2-devel

   3.2)编译安装:

[root@Test01 lamp]# tar -xf php-5.4.40.tar.bz2 
[root@Test01 lamp]# cd php-5.4.40
[root@Test01 php-5.4.40]# ./configure --prefix=/usr/local/php \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-apxs2=/usr/local/apache2410/bin/apxs --with-freetype-dir \
--with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr \
--enable-xml --enable-sockets --with-bz2 \
--with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php.d/
[root@Test01 php-5.4.40]# make && make install

    3.3)添加配置文件

[root@Test01 php-5.4.40]# cp php.ini-production  /etc/php.ini

    
    4.配置httpd支持php


#vim /usr/local/apache2410/conf/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

    5.做php同httpd的结合测试:

[root@Test01 conf]# touch /usr/local/apache2410/htdocs/index.php
[root@Test01 conf]# vim /usr/local/apache2410/htdocs/index.php
  1 <?php
  2 phpinfo();
  3 ?>
[root@Test01 conf]#

 
wKioL1VGFRKj4XH5AAIwyyTY_J8946.jpg
    6.做php同mariadb连通性测试

[root@Test01 conf]# service mysqld start
Starting MySQL                                             [  OK  ]
[root@Test01 conf]# vim /usr/local/apache2410/htdocs/index.php
<?php
      $link = mysql_connect('127.0.0.1','root','');
      if ($link)
      echo "Success...";
      else
          echo "Failure...";
      mysql_close();
?>
[root@Test01 conf]# apachectl restart

wKioL1VGFWvBG6v3AACOnNSzndE185.jpg
     7 提供phpmyadmin文件。

[root@Test01 conf]#rm -rf /usr/local/apache2410/htdocs/index.php 
[root@Test01 lamp]# tar -xf phpMyAdmin-3.2.5-all-languages.tar.gz 
[root@Test01 lamp]# cp -a phpMyAdmin-3.2.5-all-languages/* /usr/local/apache2410/htdocs/
[root@Test01 lamp]# apachectl restart

wKiom1VGFJXB6DcRAAHgoX_qvx8466.jpg



场景二。设定虚拟主机,安装discuz论坛(要求php以fpm形式同httpd结合)
     8.恢复httpd的“纯净”状态

[root@Test01 lamp]# apachectl stop
[root@Test01 lamp]# rm -rf /usr/local/apache2410/conf/httpd.conf
[root@Test01 lamp]# cp  /usr/local/apache2410/conf/httpd.conf.bak /usr/local/apache2410/conf/httpd.conf
[root@Test01 htdocs]# apachectl restart

wKiom1VGF3nDl-2JAACKADV0tm8630.jpg  

  9.编译php(以fpm形式同httpd结合)

[root@Test01 php-5.4.40]# ./configure --prefix=/usr/local/php5 \
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config  \
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \
--with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm  \
--with-bz2 --with-config-file-path=/etc/php/php.ini \
--with-config-file-scan-dir=/etc/php.d/
[root@Test01 php-5.4.40]#make && make install

     10.提供配置文件

[root@Test01 php-5.4.40]# mkdir /etc/php
[root@Test01 php-5.4.40]# cp php.ini-production  /etc/php/php.ini

     11.为php-fpm提供启动脚本


[root@Test01 php-5.4.40]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@Test01 php-5.4.40]# chmod +x /etc/rc.d/init.d/php-fpm
[root@Test01 php-5.4.40]# chkconfig --add php-fpm
[root@Test01 php-5.4.40]# chkconfig php-fpm on
[root@Test01 php-5.4.40]#

     12.为php-fpm提供配置文件:

[root@Test01 php-5.4.40]# cp /usr/local/php5/etc/php-fpm.conf.default  /usr/local/php5/etc/php-fpm.conf

     13.编辑php-fpm的配置文件:
[root@Test01 php-5.4.40]#vim /usr/local/php5/etc/php-fpm.conf
pid = /usr/local/php5/var/run/php-fpm.pid  --->明确指定pid文件
pm.INDEX = VALUE                           --->根据自己需要修改pm开头的参数行
    
     14.启动php-fpm并作测试

[root@Test01 php-5.4.40]# service php-fpm start
[root@Test01 php-5.4.40]# netstat -tlpn | grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      27740/php-fpm       
[root@Test01 php-5.4.40]#

     15.配置httpd使其支持fpm形式的php

[root@Test01 php-5.4.40]# vim  /usr/local/apache2410/conf/httpd.conf
#启用下面2项
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
Include conf/extra/httpd-vhosts.conf
#添加下面2项
 AddType application/x-httpd-php     .php
 AddType application/x-httpd-php-source   .phps
#修改下面项:
DirectoryIndex index.php index.html
#注释中心主机
#DocumentRoot "/usr/local/apache2410/htdocs"

     16.配置虚拟主机中支持使用fcgi

[root@Test01 php-5.4.40]#vim /usr/local/apache2410/conf/extra/httpd-vhosts.conf
#注释该文件中所有东东,添加下列内容
<VirtualHost 192.168.100.1:80>
     DocumentRoot "/usr/local/apache2410/docs/mydiscuz.com"
     ServerName www.mydiscuz.com
     ErrorLog "logs/mydiscuz.com-error_log"
     CustomLog "logs/mydiscuz.com-access_log" common
     ProxyRequests Off
     ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache2410/docs/mydiscuz.com/$1
     <Directory "/usr/local/apache2410/docs/mydiscuz.com">
             Options none
             AllowOverride none
             Require all granted
     </Directory>
</VirtualHost>

     17.添加虚拟主机需要的文档

[root@Test01 conf]# cd /usr/local/apache2410/htdocs/
[root@Test01 htdocs]# mkdir mydiscuz.com
[root@Test01 lamp]# unzip Discuz_7.2_FULL_SC_GBK.zip
[root@Test01 lamp]# \cp -a upload/* /usr/local/apache2410/htdocs/mydiscuz.com/

     18 创建discuz论题使用库和用户

MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.07 sec)
MariaDB [(none)]> create user 'lijun'@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.61 sec)
MariaDB [(none)]> grant all on discuz.* to 'lijun'@'localhost';
Query OK, 0 rows affected (0.08 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.06 sec)

     19 安装论坛:
修改测试主机的host文件:C:\Windows\System32\drivers\etc\hosts

#添加下列行

192.168.100.1   www.mydiscuz.com

然后浏览器像下面这样输入URL路径:
wKiom1VGGGXCmVe-AAO1EWiDFnA713.jpg

wKiom1VGGKKTKf_0AAMHm_9cfGA536.jpg



[root@Test01 mydiscuz.com]# chmod 777 ./config.inc.php  ./attachments/ ./forumdata/ ./forumdata/cache/  ./forumdata/templates/ ./forumdata/threadcaches/ ./forumdata/logs/ ./uc_client/data/cache/

然后一路下一项下一项:

wKioL1VGGraxC-PYAAK85n5hdTk062.jpg


wKiom1VGGeDhJJbtAAL67dZ0ub0474.jpg



ps:这篇博文写的很不满意,日后待改吧

你可能感兴趣的:(源代码,lamp,构架模型)