源码搭建LAMP
软件包下载源:
搜狐镜像源: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/
freetds:http://download.csdn.net/download/xhu_eternalcc/7457555
官网:http://www.freetds.org/
实验环境:
CentOS6.5-x86_64单台机器
IP192.168.9.168
版本:
apr-1.5.2
apr-util-1.5.4
httpd-2.4.20
PHP-5.6.22
MysqL-5.6.32
说明,因为PHP要连接MysqL,所以安装顺序为apache,MysqL,PHP
注:httpd2.4版本需要较新的apr和apr-util
注:新机器要初始化:参考http://www.jb51.cc/article/p-wtbdmwnu-bqn.html
注:(生产环境一般包放内网ftp下载比较快,一般前端用Nginx反向代理至后端apache+PHP机器,MysqL独立并做集群)
一、编译安装apache
1、#yum安装httpd依赖软件 [root@192-168-9-168~]#yuminstall-ygccgcc-c++libtoollibtool-ltdl-devel\ makegd-develfreetype-devellibxml2-devel\ libjpeg-devellibpng-developenssl-develpatch [root@192-168-9-168~]#yuminstall-ycurl-develbzip2pcre-develzip2-develbzip2-devel [root@192-168-9-168~]#yuminstall-ymcrypt-develzlib-develwget 2、#编译安装apr [root@192-168-9-168~]#cd/usr/local/src/ [root@192-168-9-168src]#wgethttps://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.bz2 [root@192-168-9-168src]#tarxfapr-1.5.2.tar.bz2 [root@192-168-9-168src]#cdapr-1.5.2 [root@192-168-9-168apr-1.5.2]#./configure--prefix=/usr/local/apr [root@192-168-9-168apr-1.5.2]#make&&makeinstall 3、编译安装apr-util [root@192-168-9-168apr-1.5.2]#cd/usr/local/src/ [root@192-168-9-168src]#wgethttps://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2 [root@192-168-9-168src]#tarxfapr-util-1.5.4.tar.bz2 [root@192-168-9-168src]#cdapr-util-1.5.4 [root@192-168-9-168apr-util-1.5.4]#./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr [root@192-168-9-168apr-util-1.5.4]#make&&makeinstall 4、编译安装httpd [root@192-168-9-168apr-util-1.5.4]#useradd-s/sbin/nologinwww [root@192-168-9-168apr-util-1.5.4]#cd/usr/local/src/ [root@192-168-9-168src]#wgethttp://apache.fayea.com//httpd/httpd-2.4.20.tar.bz2 [root@192-168-9-168src]#tarxfhttpd-2.4.20.tar.bz2 [root@192-168-9-168src]#cdhttpd-2.4.20 [root@192-168-9-168httpd-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-168httpd-2.4.20]#make [root@192-168-9-168httpd-2.4.20]#makeinstall [root@192-168-9-168httpd-2.4.20]#sed-i's/Userdaemon/Userwww/g'/usr/local/apache/conf/httpd.conf [root@192-168-9-168httpd-2.4.20]#sed-i's/Groupdaemon/Groupwww/g'/usr/local/apache/conf/httpd.conf [root@192-168-9-168httpd-2.4.20]#sed-i"/ServerName/s/#ServerName.*/ServerNamelocalhost/g"/usr/local/apache/conf/httpd.conf 6、启动方法 [root@192-168-9-168httpd-2.4.20]#/usr/local/apache/bin/apachectl-kstart|reload|restart|stop 7、测试验证 [root@192-168-9-168httpd-2.4.20]#curl-Ihttp://192.168.9.168 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-168httpd-2.4.20]#cd/usr/local/src/ [root@192-168-9-168src]#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-168src]#groupadd-rMysqL [root@192-168-9-168src]#useradd-r-gMysqL-s/sbin/nologinMysqL 3、#编译安装 [root@192-168-9-168src]#yuminstall-ylibaiolibaio-develnumactlnumactl-develcmakencurses-devellibxml2-devellibtool-ltdl-develgcc-c++autoconfautomakebisonzlib-devel [root@192-168-9-168src]#tarxfMysqL-5.6.37-linux-glibc2.12-x86_64.tar.gz [root@192-168-9-168src]#mvMysqL-5.6.37-linux-glibc2.12-x86_64/usr/local/MysqL #建议MysqL使用独立设备独立目录,本实验只建立目录,独立设备请参考磁盘分区与挂载 [root@192-168-9-168src]#mkdir-p/data0/MysqL #更改属主属组 [root@192-168-9-168src]#chown-RMysqL.MysqL/usr/local/MysqL #初始化数据库 [root@192-168-9-168src]#cd/usr/local/MysqL [root@192-168-9-168MysqL]#./scripts/MysqL_install_db--datadir=/data0/MysqL--user=MysqL [root@192-168-9-168MysqL]#cp./support-files/my-default.cnf/data0/MysqL/my.cnf [root@192-168-9-168MysqL]#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-168MysqL]#chown-RMysqL.MysqL/data0/MysqL/ 4,启动: [root@192-168-9-168MysqL]#/usr/local/MysqL/bin/MysqLd_safe--defaults-file=/data0/MysqL/my.cnf& [root@192-168-9-168MysqL]#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-168MysqL]#./bin/MysqL_secure_installation #导出头文件 [root@192-168-9-168MysqL]#ln-sv/usr/local/MysqL/include//usr/include/MysqL #加载库文件 [root@192-168-9-168MysqL]#echo"/usr/local/MysqL/lib/MysqL/">>/etc/ld.so.conf [root@192-168-9-168MysqL]#ldconfig [root@192-168-9-168MysqL]#echo"PATH=$PATH:/usr/local/MysqL/bin/">>/etc/profile
三、编译安装PHP
1、#编译安装libmcrypt扩展 [root@192-168-9-168src]#cd/usr/local/src/ [root@192-168-9-168src]#wgetftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz [root@192-168-9-168src]#tarxflibmcrypt-2.5.7.tar.gz [root@192-168-9-168src]#cdlibmcrypt-2.5.7 [root@192-168-9-168libmcrypt-2.5.7]#./configure [root@192-168-9-168libmcrypt-2.5.7]#make&&makeinstall 2、#编译安装freetds扩展 [root@clocal]#cd/usr/local/src/ [root@csrc]#wgetftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz [root@192-168-9-168src]#tarxffreetds-patched.tar.gz [root@192-168-9-168src]#cdfreetds-1.00.53/ [root@192-168-9-168freetds-1.00.53]#./configure--prefix=/usr/local/freetds--with-tdsver=7.4--enable-msdblib [root@192-168-9-168freetds-1.00.53]#make&&makeinstall [root@192-168-9-168freetds-1.00.53]#exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/ 4、#下载安装包 [root@192-168-9-168src]#cd/usr/local/src/ [root@192-168-9-168src]#wgethttp://cn2.PHP.net/distributions/PHP-5.6.22.tar.bz2 [root@192-168-9-168src]#tarxfPHP-5.6.22.tar.bz2 [root@192-168-9-168src]#cdPHP-5.6.22 [root@192-168-9-168PHP-5.6.22]#./configure--prefix=/usr/local/PHP\ --with-MysqL=/usr/local/MysqL/\ --with-openssl\ --with-MysqLi=/usr/local/MysqL/bin/MysqL_config\ --enable-mbstring\ --with-freetype-dir\ --with-jpeg-dir\ --with-png-dir\ --with-zlib\ --with-libxml-dir=/usr/\ --enable-xml\ --enable-sockets\ --with-apxs2=/usr/local/apache/bin/apxs\ --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,这样本机就可以不用安装MysqL和MysqL开发包。5.4已经是默认设置。 如:--with-MysqL=MysqLnd--with-pdo-MysqL=MysqLnd--with-MysqLi=MysqLnd [root@192-168-9-168PHP-5.6.22]#make [root@192-168-9-168PHP-5.6.22]#makeinstall #为PHP提供配置文件 [root@192-168-9-168PHP-5.6.22]#cpPHP.ini-development/usr/local/PHP/etc/PHP.ini 5、编辑apache配置文件httpd.conf,apache支持PHP [root@192-168-9-168PHP-5.6.22]#sed-i'/LoadModulePHP5_module/aAddTypeapplication/x-httpd-PHP-source.PHPs'/usr/local/apache/conf/httpd.conf [root@192-168-9-168PHP-5.6.22]#sed-i'/LoadModulePHP5_module/aAddTypeapplication/x-httpd-PHP.PHP.PHP5'/usr/local/apache/conf/httpd.conf [root@192-168-9-168PHP-5.6.22]#sed-i'/DirectoryIndex/s/index.html/index.PHPindex.html/'/usr/local/apache/conf/httpd.conf #重启httpd [root@192-168-9-168PHP-5.6.22]#/usr/local/apache/bin/apachectl-krestart 4、测试验证PHP "<?PHP PHPinfo(); ?>">/usr/local/apache/htdocs/index.PHP 5、浏览器访问: http://192.168.9.168 5、测试验证PHP连接数据库 [root@192-168-9-168PHP-5.6.22]#vimindex.PHP <?PHP $link=MysqL_connect('127.0.0.1','root','123456'); if($link) echo"Success..."; else echo"Failure..."; MysqL_close() ?> #浏览器访问 http://192.168.9.168 6、#ab压力测试 [root@192-168-9-168PHP-5.6.22]#ab-c100-n10000 四、测试Xcache为PHP加速 1、#编译安装 [root@192-168-9-168htdocs]#cd/usr/local/src/ [root@192-168-9-168src]#tarxfxcache-3.2.0.tar.bz2 [root@192-168-9-168src]#cdxcache-3.2.0 [root@192-168-9-168xcache-3.2.0]#/usr/local/PHP/bin/PHPize [root@192-168-9-168xcache-3.2.0]#./configure--enable-xcache--with-PHP-config=/usr/local/PHP/bin/PHP-config [root@192-168-9-168xcache-3.2.0]#make&&makeinstall 2、#编辑PHP.ini,整合PHP和xcache [root@192-168-9-168xcache-3.2.0]#mkdir-p/etc/PHP.d [root@192-168-9-168xcache-3.2.0]#cpxcache.ini/etc/PHP.d #重启apache [root@192-168-9-168xcache-3.2.0]#apachectl-krestart #压力测试,看效果原文链接:/centos/376369.html