6----CentOS6源码安装LAMP----基于fastcgi方式(2台机器)

前端之家收集整理的这篇文章主要介绍了6----CentOS6源码安装LAMP----基于fastcgi方式(2台机器)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

源码搭建LAMP

CentOS6源码安装LAMP----基于fastcgi方式(2台机器)

软件包下载源:

搜狐镜像源:http://mirrors.sohu.com/

apache下载网:http://mirror.bit.edu.cn/apache/

pcre官网:http://www.pcre.org/

apr官网:http://apr.apache.org/

apache官网:http://httpd.apache.org/

MysqL官网:https://www.mysql.com/

PHP官网:http://php.net/

freetds:http://download.csdn.net/download/xhu_eternalcc/7457555

官网:http://www.freetds.org/


实验环境:

CentOS6.5-x86_64单台机器

IP192.168.9.176 PHP

IP192.168.9.225 apache+MysqL

版本:

apr-1.5.2

apr-util-1.5.4

httpd-2.4.20

PHP-5.6.22

MysqL-5.6.32


说明,因为PHP要连接MysqL,所以安装顺序为apache,MysqLPHP

注:httpd2.4版本需要较新的apr和apr-util



注:新机器要初始化:参考http://www.jb51.cc/article/p-wtbdmwnu-bqn.html

注:(生产环境一般包放内网ftp下载比较快,一般前端用Nginx反向代理至后端apache,通过fastcgi连接PHPMysqL独立并做集群)


一、编译安装apache
1、#yum安装httpd依赖软件
[root@192-168-9-176~]#yuminstall-ygccgcc-c++libtoollibtool-ltdl-devel\
makegd-develfreetype-devellibxml2-devel\
libjpeg-devellibpng-developenssl-develpatch
[root@192-168-9-176~]#yuminstall-ycurl-develbzip2pcre-develzip2-develbzip2-devel
[root@192-168-9-176~]#yuminstall-ymcrypt-develzlib-develwget

2、#编译安装apr
[root@192-168-9-176~]#cd/usr/local/src/
[root@192-168-9-176src]#wgethttps://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.bz2
[root@192-168-9-176src]#tarxfapr-1.5.2.tar.bz2
[root@192-168-9-176src]#cdapr-1.5.2
[root@192-168-9-176apr-1.5.2]#./configure--prefix=/usr/local/apr
[root@192-168-9-176apr-1.5.2]#make&&makeinstall

3、编译安装apr-util
[root@192-168-9-176apr-1.5.2]#cd/usr/local/src/
[root@192-168-9-176src]#wgethttps://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2
[root@192-168-9-176src]#tarxfapr-util-1.5.4.tar.bz2
[root@192-168-9-176src]#cdapr-util-1.5.4
[root@192-168-9-176apr-util-1.5.4]#./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr
[root@192-168-9-176apr-util-1.5.4]#make&&makeinstall

4、编译安装httpd
[root@192-168-9-176apr-util-1.5.4]#useradd-s/sbin/nologinwww
[root@192-168-9-176apr-util-1.5.4]#cd/usr/local/src/
[root@192-168-9-176src]#wgethttp://apache.fayea.com//httpd/httpd-2.4.20.tar.bz2
[root@192-168-9-176src]#tarxfhttpd-2.4.20.tar.bz2
[root@192-168-9-176src]#cdhttpd-2.4.20
[root@192-168-9-176httpd-2.4.20]#./configure--prefix=/usr/local/apache\
--with-apr=/usr/local/apr\
--with-apr-util=/usr/local/apr-util/\
--enable-so\
--enable-ssl\
--enable-cgi\
--enable-rewrite\
--with-zlib\
--with-pcre\
--enable-modules=most\
--enable-mpms-shared=all\
--with-mpm=prefork
[root@192-168-9-176httpd-2.4.20]#make
[root@192-168-9-176httpd-2.4.20]#makeinstall
[root@192-168-9-176httpd-2.4.20]#sed-i's/Userdaemon/Userwww/g'/usr/local/apache/conf/httpd.conf
[root@192-168-9-176httpd-2.4.20]#sed-i's/Groupdaemon/Groupwww/g'/usr/local/apache/conf/httpd.conf
[root@192-168-9-176httpd-2.4.20]#sed-i"/ServerName/s/#ServerName.*/ServerNamelocalhost/g"/usr/local/apache/conf/httpd.conf


6、启动方法
#/usr/local/apache/bin/apachectl-kstart|reload|restart|stop

7、测试验证
[root@192-168-9-176httpd-2.4.20]#curl-Ihttp://192.168.9.176
HTTP/1.1200OK
Date:Fri,11Aug201715:22:43GMT
Server:Apache/2.4.20(Unix)
Last-Modified:Mon,11Jun200718:53:14GMT
ETag:"2d-432a5e4a73a80"
Accept-Ranges:bytes
Content-Length:45
Content-Type:text/html


二、编译安装MysqL

