实验拓扑图:
考虑到复杂的应用环境,我们将apache/php/mysql三种服务独立配置不同主机
我们知道apache与php有三种工作模式:
1、CGI
2、Modules
3、FastCGI
第一种现在用得很少了,性能差;对于动态页面全部由apache进程启用php解释器,然后再释放
第二种需要到本地磁盘加载Modules模块,性能比第一种好,但还是会有很多消耗资源
第三种php是一个独立应用,通过网络套接字接口,接收apache进程传过来的请求,所有php进程都由php自身管理
在php5.4以前,如果php需要连接mysql需要mysql头文件等,但在php5.4以后就不需要了,直接使用"--with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd"
由于apache并不处理动态页面,所以前端用户请求的php页面需要转发到php服务器上,这里就需要对apache做反向代理设置
当然了,我们在这里最好启用虚拟主机功能,这样方便管理。
编译安装Apache2.4.4
准备软件包:
apr-1.4.6.tar.gz
apr-util-1.4.1.tar.gz
httpd-2.4.4.tar.bz2
pcre-8.32.tar.gz
[root@station01 ~]# tar xf apr-1.4.6.tar.gz
[root@station01 ~]# cd apr-1.4.6
[root@station01 apr-1.4.6]# ./configure --prefix=/usr/local/apr
[root@station01 apr-1.4.6]# make &&make install
[root@station01 apr-1.4.6]# cd ..
[root@station01 ~]# tar xf apr-util-1.4.1.tar.gz
[root@station01 ~]# cd apr-util-1.4.1
[root@station01 apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@station01 apr-util-1.4.1]# make &&make install
[root@station01 apr-util-1.4.1]# cd
[root@station01 ~]# tar xf httpd-2.4.4.tar.bz2
[root@station01 ~]# cd httpd-2.4.4
[root@station01 httpd-2.4.4]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event
[root@station01 httpd-2.4.4]# make &&make install
[root@station01 httpd-2.4.4]# cp build/rpm/httpd.init /etc/init.d/httpd
[root@station01 httpd-2.4.4]# vim /etc/init.d/httpd
httpd=${HTTPD-/usr/local/apache/bin/httpd}
pidfile=${PIDFILE-/usr/local/apache/logs/${prog}.pid}
lockfile=${LOCKFILE-/var/lock/subsys/${prog}}
RETVAL=0
CONFFILE=/etc/httpd/httpd.conf
[root@station01 httpd-2.4.4]# chkconfig --add httpd
[root@station01 httpd-2.4.4]# chkconfig httpd on
[root@station01 httpd-2.4.4]# service httpd start
编译安装PHP5.4
准备软件包:
libmcrypt-2.5.7-5.el5.i386.rpm
libmcrypt-devel-2.5.7-5.el5.i386.rpm
php-5.4.13.tar.bz2
[root@station02 ~]# rpm -ivh *.rpm
[root@station02 ~]# tar xf php-5.4.13.tar.bz2
[root@station02 ~]# cd php-5.4.13
[root@station02 php-5.4.13]# ./configure --prefix=/usr/local/php --with-openssl --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-fpm
[root@station02 php-5.4.13]# make &&make install
[root@station02 php-5.4.13]# cp php.ini-production /etc/php.ini
[root@station02 php-5.4.13]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@station02 php-5.4.13]# chmod +x /etc/init.d/php-fpm
[root@station02 php-5.4.13]# chkconfig --add php-fpm
[root@station02 php-5.4.13]# chkconfig php-fpm on
[root@station02 php-5.4.13]# cd /usr/local/php/
[root@station02 php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@station02 php]# vim etc/php-fpm.conf
配置fpm的相关选项为你所需要的值,并启用pid文件:
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 8
pid = /usr/local/php/var/run/php-fpm.pid
[root@station02 php]# service php-fpm start
检查php-fpm是否正常
[root@station02 php]# netstat -tunlp |grep 9000
[root@station02 php]# ps -ef |grep php-fpm
二进制配置MySQL
[root@station03 ~]# tar xf mysql-5.5.28-linux2.6-i686.tar.gz -C /usr/local/
[root@station03 ~]# cd /usr/local/
[root@station03 local]# groupadd -g 3306 mysql
[root@station03 local]# useradd -g mysql -u 3306 mysql -s /sbin/nologin -M
[root@station03 local]# ln -s mysql-5.5.28-linux2.6-i686/ mysql
[root@station03 local]# cd mysql
[root@station03 mysql]# chown -R mysql.root .
[root@station03 mysql]# chown -R mysql.mysql data/
[root@station03 mysql]# scripts/mysql_install_db --datadir=/usr/local/mysql/data/ --user=mysql
[root@station03 mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@station03 mysql]# chmod +x /etc/init.d/mysqld
[root@station03 mysql]# chkconfig --add mysqld
[root@station03 mysql]# chkconfig mysqld on
[root@station03 mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@station03 mysql]# vim /etc/my.cnf
#如果data目录更改,则需要在mysqld段中注明
[root@station03 mysql]# service mysqld start
[root@station03 mysql]# vim /etc/profile.d/mysqld.sh
export PATH=$PATH:/usr/local/mysql/bin
[root@station03 mysql]# . /etc/profile.d/mysqld.sh
[root@station03 ~]# mysql
mysql> update user set password=password('asdasd') where user='root';
mysql> flush privileges;
Apache与PHP整合工作
[root@station01 ~]# vim /etc/httpd/httpd.conf
#DocumentRoot "/usr/local/apache/htdocs"
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Include /etc/httpd/extra/httpd-vhosts.conf
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
LoadModule proxy_module modules/mod_proxy.so
[root@station01 ~]# vim /etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/web/html"
ServerName "www.neo.com"
ErrorLog "logs/www.neo.com_error_log"
CustomLog "logs/www.neo.com_access_log" combined
<Directory "/web/html">
Options None
Require all granted
</Directory>
ProxyRequests Off
ProxyPassMatch ^/(.*)\.php$ fcgi://192.168.100.12:9000/web/html/$1.php
</VirtualHost>
[root@station01 ~]# mkdir /web/html -p
[root@station02 ~]# mkdir /web/html -p
[root@station01 ~]# vim /web/html/index.php
<?php
phpinfo();
?>
浏览器访问http://192.168.100.11/index.php
验证PHP是否能连上MySQL
[root@station02 ~]# vim /web/html/test.php
<?php
$link=mysql_connect('192.168.100.13','root','asdasd');
if(!$link)
echo "<h2>connect failed !!!!</h2> ";
else
echo "<h2>success ....</h2>";
mysql_close();
?>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。