一、分别编译安装Nginx,php,MySQL服务器(略)
Nginx:192.168.216.102
Php:192.168.216.101
MySQL:192.168.216.100
二、对各服务器进行关联整合(只整理关键技术点)
1、整合nginx和php
(1)修改nginx配置文件
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root /var/www/html/www;
fastcgi_pass 192.168.216.100:9000; // 连接php服务器,让fastcgi协议关联nginx和php
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
(2)配置PHP服务器
创建php发布路径
[root@php ~]# mkdir -p /var/www/html/www
[root@php ~]# vim /var/www/html/www/index.php
phpinfo();
?>
~
创建nginx用户,以便可以用nginx服务器运行php
[root@php ~]# useradd -M -s /sbin/nologin nginx
[root@php www]# chown -R nginx:nginx /var/www/html/www
[root@php www]# ll -d /var/www/html/www
drwxr-xr-x 2 nginx nginx 4096 4月 15 13:56 /var/www/html/www
修改php-fpm配置文件 (对fastcgi的实现)
[root@php ~]# vim /usr/local/php5/etc/php-fpm.conf
user = nginx
group = nginx //更改用运行用户和用户组
listen = 192.168.216.100:9000 //更改监听网卡地址
测试nginx是否可以和php关联
测试成功
2、整合php和MySQL
(1)对php服务器进行配置
添加扩展模块
[root@php ~]# yum -y install mysql-devel
[root@php ~]# cd /usr/src/php-5.3.28/ext/mysql (因为是非本地登录mysql,所以要在php服务器安装mysql扩展工具)
[root@php mysql]# ls
config.m4 mysql.dsp package.xml php_mysql.lo tests
config.w32 mysql.mak php_mysql.c php_mysql.o
CREDITS mysql_mysqlnd.h php_mysql.h php_mysql_structs.h
生成.configure文件
[root@php mysql]# /usr/local/php5/bin/phpize (生成configure文件)
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
[root@php mysql]# ls
acinclude.m4 config.w32 package.xml
aclocal.m4 CREDITS php_mysql.c
autom4te.cache install-sh php_mysql.h
build ltmain.sh php_mysql.lo
config.guess Makefile.global php_mysql.o
config.h.in missing php_mysql_structs.h
config.m4 mkinstalldirs run-tests.php
config.sub mysql.dsp tests
configure mysql.mak
configure.in mysql_mysqlnd.h
[root@php mysql]# ln -s /usr/lib64/mysql/libmysqlclient.so.16.0.0 /usr/lib/libmysqlclient.so
编译安装
[root@php mysql]# ./configure --with-mysql --with-php-config=/usr/local/php5/bin/php-config
[root@php mysql]# ls
acinclude.m4 configure.in mkinstalldirs
aclocal.m4 config.w32 modules
autom4te.cache CREDITS mysql.dsp
build include mysql.mak
config.guess install-sh mysql_mysqlnd.h
config.h libmysqlclient.so package.xml
config.h.in libtool php_mysql.c
config.log ltmain.sh php_mysql.h
config.m4 Makefile php_mysql.lo
config.nice Makefile.fragments php_mysql.o
config.status Makefile.global php_mysql_structs.h
config.sub Makefile.objects run-tests.php
configure missing tests
[root@php mysql]# make && make install
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/
修改php配置文件,添加模块
[root@php mysql]# vim /usr/local/php5/php.ini
extensions=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/mysql.so (添加扩展模块)
[root@php ~]# cd /usr/local/php5/lib/php/extensions/no-debug-non-zts-20090626/
You have new mail in /var/spool/mail/root
[root@php no-debug-non-zts-20090626]# ls
mysql.so
在php服务器的发布网页上编写测试页
[root@php ~]# cd /var/www/html/www/
[root@php www]# vim index.php
$link=mysql_connect('192.168.216.101','root','123123');
if($link) echo "
mysql_close();
?>
附(网上的问题解决办法):
运行/usr/local/webserver/php/bin/phpize时出现:
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
根据网上的解决办法是:
# cd /usr/src
# wget http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
# tar -zvxf m4-1.4.9.tar.gz
# cd m4-1.4.9/
# ./configure && make && make install
# cd ../
# wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
# tar -zvxf autoconf-2.62.tar.gz
# cd autoconf-2.62/
# ./configure && make && make install
更简单的办法
# yum install m4
# yum install autoconf
(2)对MySQL服务器进行配置
进入数据库,查询用户信息
mysql> select user,host from mysql.user;
+----------+-----------------+
| user | host |
+----------+-----------------+
| root | 192.168.216.100 |
| runskyuc | 192.168.216.100 |
| root | ::1 |
| | localhost |
| root | localhost |
| | www.amber.com |
| root | www.amber.com |
+----------+-----------------+
7 rows in set (0.03 sec)
对指定IP进行远程登录授权
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"192.168.216.100" IDENTIFIED BY "123123" WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
三、测试
在网址url输入:192.168.216.102/index.php (在nginx下)
分离架构成功!