httpd 2.4.9 + mysql-5.5.3 + php-5.4.26
httpd-2.4.9需要较新的版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种:一种是通过源码编译安装,一种是直接升级rpm包。这里选择使用编译安装 它的作用是为了简化跨平台,应用程序之间的管理,例如php-fpm、mysql
# tar xf apr-1.5.0.tar.bz2# cd apr-1.5.0# ./configure --prefix=/usr/lcoal/apr# make && make install
# tar xf apr-util-1.5.3.tar.bz2# cd apr-util-1.5.3# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr# make && make install
httpd-2.4.9编译过程也要依赖于pcre-devel软件包,需要事先安装。此软件包系统光盘自带,因此,找到并安装即可
~]# tar xf httpd-2.4.9.tar.bz2
~]# cd httpd-2.4.9
~]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr --with-apr-util=/usr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
~]# make -j 4 && make install
/usr/local/apache24/build/config.nice:记录了安装时候所执行的命令
--prefix=/usr/local/apache24指定安装路径--sysconfdir=/etc/httpd24更改定义配置文件的安装路径,不指明就在安装路径下--enable-so支持DSO机制 --enable-ssl支持ssl功能--enable-cgi支持cgi机制--enable-rewrite支持URL重写--with-zlib依赖于Zlib提供压缩库实现页面压缩 --with-pcre支持pcre扩展的模式,更为强大的正则表达式功能--with-apr=/usr/local/apr依赖于指定路径的apr--with-apr-util=/usr/local/apr-util依赖于指定路径的apr-util --enable-modules=most启用模块,可以给模块列表,可以most大多数常用模块,也可以All --enable-mpms-shared=all将所有的MPM模块编译出来--with-mpm=prefork指定启动时默认的MPM模块
(1)构建MPM为静态模块
在全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本 时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 ./httpd -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。
(2)构建 MPM 为动态模块
在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用--enable-mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令内容可以选择不同的MPM。
/etc/httpd/httpd.conf
PidFile "/var/run/httpd.pid" 定义pid路径
#DocumentRoot 注释
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so 启用
LoadModule proxy_module modules/mod_proxy.so 启用反向代理模块
Include /etc/httpd/extra/httpd-mpm.conf 启用
Include /etc/httpd/extra/httpd-vhosts.conf 启用
AddType application/x-httpd-php .php 添加,将所有的以php结尾的文件送给php服务器解决
AddType application/x-httpd-php-source .phps 添加
/etc/httpd/extra/httpd-vhosts.conf
DirectoryIndex index.php index.html
<VirtualHost 172.18.64.60:80>
ServerName www.phpadmin.com
DocumentRoot "/apps/vhosts/www"
ProxyRequests Off
proxyPassMatch ^/(.*\.php)$ fcgi://172.18.64.61:9000/apps/vhosts/$1
<Directory "/apps/vhosts/www">
Options None
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
此处要在对应目录下创建对应的网页文件
方法一:手动指明路径启动
~]# /usr/local/apache/bin/apachectl start 指明编译安装路径
方法二:修改环境变量,手动指定绝对路径
~]# vim /etv/profile.d/httpd.sh
~]# export PATH=/usr/local/apache/bin:$PATH
~]# apachectl restart
方法三:
~]# cd /etc/rc.d/init.d/
~]# vim httpd
~]# chkconfig --add httpd
~]# service httpd restart
#!/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
mariadb-5.5.46-linux-x86_64.tar.gz 指定平台的是二进制包
mariadb-5.5.46.tar.gz 没有指定平台的是源码包
新建一个逻辑卷,并将其挂载至特定目录即可。而后将逻辑卷挂载到目录/mydata/data
~]# groupadd -r mysql ~]# useradd -g -r -s /sbin/nologin -M -d /mydata/data mysql <--创建一个系统用户mysql,属于mysql组,默认shell为。。不创建家目录,并指定家目录为/mydata/data~]# chown -R mysql:mysql /mydata/data
~]# tar xf mariadb-5.5.46.tar.gz -C /usr/local~]# cd /usr/local ~]# ln -sv mariadb-5.5.46 mysql ~]# cd mysql~]# chown -R mysql:mysql . ~]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data ~]# chown -R root . 将属主改回root
~]# cd /usr/local/mysql ~]# cp support-files/my-large.cnf /etc/my.cnf ~]# vim /etc/my.cnf ~]# thread_concurrency = 2 此值为你cpu个数乘以2 ~]# datadir = /mydata/data ~]# innodb_file_per_table = ON 使用独立表空间 ~]# skip_name_ resolve = ON 禁止IP反向解析为主机名
~]# cd /usr/local/mysql ~]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld ~]# chmod +x /etc/rc.d/init.d/mysqld ~]# chkconfig --add mysqld~]# chkconfig --level 2345 mysqld on
~]# vim /etc/man.config 添加如下行即可 MANPATH /usr/local/mysql/man
~]# ln -sv /usr/local/mysql/include /usr/include/mysql <--可以理解为调用的库
(8) 输出库文件给系统库查找路径
~]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf~]# ldconfig 重载
~]# vim /etc/profile.d/mysql.sh ~]# PATH=/usr/local/mysql/bin:$PATH <--可以直接使用mysql命令
~]> select user,passwd,host from mysql.user; ~]> create user ‘root‘@‘172.18.%.%‘; ~]> grant all on *.* to ‘root‘@‘172.18.%.%‘ identified by ‘123456‘ ~]> grant all on wordpress.* to wordpress@‘172.18.%.%‘ identified by ‘123456‘ ~]> flush privileges;~]# mysql_secure_installation 为mysql自己添加密码
~]# yum -y grouinstall "Desktop Platform Development" ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel
~]# tar xf php-5.4.26.tar.bz2 ~]# cd php-5.4.26 ~]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-pdo-mysql=mysqlnd <--此处编译为fast-cgi ~]# make && make test && make install ~]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 <--此处编译成了http的模块
~]# cp php.ini-production /etc/php.ini
~]# vim /usr/local/php/etc/php-fpm.conf
listen = 172.18.64.61:9000 监听PHP服务器本机
listen.allowed_clients = 172.18.64.60 允许60这台远程httpd服务器监听
连接池:
pm = static|dynamic
static:固定数量的子进程;
例:pm.max_children;
dynamic:子进程数据以动态模式管理;
例:pm.start_servers <--启动的时候启动的进程数
pm.min_spare_servers <--最小空闲进程数
pm.max_spare_servers <--最大空闲的进程数
pm.max_requests = 500 <--最多响应500个请求
php_admin_value[error_log] = .....<--错误日志存放路径
php_value[session.save_path] = ...<--sessin存放路径,实现集群高可用有用处
创建session目录,并确保运行php-fpm进程的用户对此目录有读写权限;
# mkdir /var/lib/php/session
# chown apache.apache /var/lib/php/session
php测试代码 <php? phpinfo(); ?> php连接mysql的测试代码 <?php $conn = mysql_connect(‘172.18.64.62‘.‘root‘,‘123456‘); if ($conn) echo "ok"; else echo "Failure" ?>
原文地址:http://wscto.blog.51cto.com/11249394/1783555