一、编译安装apache
1、解决依赖关系
安装开发环境,安装pcre-devel
# yum -y groupinstall "Development tools" "Server Platform Development" # yum -y install pcre-devel
httpd-2.4依赖于apr-1.4+和apr-util-1.4+,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。下载地址:http://apr.apache.org/download.cgi
(1)编译安装apr
# tar xf apr-1.6.3.tar.gz # cd apr-1.6.3 # ./configure --prefix=/usr/local/apr # make && make install
(2) 编译安装apr-util
apr-util-1.6.1需要expat开发库
# yum -y install expat-devel # tar xf apr-util-1.6.1.tar.gz # cd apr-util-1.6.1 # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr # make && make install
2、编译安装httpd-2.4.29
# groupadd -r apache # useradd -r -g apache apache # tar xf httpd-2.4.29.tar.gz # cd httpd-2.4.29 # ./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=most --enable-mpms-shared=all --with-mpm=event # make && make install --enable-so:启动sharedobject共享对象 --enable-ssl:启用ssl,借助于此可以实现HTTPS访问 --enable-cgi:启用CGI,可以实现CGI脚本执行 --enable-rewrite;启用Rewrite重写,能够实现诸如301重定向的功能,依赖PCRE包 --with-zlib:启用zlib压缩 --with-pcre:启用PCRE --with-apr:指定apr的路径,httpd2.4依赖apr1.4版本以上,所以要指明 --with-apr-util:指定apr-util的路径,同上 --enable-modules:启用哪些模块加载,most尽可能多的 --enable-mpms-shared=all:http2.4上prefork、worker、event是模块化的,可以动态加载 --with-mpm=event:指明默认的httpd2.4 MPM,即运行在event模型下
3、修改httpd的主配置文件,设置其Pid文件的路径
编辑/etc/httpd/httpd.conf,添加如下行即可:
PidFile "/var/run/httpd.pid"
4、提供SysV服务脚本/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
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
也可以复制其他主机上的/etc/rc.d/init.d/httpd文件进行修改:
apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd}
根据实际情况修改pidfile位置
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
5、导出二进制程序目录至PATH环境变量中
# vim /etc/profile.d/http.sh export PATH=$PATH:/usr/local/apache/bin # source /etc/profile.d/http.sh
6、导出头文件
# ln -sv /usr/local/apache/include /usr/include/httpd
7、导出帮助手册
# vim /etc/man.config MANPATH /usr/local/apache/man
接下来就可以启动服务进行测试了。
二、编译安装mysql-5.6.38
1、安装cmake
安装依赖并编译安装cmake
# yum -y install ncurses-devel # tar xf cmake-2.8.4.tar.gz # cd cmake-2.8.4 # ./bootstrap # make && make install
2、编译安装mysql-5.6.38
# tar xf mysql-5.6.38.tar.gz # cd mysql-5.6.38 # cmake . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.38 \ -DMYSQL_DATADIR=/data/mysql \ -DWITH_DEBUG=OFF \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DENABLE_DTRACE=OFF \ -DWITH_INNOBASE_STORAGE_ENGINE=ON # make && make instal
3、创建mysql用户和mysql组
# groupadd -r -g 3306 mysql # useradd -r -g 3306 -u 3306 mysql
4、初始化mysql
# cd /usr/local/mysql-5.6.38/ # chown -R root.mysql ./* # scripts/mysql_install_db --user=mysql --datadir=/data/mysql
5、为mysql提供主配置文件:
# cp support-files/my-default.cnf /etc/my.cnf
6、为mysql提供sysv服务脚本:
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld # chmod +x /etc/rc.d/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on
7、输出mysql的头文件至系统头文件路径/usr/include:
# ln -sv /usr/local/mysql-5.6.38/include /usr/include/mysql
8、输出mysql的库文件给系统库查找路径:
# echo '/usr/local/mysql-5.6.38/lib/' > /etc/ld.so.conf.d/mysql.conf
9、修改PATH环境变量,让系统可以直接使用mysql的相关命令
# vim /etc/profile.d/mysql.sh export PATH=$PATH:/usr/local/mysql-5.6.38/bin # source /etc/profile.d/mysql.sh
而后就可以启动服务测试使用了。
三、编译安装php-5.6.32
1、解决依赖关系:
请配置好yum源(系统安装源及epel源)后执行如下命令:
# yum -y groupinstall "Desktop Platform Development" # yum -y install bzip2-devel libmcrypt-devel libxml2-devel libpng12-devel freetype-devel
2、编译安装php-5.6.32
# tar xf php-5.6.32.tar.gz # cd php-5.6.32 # ./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-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts # make && make install --with-mysql=/usr/local/mysql:mysql安装目录,对mysql的支持 --with-openssl:openssl的支持,加密传输时用到的 --with-mysqli=/usr/local/mysql/bin/mysql_config:mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,而且还可以使访问数据库工作变得更加稳定。 --enable-mbstring:多字节,字符串的支持 --with-freetype-dir:打开对freetype字体库的支持 --with-jpeg-dir:打开对jpeg图片的支持 --with-png-dir:打开对png图片的支持 --with-zlib:打开zlib库的支持 --with-libxml-dir=/usr:打开libxml2库的支持 --enable-xml:支持xml语言的支持 --enable-sockets:打开sockets支持 --with-apxs2=/usr/local/apache/bin/apxs:整合apache,apxs功能是使用mod_so中的LoadModule指令,加载指定模块到apache,要求apache要打开SO模块 --with-mcrypt:mcrypt算法的扩展 --with-config-file-path=/etc:指定php.ini位置 --with-config-file-scan-dir=/etc/php.d:指定以ini结尾的扩展配置文件位置 --with-bz2:打开对bz2文件的支持 --enable-maintainer-zts --enable-bcmath --with-gd
3、为php提供配置文件:
# cp php.ini-production /etc/php.ini
4、编辑apache配置文件httpd.conf,以apache支持php
# vim /etc/httpd/httpd.conf 1、添加如下二行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 2、定位至DirectoryIndex index.html 修改为: DirectoryIndex index.php index.html
5、测试页面index.php示例如下:
<?php $link = mysql_connect('127.0.0.1','root',''); if ($link) echo "Success..."; else echo "Failure..."; mysql_close(); phpinfo(); ?>
而后重新启动httpd,或让其重新载入配置文件即可测试php是否已经可以正常使用。