本节索引:
准备软件版本:
apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 httpd-2.4.27.tar.bz2 mariadb-5.5.57-linux-x86_64.tar.gz(二进制) PHP-5.6.31.tar.bz2 xcache-3.2.0.tar.gz wordpress-4.8-zh_CN.tar.gz
一. 源码编译安装 httpd2.4
1.准备编译环境安装
yumgroupinstall"developmenttools"-y yuminstallopenssl-develexpat-develpcre-devel-y
2.准备安装包及文件
tarxfapr-1.5.2.tar.bz2 tarxfapr-util-1.5.4.tar.bz2 tarxvfhttpd-2.4.27.tar.bz2 cp-rapr-1.5.2httpd-2.4.27/srclib/apr cp-rapr-util-1.5.4httpd-2.4.27/srclib/apr-util cdhttpd-2.4.27/
3.开始编译安装
./configure--prefix=/app/httpd24\ --sysconfdir=/etc/httpd24\ --enable-so\ --enable-ssl\ --enable-rewrite\ --with-zlib\ --with-pcre\ --with-included-apr\ --enable-modules=most\ --enable-mpms-shared=all\ --with-mpm=prefork make-j4&&makeinstall
4.配置httpd管理命令路径
vim/etc/profile.d/lamp.sh PATH=/app/httpd24/bin/:$PATH ./etc/profile.d/lamp.sh
5.配置服务脚本并启动
cp/etc/init.d/httpd/etc/init.d/httpd24#如没有httpd可从其他主机拷贝过来 vim/etc/init.d/httpd24#修改配置文件 apachectl=/app/httpd24/bin/apachectl httpd=${HTTPD-/app/httpd24/bin/httpd} prog=httpd pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd24} chkconfig--addhttpd24 chkconfig--listhttpd24 servicehttpd24start
二. 二进制安装及配置 mariadb
1.二进制安装mariadb
yumremoveMysqL-y#centos6默认安装MysqL并创建了用户名,安装较新版mariadb避免冲突要卸载MysqL tarxvfmariadb-5.5.57-linux-x86_64.tar.gz-C/usr/local cd/usr/local ln-smariadb-5.5.57-linux-x86_64/MysqL chown-Rroot:MysqLMysqL/ cdMysqL/ scripts/MysqL_install_db--datadir=/app/MysqLdb--user=MysqL#创建数据库文件
2.配置 mariadb 配置文件
mkdir/etc/MysqL cpsupport-files/my-large.cnf/etc/MysqL/my.cnf vim/etc/MysqL/my.cnf#在[MysqLd]下添加如下三条配置 [MysqLd] datadir=/app/MysqLdb innodb_file_per_table=ON skip_name_resolve=ON
3.配置服务脚本并启动
cpsupport-files/MysqL.server/etc/init.d/MysqLd chkconfig--addMysqLd chkconfig--list
4.配置日志文件
touch/var/log/MysqLd.log chownMysqL/var/log/MysqLd.log serviceMysqLdstart
5.配置命令路径
vi/etc/profile.d/lamp.sh PATH=/usr/local/MysqL/bin/:/app/http24/bin:$PATH ./etc/profile.d/lamp.sh
MysqL_secure_installation MysqL-uroot-pcentos createdatabasewpdb; grantallonwpdb.*towpuser@'%'identifiedby'centos'; 或者在命令行 MysqL-uroot-pcentos-ecreatedatabasewpdb;grantallonwpdb.*towpuser@'%'identifiedby'centos';
三.编译安装 PHP 及配置
1.编译前准备
yuminstalllibxml2-develbzip2-devellibmcrypt-devel(在epepl源) tarxvfPHP-5.6.31.tar.xz cdPHP-5.6.31
2.开始编译
./configure\ --prefix=/app/PHP5\#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\ --enable-fpm\ --with-mcrypt\ --with-config-file-path=/etc/PHP5\ --with-config-file-scan-dir=/etc/PHP5.d\ --with-bz2 注意:如参数--enable-fpm替换为--with-apxs2=/app/httpd24/bin/apxs则为模块方式PHP。 PHP连接httpd主要采用两种方式模块方式和fast-cgi独立方式(PHP-fpm为fastcgi进程管理器)。 --enable-maintainer-zts用于支持worker和event模块,如果prefork不需要 如MysqL不在本机--with-MysqL=MysqLnd,--with-MysqLi=MysqLnd make-j4&&makeinstall
3.配置命令路径
vi/etc/profile.d/lamp.sh PATH=/app/PHP5/bin:/app/httpd24/bin/:/usr/local/MysqL/bin/:$PATH ./etc/profile.d/lamp.sh
mkdir/etc/PHP5//etc/PHP5.d cpPHP.ini-production/etc/PHP5/PHP.ini#复制ini配置文件 注:ini文件中memory_limit128M生产中不够,可根据情况调大。 另外还有控制上传数据大小、数量等参数可调节 cpsapi/fpm/init.d.PHP-fpm/etc/init.d/PHP-fpm#复制脚本文件,fast-cgi方式需要 chmod+x/etc/init.d/PHP-fpm chkconfig--addPHP-fpm chkconfig--listPHP-fpm cd/app/PHP5/etc cpPHP-fpm.conf.defaultPHP-fpm.conf#复制主配置文件
5.编辑httpd相关配置参数
vim/etc/httpd24/httpd.conf #fast-cgi模式要取消两行的注释 LoadModuleproxy_modulemodules/mod_proxy.so LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so #在文件尾部加四行 AddTypeapplication/x-httpd-PHP.PHP AddTypeapplication/x-httpd-PHP-source.PHPs ProxyRequestsOff#fast-cgi要关闭正向代理 ProxyPassMatch^/(.*\.PHP)$fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1#转发到fast-cgi #修改下面行 <IfModuledir_module> DirectoryIndexindex.PHPindex.html </IfModule> servicehttpd24restart
vim/app/httpd24/htdocs/index.PHP <html><body><h1>Itworks!</h1></body></html> <?PHP $MysqLi=newMysqLi("localhost","root","centos"); if(MysqLi_connect_errno()){ echo"连接数据库失败!"; $MysqLi=null; exit; } echo"连接数据库成功!"; $MysqLi->close(); ####注释区为较老测试连接方式fast-cgi方式不支持#### $conn=MysqL_connect('localhost','root','centos'); if($conn) echo"OK"; else echo"Failure"; MysqL_close(); ################################################### PHPinfo(); ?>
四. 配置wordpress
1.安装
tarxvfwordpress-4.8.1-zh_CN.tar.gz-C/app/httpd24/htdocs cd/app/httpd24/htdocs mvwordpress/blog/ cd/app/httpd24/htdocs/blog/ cpwp-config-sample.PHPwp-config.php
vimwp-config.php define('DB_NAME','wpdb'); /**MysqL数据库用户名*/ define('DB_USER','wpuser'); /**MysqL数据库密码*/ define('DB_PASSWORD','centos'); /**MysqL主机*/ define('DB_HOST','localhost');
3.登录主机测试
http://websrv/blog#配置用户信息 测试性能 ab-c20-n200http://websrv/blog/
五.编译xcache 实现PHP加速
1.编译安装准备
tarxvfxcache-3.2.0.tar.bz2 cdxcache-3.2.0 /app/PHP5/bin/PHPize#生成configure文件
2.编译安装
./configure--enable-xcache--with-PHP-config=/app/PHP5/bin/PHP-config#指定PHP-config路径 make&&makeinstall#编译完成要记录模块路径!
3.编辑配置文件
mkdir/etc/PHP5.d/ cpxcache.ini/etc/PHP5.d/ vim/etc/PHP.d/xcache.ini extension=/app/PHP5/lib5/PHP/extensions/no-debug-non-zts-20131226/xcache.so#填写模块路径 servicePHP-fpmrestart
4.测试性能
ab-c20-n200http://websrv/blog/原文链接:https://www.f2er.com/centos/375603.html