一、安装相关组件
①安装所需依赖包
# yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel gd gd-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel ImageMagick ImageMagick-devel # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community-release-el7-5.noarch.rpm ##安装MySQL源 # yum -y install mysql-server mysql-devel ##安装MySQL
②下载编译源码安装的包
# wget http://nginx.org/download/nginx-1.9.4.tar.gz # wget http://cn2.php.net/distributions/php-5.6.13.tar.gz # wget http://ncu.dl.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz # wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz # wget http://nchc.dl.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz # wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz # wget http://pecl.php.net/get/memcache-2.2.7.tgz # wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz # wget http://pecl.php.net/get/imagick-3.1.2.tgz
其中:
zlib====》提供数据压缩用的函式库 pcre====》rewrite的支持库 openssl====》https的支持库 libiconv====》字符编码转换库 libxml====》XML库 libpng====》图片库 freetype====》字库 libmcrypt====》加密算法 mhash====》加密库 curl====》URL传输 gd====》绘图
③关闭SELinux和防火墙:
a、临时关闭(不用重启机器):
# setenforce 0 ##设置SELinux 成为permissive模式 (关闭SELinux) # setenforce 1 ##设置SELinux 成为enforcing模式 (开启SELinux)
b、修改配置文件需要重启机器:
# vi /etc/selinux/config
将SELINUX=enforcing 改为SELINUX=disabled(需重启机器)
c、可自己做策略开放相应端口,这里我直接关闭:
# systemctl status firewalld.service ##查看防火墙状态 # systemctl stop firewalld.service ##关闭防火墙
二、编译安装PHP(FastCGI模式)
①编译安装PHP所需的支持库
a.编译libiconv【为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换】
# tar -zvxf libiconv-1.14.tar.gz # cd libiconv-1.14/ # ./configure --prefix=/usr/local # make # make install
编译错误:
make时出现如下错误:
In file included from progname.c:26:0: ./stdio.h:1010:1: 错误:‘gets’未声明(不在函数内) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^ make[2]: *** [progname.o] 错误 1 make[2]: 离开目录“/root/libiconv-1.14/srclib” make[1]: *** [all] 错误 2 make[1]: 离开目录“/root/libiconv-1.14/srclib” make: *** [all] 错误 2
解决方法:
# cd /root/libiconv-1.14/srclib # sed -i -e '/gets is a security/d' ./stdio.in.h
来源于:http://blog.csdn.net/white__cat/article/details/28608489
b.编译libmcrypt【加密算法扩展库】
# tar -zxvf libmcrypt-2.5.8.tar.gz # cd libmcrypt-2.5.8/ # ./configure # make # make install # cd libltdl/ # ./configure --enable-ltdl-install # make # make install
c.编译mhash【基于离散数学原理的不可逆向的php加密方式扩展库】
# tar -zxvf mhash-0.9.9.9.tar.gz # cd mhash-0.9.9.9/ # ./configure # make # make install
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
d.编译mcrypt【加密支持扩展库】
# tar -zxvf mcrypt-2.6.8.tar.gz # ./configure # make # make install
编译错误1:
checking for libmcrypt-config... /usr/local/bin/libmcrypt-config checking for libmcrypt - version >= 2.5.0... no *** Could not run libmcrypt test program, checking why... *** The test program compiled, but did not run. This usually means *** that the run-time linker is not finding LIBMCRYPT or finding the wrong *** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you'll need to set your *** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point *** to the installed location Also, make sure you have run ldconfig if that *** is required on your system *** *** If you have an old version installed, it is best to remove it, although *** you may also be able to get things to work by modifying LD_LIBRARY_PATH *** configure: error: *** libmcrypt was not found
编译错误2:
checking whether mhash >= 0.8.15... no configure: error: "You need at least libmhash 0.8.15 to compile this program. http://mhash.sf.net/"
解决方法:
# vi /etc/ld.so.conf ##添加如下 /usr/local/lib/ # ldconfig ##重新载入
②编译安装PHP(FastCGI模式)
# tar -zxvf php-5.6.13.tar.gz # cd php-5.6.13/ # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts # make # make install
错误:
collect2: error: ld returned 1 exit statusmake: *** [sapi/cli/php] 错误 1
解决:
# make ZEND_EXTRA_LIBS='-liconv'
# cp php.ini-production /usr/local/php/etc/php.ini ##复制php.ini配置文件 # cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm ##复制php-fpm启动脚本到init.d # chmod u+x /etc/init.d/php-fpm ##赋予执行权限 # chkconfig --add php-fpm ##添加为启动项 # chkconfig php-fpm on ##设置开机启动 # groupadd www ##创建群组 # useradd -s /sbin/nologin -g www -M www ##创建用户,不允许其登录及创建主目录 # systemctl start php-fpm.service ##启动php-fpm # mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # ln -s /usr/local/php/etc/php.ini /etc/php.ini # ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
注:php-fpm已集成至PHP中,不在是第三方包了。
③编译安装PHP扩展模块
a.编译memcache【提供于memcached方便的面向过程及面向对象的接口】
# tar -zxvf memcache-2.2.7.tgz # cd memcache-2.2.7/ # /usr/local/php/bin/phpize ##用phpize为PHP添加动态扩展 Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 # ./configure --with-php-config=/usr/local/php/bin/php-config # make # make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
b.编译xcache【开源的opcode缓存器/优化器】
# tar -zxvf xcache-3.2.0.tar.gz # cd xcache-3.2.0/ # /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 # ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config # make # make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
c.编译imagick【可供PHP调用ImageMagick功能的PHP扩展】
# tar -zxvf imagick-3.1.2.tgz # cd imagick-3.1.2/ # /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api No: 20131226 Zend Extension Api No: 220131226 # ./configure --with-php-config=/usr/local/php/bin/php-config # make # make install Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ Installing header files: /usr/local/php/include/php/
错误:
configure时出现如下错误:
checking ImageMagick MagickWand API configuration program... configure: error: not found. Please provide a path to MagickWand-config or Wand-config program.
解决:未安装ImageMagick的devel包,yum install ImageMagick-devel安装解决
4.配置PHP以支持扩展模块
# vi /etc/php.ini 126 output_buffering 127 Default Value: On ##开启输出缓冲器 732 ; Directory in which the loadable extensions (modules) reside. 736 ; extension_dir = "ext" 737 ##添加模块如下路径 738 extension_dir = /usr/local/php/lib/php/extensions/no-debug-zts-20131226/ 739 extension = memcache.so 740 extension = imagick.so 741 extension = xcache.so 778 cgi.fix_pathinfo=0 ##防止Nginx文件类型错误解析漏洞
并添加如下:
[xcache.admin] xcache.admin.enable_auth = On ##启用xcache管理认证 xcache.admin.user = "xcache" xcache.admin.pass = "827ccb0eea8a706c4c34a16891f84e7b" [xcache] xcache.shm_scheme ="mmap" ## 选择低级别的共享存储器/分配算符安排执行 xcache.size=60M ##启用缓存器,缓存大小为60M xcache.count =1 ##指定将 cache 切分成多少块 xcache.slots =8K xcache.ttl=0 ##设置缓冲项目的 TTL值, 0=永不过期 xcache.gc_interval =0 xcache.var_size=4M xcache.var_count =1 xcache.var_slots =8K xcache.var_ttl=0 xcache.var_maxttl=0 xcache.var_gc_interval =300 xcache.test =Off xcache.readonly_protection = On xcache.mmap_path ="/tmp/xcache" xcache.coredump_directory ="" xcache.cacher =On xcache.stat=On xcache.optimizer =Off [xcache.coverager] xcache.coverager =On xcache.coveragedump_directory =""
# touch /tmp/xcache ##新建Xcache缓存文件 # chmod 777 /tmp/xcache # echo -n "12345" | md5sum ##生成Xcache管理员密钥 827ccb0eea8a706c4c34a16891f84e7b # cp -a xcache-3.2.0/htdocs/ /usr/html/xadmin ##拷贝Xcache管理程序到网站根目录下 # systemctl restart php-fpm.service ##重启php-fpm
访问http://localhost/xadmin,用户名为xcache 密码为12345
查看缓存器
三、编译安装nginx
①编译安装nginx
nginx所需的依赖关系,一般需先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
# groupadd -r nginx # useradd -r -g nginx nginx # tar -zxvf nginx-1.9.4.tar.gz # cd nginx-1.9.4/ # ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ --http-scgi-temp-path=/var/tmp/nginx/scgi \ --with-pcre # make # make install # /usr/sbin/nginx ##开启nginx
错误: 开启nginx时出现如下错误: nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory) 解决: # mkdir -p /var/tmp/nginx/client # /usr/sbin/nginx
②修改相关nginx配置
# vi /etc/nginx/nginx.conf user www; server { listen 80; server_name localhost; index index.php index.html; root /usr/html; location / { root html; index index.html index.htm index.php; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi.conf; }
# /usr/sbin/nginx -t ##测试语法 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
③测试php
# chown www.www /usr/html/ -R # chmod 700 /usr/html/ -R # cd /usr/html # rm index.html
# vi index.php <?php phpinfo(); ?>
# chown www.www index.php # chmod 700 index.php # /usr/sbin/nginx -s reload ##重载nginx
输入IP地址查看:
④安装WordPress
# wget https://cn.wordpress.org/wordpress-4.3.1-zh_CN.tar.gz # tar -zxvf wordpress-4.3.1-zh_CN.tar.gz # rm index.php # mv wordpress/* /usr/html/ # chown -R www.www /usr/html/
输入IP地址查看:
# systemctl start mysql.service # mysql -u root -p mysql> use mysql; mysql> update user set password=PASSWORD('root') where user='root'; ##设置root密码 mysql> create database wordpress; ##新建WordPress数据库 mysql> flush privileges; mysql> quit
按照提示输入相关内容,主机名默认localhost,如出现错误改为127.0.0.1试试。
最后输入用户名和密码
这网站就搭建好了
附:本文参照nginx中文文档http://www.nginx.cn/doc/index.html下的http://blog.zyan.cc/nginx_php_v6/