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

LNMP环境搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-1-7 09:56:36 | 显示全部楼层 |阅读模式
LNMP环境搭建(基于Centos6.7 32位Linux操作系统)

一、linux环境安装


二、MySQL安装

三、PHP编译安装
注意:针对Nginx的php安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的

1、下载PHP源码包,解压
[iyunv@daixuan ~]# cd /usr/local/src
[iyunv@daixuan src]# wget http://cn2.php.net/distributions/php-5.4.37.tar.bz2
[iyunv@daixuan src]# tar jxvf php-5.4.37.tar.bz2
[iyunv@daixuan src]# ls
php-5.4.37

2、创建相关账户
[iyunv@daixuan src]# useradd -s /sbin/nologin php-fpm

3、配置编译选项
注意:由于之前在该虚拟机上安装了LAMP,安装过php,这里需要先删除
[iyunv@daixuan php-5.4.37]# rm -rf /usr/local/php/
[iyunv@daixuan src]# cd php-5.4.37
[iyunv@daixuan php-5.4.37]# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm --with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--enable-zend-multibyte \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl
[iyunv@daixuan php-5.4.37]# echo $?   //结果为0说明没有报错
0
这里如果有报错,可能是某些库没有安装,例如:安装libcurl库:yum install -y libcurl-delevel

4、编译PHP
[iyunv@daixuan php-5.4.37]# make
[iyunv@daixuan php-5.4.37]# echo $?
0
注:如果这里遇到这样的错误,解决方法是:yum install -y libtool-ltdl-devel
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm]

5、安装PHP
[iyunv@daixuan php-5.4.37]# make install

6、修改配置文件
[iyunv@daixuan php-5.4.37]# cp php.ini-production /usr/local/php/etc/php.ini
[iyunv@daixuan php-5.4.37]# cd /usr/local/php/etc/   
[iyunv@daixuan etc]# mv php-fpm.conf.default php-fpm.conf
[iyunv@daixuan etc]# ls
pear.conf  php-fpm.conf  php.ini
保存配置文件后,检验配置是否正确的方法为:
[iyunv@daixuan etc]# /usr/local/php/sbin/php-fpm -t
[05-Jan-2016 20:24:32] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
test is successful字样,说明配置没有问题

7、拷贝启动脚本
[iyunv@daixuan src]# cd /usr/local/src/php-5.4.37
首先是拷贝一个php的启动脚本到/etc/init.d/下:
[iyunv@daixuan php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[iyunv@daixuan php-5.4.37]# chmod 755 /etc/init.d/php-fpm
添加php-fpm到服务列表中,让它开机启动
[iyunv@daixuan php-5.4.37]# chkconfig --add php-fpm
[iyunv@daixuan php-5.4.37]# chkconfig php-fpm on
[iyunv@daixuan php-5.4.37]# service php-fpm start
Starting php-fpm  done
查看php-fpm的进程:
[iyunv@daixuan php-5.4.37]# netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address  Foreign Address   State       PID/Program name
tcp   0    0   127.0.0.1:9000   0.0.0.0:*      LISTEN      19901/php-fpm
[iyunv@daixuan php-5.4.37]# ps aux | grep php-fpm
root 19901 0.0 0.1 26084 2976 ? Ss 20:17 0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)            
php-fpm  19902  0.0  0.1  26084  2644 ?  S  20:17   0:00 php-fpm: pool www     php-fpm  19903  0.0  0.1  26084  2644 ?   S    20:17   0:00 php-fpm: pool www   
root    19926  0.0  0.0   6048   780 pts/0   S+   20:20   0:00 grep php-fpm

二、Nginx编译安装

1、下载解压Nginx
[iyunv@daixuan src]# cd /usr/local/src/
[iyunv@daixuan src]# wget http://nginx.org/download/nginx-1.8.0.tar.gz  
[iyunv@daixuan src]# tar zxvf nginx-1.8.0.tar.gz
[iyunv@daixuan src]# ls
nginx-1.8.0
nginx-1.8.0.tar.gz

2、配置编译选项
[iyunv@daixuan nginx-1.8.0]# cd nginx-1.8.0
[iyunv@daixuan nginx-1.8.0]# ./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
[iyunv@daixuan nginx-1.8.0]# echo $?
1
发现有错误,解决方法,安装pcre库,重新配置编译选项
[iyunv@daixuan nginx-1.8.0]# yum install -y pcre-devel
[iyunv@daixuan nginx-1.8.0]# echo $?
0

3、编译Nginx
[iyunv@daixuan nginx-1.8.0]#make

4、安装
[iyunv@daixuan nginx-1.8.0]#make install

5、启动Nginx
[iyunv@daixuan nginx-1.8.0]# cd /usr/local/nginx/
[iyunv@daixuan nginx]# ls sbin/nginx
sbin/nginx
启动nginx,报错:
[iyunv@daixuan nginx]# /usr/local/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[iyunv@daixuan nginx]# netstat -lnp
tcp  0  0 ::ffff:127.0.0.1:8005  :::*    LISTEN      2183/java
tcp  0  0 :::8009            :::*   LISTEN      2183/java
tcp  0  0 :::80             :::*    LISTEN      2183/java
这里报错是因为80端口已经被tomcat占用,需要先关闭tomcat
[iyunv@daixuan nginx]# service tomcat stop
重新启动nginx
[iyunv@daixuan nginx]# /usr/local/nginx/sbin/nginx
[iyunv@daixuan nginx]# ps aux | grep nginx
root30631 0.1 0.0 5028 644 ? Ss 21:160:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   30632  0.1  0.0   5232   980 ?  S    21:16   0:00 nginx: worker process
root     30636  0.0  0.0   6048   780 pts/0    S+   21:16   0:00 grep nginx

三、测试PHP解析
1、修改nginx配置文件,使其支持php

[iyunv@daixuan nginx]# vim /usr/local/nginx/conf/nginx.conf
把这一段注释去掉,让其生效,/usr/local/nginx/html是PHP的文件目录
location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
      }
[iyunv@daixuan nginx]# /usr/local/nginx/sbin/nginx -s reload //重新加载nginx配置文件
[iyunv@daixuan ~]# cd /usr/local/nginx/html
[iyunv@daixuan html]# vim info.php
<?php
phpinfo();
?>
浏览器中可以访问:
http://192.168.101.230/info.php


运维网声明 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-161308-1-1.html 上篇帖子: LAMP之禁止默认虚拟主机 下篇帖子: CentOS6.5搭建LNMP PHP源码 linux 操作系统 Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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