首页 > 代码库 > CentOS6源码安装LAMP----基于fastcgi方式(2台机器)
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 单台机器
IP 192.168.9.176 php
IP 192.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,mysql,php
注:httpd2.4版本需要较新的apr和apr-util
注:新机器要初始化:参考http://wupengfei.blog.51cto.com/7174803/1955545
注:(生产环境一般包放内网ftp下载比较快,一般前端用nginx反向代理至后端apache,通过fastcgi连接php,mysql独立并做集群)
一、编译安装apache
1、#yum安装httpd依赖软件 [root@192-168-9-176 ~]# yum install -y gcc gcc-c++ libtool libtool-ltdl-devel make gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel patch [root@192-168-9-176 ~]# yum install -y curl-devel bzip2 pcre-devel zip2-devel bzip2-devel [root@192-168-9-176 ~]# yum install -y mcrypt-devel zlib-devel wget 2、#编译安装apr [root@192-168-9-176 ~]# cd /usr/local/src/ [root@192-168-9-176 src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.5.2.tar.bz2 [root@192-168-9-176 src]# tar xf apr-1.5.2.tar.bz2 [root@192-168-9-176 src]# cd apr-1.5.2 [root@192-168-9-176 apr-1.5.2]# ./configure --prefix=/usr/local/apr [root@192-168-9-176 apr-1.5.2]# make && make install 3、编译安装apr-util [root@192-168-9-176 apr-1.5.2]# cd /usr/local/src/ [root@192-168-9-176 src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2 [root@192-168-9-176 src]# tar xf apr-util-1.5.4.tar.bz2 [root@192-168-9-176 src]# cd apr-util-1.5.4 [root@192-168-9-176 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr [root@192-168-9-176 apr-util-1.5.4]# make && make install 4、编译安装httpd [root@192-168-9-176 apr-util-1.5.4]# useradd -s /sbin/nologin www [root@192-168-9-176 apr-util-1.5.4]# cd /usr/local/src/ [root@192-168-9-176 src]# wget http://apache.fayea.com//httpd/httpd-2.4.20.tar.bz2 [root@192-168-9-176 src]# tar xf httpd-2.4.20.tar.bz2 [root@192-168-9-176 src]# cd httpd-2.4.20 [root@192-168-9-176 httpd-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-176 httpd-2.4.20]# make [root@192-168-9-176 httpd-2.4.20]# make install [root@192-168-9-176 httpd-2.4.20]# sed -i ‘s/User daemon/User www/g‘ /usr/local/apache/conf/httpd.conf [root@192-168-9-176 httpd-2.4.20]# sed -i ‘s/Group daemon/Group www/g‘ /usr/local/apache/conf/httpd.conf [root@192-168-9-176 httpd-2.4.20]# sed -i "/ServerName/s/#ServerName.*/ServerName localhost/g" /usr/local/apache/conf/httpd.conf 6、启动方法 #/usr/local/apache/bin/apachectl -k start|reload|restart|stop 7、测试验证 [root@192-168-9-176 httpd-2.4.20]# curl -I http://192.168.9.176 HTTP/1.1 200 OK Date: Fri, 11 Aug 2017 15:22:43 GMT Server: Apache/2.4.20 (Unix) Last-Modified: Mon, 11 Jun 2007 18:53:14 GMT ETag: "2d-432a5e4a73a80" Accept-Ranges: bytes Content-Length: 45 Content-Type: text/html
二、编译安装MySQL
1、#下载安装包 [root@192-168-9-176 httpd-2.4.20]# cd /usr/local/src/ [root@192-168-9-176 src]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz 2、#建立运行mysql用户和组为系统账号 [root@192-168-9-176 src]# groupadd -r mysql [root@192-168-9-176 src]# useradd -r -g mysql -s /sbin/nologin mysql 3、#编译安装 [root@192-168-9-176 src]# yum install -y libaio libaio-devel numactl numactl-devel cmake ncurses-devel libxml2-devel libtool-ltdl-devel gcc-c++ autoconf automake bison zlib-devel [root@192-168-9-176 src]# tar xf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz [root@192-168-9-176 src]# mv mysql-5.6.37-linux-glibc2.12-x86_64 /usr/local/mysql #建议mysql使用独立设备独立目录,本实验只建立目录,独立设备请参考磁盘分区与挂载 [root@192-168-9-176 src]# mkdir -p /data0/mysql #更改属主属组 [root@192-168-9-176 src]# chown -R mysql.mysql /usr/local/mysql #初始化数据库 [root@192-168-9-176 src]# cd /usr/local/mysql [root@192-168-9-176 mysql]# ./scripts/mysql_install_db --datadir=/data0/mysql --user=mysql [root@192-168-9-176 mysql]# cp ./support-files/my-default.cnf /data0/mysql/my.cnf [root@192-168-9-176 mysql]# 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-176 mysql]# chown -R mysql.mysql /data0/mysql/ 4,启动: [root@192-168-9-176 mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data0/mysql/my.cnf & [root@192-168-9-176 mysql]# 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-176 mysql]# ./bin/mysql_secure_installation #导出头文件 [root@192-168-9-176 mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql #加载库文件 [root@192-168-9-176 mysql]# echo "/usr/local/mysql/lib/mysql/" >>/etc/ld.so.conf [root@192-168-9-176 mysql]# ldconfig [root@192-168-9-176 mysql]# echo "PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
三、编译安装PHP
1、#编译安装libmcrypt扩展 [root@192-168-9-168 src]# cd /usr/local/src/ [root@192-168-9-168 src]# wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz [root@192-168-9-168 src]# tar xf libmcrypt-2.5.7.tar.gz [root@192-168-9-168 src]# cd libmcrypt-2.5.7 [root@192-168-9-168 libmcrypt-2.5.7]# ./configure [root@192-168-9-168 libmcrypt-2.5.7]# make && make install 2、#编译安装freetds扩展 [root@c local]# cd /usr/local/src/ [root@c src]# wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz [root@192-168-9-168 src]# tar xf freetds-patched.tar.gz [root@192-168-9-168 src]# cd freetds-1.00.53/ [root@192-168-9-168 freetds-1.00.53]# ./configure --prefix=/usr/local/freetds --with-tdsver=7.4 --enable-msdblib [root@192-168-9-168 freetds-1.00.53]# make && make install [root@192-168-9-168 freetds-1.00.53]# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/ 4、#下载安装包 [root@192-168-9-168 src]# cd /usr/local/src/ [root@192-168-9-168 src]# wget http://cn2.php.net/distributions/php-5.6.22.tar.bz2 [root@192-168-9-168 src]# tar xf php-5.6.22.tar.bz2 [root@192-168-9-168 src]# cd php-5.6.22 [root@192-168-9-168 php-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-168 php-5.6.22]# make [root@192-168-9-168 php-5.6.22]# make install #为php提供配置文件 [root@192-168-9-168 php-5.6.22]# cp php.ini-development /usr/local/php/etc/php.ini 5、编辑apache配置文件httpd.conf,apache支持php [root@192-168-9-168 php-5.6.22]# sed -i ‘/LoadModule php5_module/ aAddType application/x-httpd-php-source .phps‘ /usr/local/apache/conf/httpd.conf [root@192-168-9-168 php-5.6.22]# sed -i ‘/LoadModule php5_module/ aAddType application/x-httpd-php .php .php5‘ /usr/local/apache/conf/httpd.conf [root@192-168-9-168 php-5.6.22]# sed -i ‘/DirectoryIndex/ s/index.html/index.php index.html/‘ /usr/local/apache/conf/httpd.conf #重启httpd [root@192-168-9-168 php-5.6.22]# /usr/local/apache/bin/apachectl -k restart 4、测试验证php "<?php phpinfo(); ?>" > /usr/local/apache/htdocs/index.php 5、浏览器访问: http://192.168.9.168 5、测试验证php连接数据库 [root@192-168-9-168 php-5.6.22]# vim index.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-168 php-5.6.22]# ab -c 100 -n 10000 四、测试Xcache为php加速 1、#编译安装 [root@192-168-9-168 htdocs]# cd /usr/local/src/ [root@192-168-9-168 src]# tar xf xcache-3.2.0.tar.bz2 [root@192-168-9-168 src]# cd xcache-3.2.0 [root@192-168-9-168 xcache-3.2.0]# /usr/local/php/bin/phpize [root@192-168-9-168 xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config [root@192-168-9-168 xcache-3.2.0]# make && make install 2、#编辑php.ini,整合php和xcache [root@192-168-9-168 xcache-3.2.0]# mkdir -p /etc/php.d [root@192-168-9-168 xcache-3.2.0]# cp xcache.ini /etc/php.d #重启apache [root@192-168-9-168 xcache-3.2.0]# apachectl -k restart #压力测试,看效果
CentOS6源码安装LAMP----基于fastcgi方式(2台机器)