设为首页 收藏本站
查看: 1418|回复: 0

LNMP实现(CentOS7+Nginx-1.9.4+PHP-5.6+MySQL-5.6.26)

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-9-24 09:05:49 | 显示全部楼层 |阅读模式
一、安装相关组件

①安装所需依赖包
1
2
3
4
# 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-client mysql-devel   ##安装MySQL(编译用时太久)




②下载编译源码安装的包
1
2
3
4
5
6
7
8
9
# 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/pr ... hash-0.9.9.9.tar.gz
# wget http://nchc.dl.sourceforge.net/p ... mcrypt-2.5.8.tar.gz
# wget http://nchc.dl.sourceforge.net/p ... 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




其中:      
1
2
3
4
5
6
7
8
9
10
11
      zlib====》提供数据压缩用的函式库
      pcre====》rewrite的支持库
      openssl====》https的支持库
      libiconv====》字符编码转换库
      libxml====》XML库
      libpng====》图片库
      freetype====》字库
      libmcrypt====》加密算法
      mhash====》加密库
      curl====》URL传输
      gd====》绘图




二、编译安装PHP(FastCGI模式)


①编译安装PHP所需的支持库
a.编译libiconv【为需要做转换的应用提供了一个iconv()的函数,以实现一个字符编码到另一个字符编码的转换】
1
2
3
4
5
# tar -zvxf libiconv-1.14.tar.gz
# cd libiconv-1.14/
# ./configure --prefix=/usr/local
# make
# make install



编译错误:
make时出现如下错误:
1
2
3
4
5
6
7
8
9
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



解决方法:
1
2
# cd /root/libiconv-1.14/srclib
# sed -i -e '/gets is a security/d' ./stdio.in.h



来源于:http://blog.iyunv.com/white__cat/article/details/28608489

b.编译libmcrypt【加密算法扩展库】
1
2
3
4
5
6
7
8
9
# 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加密方式扩展库】
1
2
3
4
5
# tar -zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure
# make
# make install



1
2
3
4
5
6
7
8
9
10
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【加密支持扩展库】
1
2
3
4
#  tar -zxvf mcrypt-2.6.8.tar.gz
#  ./configure
# make
# make install




编译错误1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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:
1
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/"



解决方法:
1
2
3
# vi /etc/ld.so.conf      ##添加如下
/usr/local/lib/
# ldconfig              ##重新载入




②编译安装PHP(FastCGI模式)
1
2
3
4
5
# 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



错误:

1
collect2: error: ld returned 1 exit statusmake: *** [sapi/cli/php] 错误 1



解决:
1
# make ZEND_EXTRA_LIBS='-liconv'



1
2
3
4
5
6
7
8
9
10
11
# 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方便的面向过程及面向对象的接口】
1
2
3
4
5
6
7
8
9
10
11
# 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缓存器/优化器】

1
2
3
4
5
6
7
8
9
10
11
# 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扩展】
1
2
3
4
5
6
7
8
9
10
11
12
# 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时出现如下错误:
1
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以支持扩展模块
1
2
3
4
5
6
7
8
9
10
11
12
# 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文件类型错误解析漏洞



并添加如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[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 =""



1
2
3
4
5
6
7
# 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
# /usr/sbin/nginx -s reload                      ##重载nginx



访问http://localhost/xadmin,用户名为xcache 密码为12345
wKiom1YCYxPAqrKaAAZIQCuLt0k658.jpg
查看缓存器
wKiom1YCY3vS-YklAATH2trbo_A872.jpg

三、编译安装nginx

①编译安装nginx

nginx所需的依赖关系,一般需先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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



1
2
3
4
5
6
错误:
开启nginx时出现如下错误:
nginx: [emerg] mkdir() "/var/tmp/nginx/client/" failed (2: No such file or directory)
解决:
# mkdir -p /var/tmp/nginx/client
# /usr/sbin/nginx



QQ截图20150924090526.png



②修改相关nginx配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 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;
        }



1
2
3
# /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
1
2
3
4
# chown www.www /usr/html/ -R
# chmod 700 /usr/html/ -R
# cd /usr/html
# rm index.html



1
2
3
4
# vi index.php
<?php  
phpinfo();
?>



1
2
3
# chown www.www index.php
# chmod 700 index.php
/usr/sbin/nginx -s reload         ##重载nginx



输入IP地址查看:
wKiom1YCBkmyuDZPAAShCYbIQBI548.jpg

④安装WordPress

1
2
3
4
5
# 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地址查看:

wKiom1YCC5HjG4FCAALHbGJCtQo482.jpg
1
2
3
4
5
6
7
# 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试试。
wKioL1YCKIiyn0EpAAJTLZjFPRg608.jpg 最后输入用户名和密码
wKioL1YCKXfzCyo8AAKTlSxPwsg604.jpg
这网站就搭建好了



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-117997-1-1.html 上篇帖子: 实现php-fpm的工作机制,编译LAMP 下篇帖子: 一键优化lamp之php
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表