1、#下载安装包
[root@192-168-9-176httpd-2.4.20]#cd/usr/local/src/
[root@192-168-9-176src]#wgethttps://cdn.MysqL.com//Downloads/MysqL-5.6/MysqL-5.6.37-linux-glibc2.12-x86_64.tar.gz

2、#建立运行MysqL用户和组为系统账号
[root@192-168-9-176src]#groupadd-rMysqL
[root@192-168-9-176src]#useradd-r-gMysqL-s/sbin/nologinMysqL

3、#编译安装
[root@192-168-9-176src]#yuminstall-ylibaiolibaio-develnumactlnumactl-develcmakencurses-devellibxml2-devellibtool-ltdl-develgcc-c++autoconfautomakebisonzlib-devel
[root@192-168-9-176src]#tarxfMysqL-5.6.37-linux-glibc2.12-x86_64.tar.gz
[root@192-168-9-176src]#mvMysqL-5.6.37-linux-glibc2.12-x86_64/usr/local/MysqL
#建议MysqL使用独立设备独立目录,本实验只建立目录,独立设备请参考磁盘分区与挂载
[root@192-168-9-176src]#mkdir-p/data0/MysqL
#更改属主属组
[root@192-168-9-176src]#chown-RMysqL.MysqL/usr/local/MysqL
#初始化数据库
[root@192-168-9-176src]#cd/usr/local/MysqL
[root@192-168-9-176MysqL]#./scripts/MysqL_install_db--datadir=/data0/MysqL--user=MysqL
[root@192-168-9-176MysqL]#cp./support-files/my-default.cnf/data0/MysqL/my.cnf
[root@192-168-9-176MysqL]#echo"basedir=/usr/local/MysqL
datadir=/data0/MysqL
port=3306
server_id=1000
socket=/tmp/MysqL.sock">>/data0/MysqL/my.cnf
[root@192-168-9-176MysqL]#chown-RMysqL.MysqL/data0/MysqL/
4,启动:
[root@192-168-9-176MysqL]#/usr/local/MysqL/bin/MysqLd_safe--defaults-file=/data0/MysqL/my.cnf&
[root@192-168-9-176MysqL]#echo"/usr/local/MysqL/bin/MysqLd_safe--defaults-file=/data0/MysqL/my.cnf&">>/etc/rc.d/rc.local

6、#安全初始化
#安全验证初始化,设置root用户密码,删除匿名用户禁止root用户远程连接,删除test库
[root@192-168-9-176MysqL]#./bin/MysqL_secure_installation
#导出头文件
[root@192-168-9-176MysqL]#ln-sv/usr/local/MysqL/include//usr/include/MysqL
#加载库文件
[root@192-168-9-176MysqL]#echo"/usr/local/MysqL/lib/MysqL/">>/etc/ld.so.conf
[root@192-168-9-176MysqL]#ldconfig
[root@192-168-9-176MysqL]#echo"PATH=$PATH:/usr/local/MysqL/bin/">>/etc/profile


三、编译安装PHP

1、#编译安装libmcrypt扩展
[root@192-168-9-176~]#yuminstall-ygccgcc-c++libtoollibtool-ltdl-devel\
makegd-develfreetype-devellibxml2-devel\
libjpeg-devellibpng-developenssl-develpatch
[root@192-168-9-176~]#yuminstall-ycurl-develbzip2pcre-develzip2-develbzip2-devel
[root@192-168-9-176~]#yuminstall-ymcrypt-develzlib-develwgetMysqLMysqL-devel
[root@192-168-9-225~]#cd/usr/local/src/
[root@192-168-9-225src]#wgetftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
[root@192-168-9-225src]#tarxflibmcrypt-2.5.7.tar.gz
[root@192-168-9-225src]#cdlibmcrypt-2.5.7
[root@192-168-9-225libmcrypt-2.5.7]#./configure
[root@192-168-9-225libmcrypt-2.5.7]#make&&makeinstall

2、#编译安装freetds扩展
[root@192-168-9-225local]#cd/usr/local/src/
[root@192-168-9-225src]#wgetftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
[root@192-168-9-225src]#tarxffreetds-patched.tar.gz
[root@192-168-9-225src]#cdfreetds-1.00.53/
[root@192-168-9-225freetds-1.00.53]#./configure--prefix=/usr/local/freetds--with-tdsver=7.4--enable-msdblib
[root@192-168-9-225freetds-1.00.53]#make&&makeinstall
[root@192-168-9-225freetds-1.00.53]#exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/
[root@192-168-9-225freetds-1.00.53]#echo"exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/">>/etc/profile

