LAMP环境:httpd 2.4.6 + mysql-5.6.13 + php-5.4.22
系统环境:Amazon Linux (64-bit) (类似于RHEL6.4_x86_64)
一、编译安装httpd-2.4.6
1、安装httpd所依赖的软件包
$ sudo yum groupinstall Development Libraries Development tools $ sudo mkdir /usr/src/lamp
<1> 编译安装apr
$ cd /usr/src/lamp $ sudo wget http://down1.chinaunix.net/distfiles/apr-1.4.6.tar.bz2 $ sudo tar xf apr-1.4.6.tar.bz2 $ cd apr-1.4.6 $ sudo ./configure --prefix=/usr/local/apr $ sudo make $ sudo make install
<2> 编译安装apr-util
$ cd /usr/src/lamp $ sudo wget http://apache.spinellicreations.com//apr/apr-util-1.5.2.tar.bz2 $ sudo tar xf apr-util-1.5.2.tar.bz2 $ cd apr-util-1.5.2 $ sudo ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr $ sudo make $ sudo make install
<3> Yum安装pcre-devel
$ sudo yum -y install pcre-devel
2、编译安装httpd-2.4.6
$ cd /usr/src/lamp $ sudo wget http://mirror.cc.columbia.edu/pub/software/apache//httpd/httpd-2.4.6.tar.bz2 $ sudo tar xf httpd-2.4.6.tar.bz2 $ cd httpd-2.4.6 $ sudo ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=all --enable-mpms-shared=all --with-mpm=event $ sudo make $ sudo make install
如编译出现以下错误:
checking for OpenSSL version >= 0.9.7... FAILED configure: WARNING: OpenSSL version is too old
则需要安装最新的openssl和openssl-devel的rpm包,如默认已安装最新的openssl仍编译出错,查看openssl-devel是否未装,安装即解决问题
$ sudo yum install openssl-devel.x86_64
3、编辑httpd的主配置文件,添加Pid文件的路径
$ sudo vim /etc/httpd/httpd.conf PidFile "/var/run/httpd.pid"
4、为httpd提供sysv服务脚本
$ sudo vim /etc/rc.d/init.d/httpd
#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL
为此脚本添加执行权限:
$ sudo chmod +x /etc/rc.d/init.d/httpd
添加至服务列表:
$ sudo chkconfig --add httpd
5、修改PATH环境变量
$ sudo vim /etc/profile.d/httpd.sh export PATH=$PATH:/usr/local/apache/bin
6、启动httpd服务并测试
$ sudo service httpd start
二、安装mysql-5.6.13(通用二进制)
1、新建mysql用户
$ sudo groupadd -r mysql $ sudo useradd -g mysql -r -s /sbin/nologin -M -d /mydata/data mysql $ sudo chown -R mysql:mysql /mydata/data $ sudo mkdir /mydata/data -p $ sudo chown -R mysql:mysql /mydata/data
2、安装并初始化mysql-5.6.13
$ cd /usr/src/lamp $ sudo wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz $ sudo tar xf mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz -C /usr/local $ cd /usr/local/ $ sudo ln -sv mysql-5.6.13-linux-glibc2.5-x86_64 mysql $ cd mysql
$ sudo chown -R mysql:mysql . $ sudo scripts/mysql_install_db --user=mysql --datadir=/mydata/data $ sudo chown -R root .
3、为mysql提供主配置文件并编辑
$ cd /usr/local/mysql $ sudo cp support-files/my-default.cnf /etc/my.cnf
$ sudo vim /etc/my.cnf datadir=/mydata/data socket=/var/lib/mysql/mysql.sock log-error=/var/log/mysqld.log thread_concurrency = 2 innodb_file_per_table = 1
4、为mysql提供sysv服务脚本
$ cd /usr/local/mysql $ sudo cp support-files/mysql.server /etc/rc.d/init.d/mysqld
添加执行权限:
$ sudo chmod +x /etc/rc.d/init.d/mysqld
添加至服务列表:
$ sudo chkconfig --add mysqld $ sudo chkconfig mysqld on
5、编辑man配置文件,添加mysql的man文件路径
$ sudo vim /etc/man.config MANPATH /usr/local/mysql/man
6、将mysql的头文件输出至系统
$ sudo ln -sv /usr/local/mysql/include /usr/include/mysql
7、将mysql的库文件输出至系统库并重新载入
$ sudo echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf $ sudo ldconfig
8、修改PATH环境变量
$ sudo vim /etc/profile.d/mysqld.sh export PATH=$PATH:/usr/local/mysql/bin
9、启动mysql服务并测试
$ sudo service mysqld start
三、编译安装php-5.4.22
1、安装PHP所依赖的软件包
<1> RPM安装mcrypt
$ cd /usr/src/lamp $ sudo wget ftp://ftp.muug.mb.ca/mirror/fedora/epel/beta/6/x86_64/libmcrypt-2.5.8-9.el6.x86_64.rpm $ sudo wget http://www.gymglish.com/opensource/rpms/centos6-rpms/libmcrypt-devel-2.5.8-9.el6.x86_64.rpm $ sudo rpm -ivh lib*
<2> Yum安装libxml和bzip2的devel包
$ sudo yum install libxml2-devel.x86_64 $ sudo yum install bzip2-devel.x86_64
2、编译安装php-5.4.22
$ cd /usr/src/lamp $ sudo wget http://au1.php.net/distributions/php-5.4.22.tar.bz2 $ sudo tar xf php-5.4.22.tar.bz2 $ cd php-5.4.22 $ sudo ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --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-config-file-path=/etc/ --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts $ sudo make $ sudo make install
为php提供配置文件:
$ sudo cp php.ini-production /etc/php.ini
3、编辑httpd配置文件,使其支持php及默认主页
$ sudo vim /etc/httpd/httpd.conf
# 添加以下内容: AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps # 修改以下内容: DirectoryIndex index.php index.html
4、编辑httpd配置文件,新建虚拟主机
$ sudo vim /etc/httpd/httpd.conf Include /etc/httpd/extra/vhosts.conf
$ sudo vim /etc/httpd/extra/vhosts.confDocumentRoot "/mydata/web" ServerName cominggo.com ServerAlias www.cominggo.com Options none AllowOverride none Require all granted
5、重启httpd服务并测试
$ sudo servcie httpd configtest $ sudo service httpd restart
四、安装PHP加速器XCache(可选)
1、编译安装xcache-3.0.4
$ cd /usr/src/lamp $ sudo wget http://xcache.lighttpd.net/pub/Releases/3.0.4/xcache-3.0.4.tar.gz $ sudo tar xf xcache-3.0.4.tar.gz $ cd xcache-3.0.4 $ /usr/local/php/bin/phpize $ sudo /usr/local/php/bin/phpize $ sudo ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config $ sudo make $ sudo make install # 安装结果如下: Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20100525/
2、编辑xcache配置文件,整合PHP和XCache
$ sudo mkdir /etc/php.d $ sudo cp xcache.ini /etc/php.d/
$ sudo vim /etc/php.d/xcache.ini # 修改以下内容: extension = /usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
注:xcache自3.0版本开始不再支持使用zend_extension加载xcache
3、重启httpd服务并测试
$ sudo service httpd restart