使用源代码包实现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,
因此需要事先对其进行升级。
1
$ rpm -qa | grep apr
apr-util-1.3.9-3.el6_0.1.x86_64
apr-1.3.9-5.el6_2.x86_64
$
(1):编译安装apr和apr-util:
1
$ tar -xf apr-1.5.0.tar.bz2
$ cd apr-1.5.0
$ ./configure --prefix=/usr/local/apr && make
$sudo make install
$ ls /usr/local/apr
binbuild-1includelib
$
(2):编译安装apr-util:
1
$ 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
$ sudo make install
$ ls /usr/local
aprapr-utilbinetcgamesincludeliblib64libexecsbinsharesrc
$
(3):使用系统光盘安装pcre-devel:
1
$ sudo mount -r /dev/sr0 /media/
$ 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... ###########################################
1:pcre-devel ###########################################
$
1.2)编译安装httpd-2.4.10.tar.bz2
1
$ tar -xf httpd-2.4.10.tar.bz2
$ cd 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
$ make
$ sudo make install
$ ls /usr/local/apache2410/
binbuildcgi-binconferrorhtdocsiconsincludelogsmanmanualmodules
$
1.3 )修改PATH路径,导出头文件,添加man手册
1
$ sudo vim /etc/profile.d/httpd.sh
export PATH=/usr/local/apache2410/bin:$PATH
:wq
$ sudo ln -sv /usr/local/apache2410/include /usr/include/http
"/usr/include/http" -> "/usr/local/apache2410/include"
$ sudo vim /etc/man.config
MANPATH /usr/local/apache2410/man
:wq
2 安装mariadb 二进制程序包
1
$ sudo tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local/
$ ls /usr/local
apache2410apr-utiletc includelib64 mariadb-5.5.43-linux-x86_64share
apr bin gameslib libexecsbin src
$ sudo ln -s /usr/local/mariadb-5.5.43-linux-x86_64//usr/local/mysql
$ cd /usr/local/mysql
$sudo groupadd -r mysql
$sudo useradd -g mysql -r mysql
$sudo chown -R root:mysql mariadb-5.5.43-linux-x86_64
$sudo chown -R mysql:mysql mariadb-5.5.43-linux-x86_64/data/
$sudo mkdir /etc/mysql/
$sudo cp /usr/local/mysql/support-files/my-medium.cnf /etc/mysql/my.cnf
$ sudo /usr/local/mysqlscripts/mysql_install_db --user=mysql --defaults-file=/etc/mysql/my.cnf
$sudo cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
$sudo chmod +x /etc/init.d/mysqld
$ sudo touch /etc/profile.d/mysql.sh
$ sudo vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
:wq
$ sudo ln -s /usr/local/mysql/include /usr/include/mysql
$ sudo vim /etc/man.config
MANPATH /usr/local/mysql/man
:wq
场景一:设定虚拟主机,提供phpamdin的登录(此场景下要求php编译为httpd的模块使用)
3.编译安装php
3.1)安装依赖的组件:libxml2-devel,bzip2-devel
1
$sudo yum -y install bzip2-devellibxml2-devel
3.2)编译安装:
1
# tar -xf php-5.4.40.tar.bz2
# cd 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/
# make && make install
3.3)添加配置文件
1
# 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
修改为:
DirectoryIndexindex.phpindex.html
5.做php同httpd的结合测试:
1
# touch /usr/local/apache2410/htdocs/index.php
# vim /usr/local/apache2410/htdocs/index.php
1 2 phpinfo();
3 ?>
#
6.做php同mariadb连通性测试
1
# service mysqld start
Starting MySQL
# vim /usr/local/apache2410/htdocs/index.php
$link = mysql_connect('127.0.0.1','root','');
if ($link)
echo "Success...";
else
echo "Failure...";
mysql_close();
?>
1
# apachectl restart
7 提供phpmyadmin文件。
1
#rm -rf /usr/local/apache2410/htdocs/index.php
# tar -xf phpMyAdmin-3.2.5-all-languages.tar.gz
# cp -a phpMyAdmin-3.2.5-all-languages/* /usr/local/apache2410/htdocs/
# apachectl restart
场景二。设定虚拟主机,安装discuz论坛(要求php以fpm形式同httpd结合)
8.恢复httpd的“纯净”状态
1
# apachectl stop
# rm -rf /usr/local/apache2410/conf/httpd.conf
# cp/usr/local/apache2410/conf/httpd.conf.bak /usr/local/apache2410/conf/httpd.conf
# apachectl restart
9.编译php(以fpm形式同httpd结合)
1
# ./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/
#make && make install
10.提供配置文件
1
# mkdir /etc/php
# cp php.ini-production/etc/php/php.ini
11.为php-fpm提供启动脚本
1
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
# chmod +x /etc/rc.d/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
#
12.为php-fpm提供配置文件:
1
# cp /usr/local/php5/etc/php-fpm.conf.default/usr/local/php5/etc/php-fpm.conf
13.编辑php-fpm的配置文件:
#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并作测试
1
# service php-fpm start
# netstat -tlpn | grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 27740/php-fpm
#
15.配置httpd使其支持fpm形式的php
1
# 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
1
#vim /usr/local/apache2410/conf/extra/httpd-vhosts.conf
#注释该文件中所有东东,添加下列内容
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
Options none
AllowOverride none
Require all granted
17.添加虚拟主机需要的文档
1
# cd /usr/local/apache2410/htdocs/
# mkdir mydiscuz.com
# unzip Discuz_7.2_FULL_SC_GBK.zip
# cp -a upload/* /usr/local/apache2410/htdocs/mydiscuz.com/
18 创建discuz论题使用库和用户
1
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:WindowsSystem32driversetchosts
#添加下列行
192.168.100.1 www.mydiscuz.com
然后浏览器像下面这样输入URL路径:
1
# chmod 777 ./config.inc.php./attachments/ ./forumdata/ ./forumdata/cache/./forumdata/templates/ ./forumdata/threadcaches/ ./forumdata/logs/ ./uc_client/data/cache/
然后一路下一项下一项:
ps:这篇博文写的很不满意,日后待改吧
页:
[1]