3、#下载安装包
[root@192-168-9-225src]#cd/usr/local/src/
[root@192-168-9-225src]#wgethttp://cn2.PHP.net/distributions/PHP-5.6.22.tar.bz2
[root@192-168-9-225src]#tarxfPHP-5.6.22.tar.bz2
[root@192-168-9-225src]#cdPHP-5.6.22
[root@192-168-9-225PHP-5.6.22]#./configure--prefix=/usr/local/PHP\
--with-MysqL=MysqLnd\
--with-pdo-MysqL=MysqLnd\
--with-MysqLi=MysqLnd\
--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-mssql=/usr/local/freetds\
--with-bz2\
--enable-maintainer-zts\
--with-curl\
--enable-ftp\
--enable-bcmath\
--with-gd\
--with-freetype-dir\
--enable-gd-native-ttf\
--with-iconv-dir\
--enable-mbstring\
--enable-calendar\
--with-gettext\
--enable-dom\
--enable-fpm
#说明:如果PHP5.3以上的版本,为了链接数据库,可以指定MysqLnd,这样本机就可以不用安装MysqLMysqL开发包。5.4已经是默认设置。
如:--with-MysqL=MysqLnd--with-pdo-MysqL=MysqLnd--with-MysqLi=MysqLnd
[root@192-168-9-225PHP-5.6.22]#make
[root@192-168-9-225PHP-5.6.22]#makeinstall

4/#为PHP提供配置文件
[root@192-168-9-225PHP-5.6.22]#cpPHP.ini-production/etc/PHP.ini
[root@192-168-9-225PHP-5.6.22]#cpsapi/fpm/init.d.PHP-fpm/etc/rc.d/init.d/PHP-fpm
[root@192-168-9-225PHP-5.6.22]#chmod+x/etc/rc.d/init.d/PHP-fpm
[root@192-168-9-225PHP-5.6.22]#chkconfig--addPHP-fpm
[root@192-168-9-225PHP-5.6.22]#chkconfigPHP-fpmon
[root@192-168-9-225PHP-5.6.22]#cp/usr/local/PHP/etc/PHP-fpm.conf.default/usr/local/PHP/etc/PHP-fpm.conf
[root@192-168-9-225PHP-5.6.22]#vim/usr/local/PHP/etc/PHP-fpm.conf
#配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):
listen=192.168.9.225:9000
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@192-168-9-225~]#mkdir-pv/data0/web_root/domain/www
[root@192-168-9-225~]#echo"<?PHP
PHPinfo();
?>">/data0/web_root/domain/www/index.PHP
[root@192-168-9-225PHP-5.6.22]#servicePHP-fpmstart
5、编辑apache配置文件httpd.conf,apache支持PHP
#启用httpd的相关模块
[root@192-168-9-176~]#vim/usr/local/apache/conf/httpd.conf
#在Apachehttpd2.4以后已经专门有一个模块针对FastCGI的实现,此模块为mod_proxy_fcgi.so,它其实是作为mod_proxy.so模块的扩充,因此,这两个模块都要加载
LoadModuleproxy_modulemodules/mod_proxy.so
LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so
#配置虚拟主机支持使用fcgi
#注释根,打开虚拟主机
#DocumentRoot"/usr/local/apache/htdocs"
Includeconf/extra/vhosts/*.conf
#编辑apache配置文件httpd.conf,让apache能识别PHP格式的页面,并支持PHP格式的主页
#添加如下二行
AddTypeapplication/x-httpd-PHP.PHP
AddTypeapplication/x-httpd-PHP-source.PHPs

#定位至DirectoryIndexindex.html
修改为:
DirectoryIndexindex.PHPindex.html

[root@192-168-9-176~]#mkdir-p/usr/local/apache/conf/extra/vhosts/
[root@192-168-9-176~]#vim/usr/local/apache/conf/extra/vhosts/domain.conf
#ProxyRequestsOff:关闭正向代理
#ProxyPassMatch:把以.PHP结尾的文件请求发送到PHP-fpm进程,PHP-fpm至少需要知道运行的目录和URI,所以这里直接在fcgi://192.168.0.17:9000后指明了这两个参数,其它的参数的传递已经被mod_proxy_fcgi.so进行了封装,不需要手动指定。
<VirtualHost*:80>
ServerAdminwebadmin@a.com
DocumentRoot"/data0/web_root/domain/www"
DirectoryIndexindex.PHPindex.html
ServerNamewww.domain.com
ServerAliasdomain.com
ErrorLog"logs/www.domain.com-error_log"
CustomLog"logs/www.domain.com-access_log"common
<Directory"/data0/web_root/domain/www">
OptionsNone
Requireallgranted
</Directory>
ProxyRequestsOff
ProxyPassMatch^/(.*\.PHP)$fcgi://192.168.9.225:9000/data0/web_root/domain/www/$1
</VirtualHost>

#重启httpd
[root@192-168-9-176~]#/usr/local/apache/bin/apachectl-krestart

6、浏览器访问:
http://192.168.9.176
7、测试验证PHP连接数据库
[root@192-168-9-225PHP-5.6.22]#vimindex.PHP

<?PHP
$link=MysqL_connect('192.168.9.176','root','123456');
if($link)
echo"Success...";
else
echo"Failure...";
MysqL_close()
?>
#浏览器访问
http://192.168.9.176

6、#ab压力测试
[root@192-168-9-276PHP-5.6.22]#ab-c100-n10000
原文链接:https://www.f2er.com/centos/376368.html

猜你在找的CentOS相关文章