LNMP的搭建

1.安装mysql //在练习lamp时已经安装过
2.php安装
[[email protected] php-5.4.37]# wget  http://cn2.php.net/distributions/php-5.4.37.tar.bz2
[[email protected] php-5.4.37]# tar jxf php-5.4.37.tar.bz2
[[email protected] php-5.4.37]# useradd -s /sbin/nologin php-fpm
[[email protected] php-5.4.37]# cd php-5.4.37
[[email protected] php-5.4.37]# ./configure --prefix=/usr/local/php-fpm   --with-config-file-path=/usr/local/php-fpm/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    --disable-ipv6     --with-curl 
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
[[email protected] php-5.4.37]# yum install -y curl-devel
[[email protected] php-5.4.37]# cp php.ini-production /usr/local/php-fpm/etc/php.ini 
拷贝启动脚本:
[[email protected] php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-5.4.37]# chmod 755 /etc/init.d/php-fpm 
[[email protected] php-5.4.37]# chkconfig --add php-fpm
[[email protected] php-5.4.37]# chkconfig php-fpm on
[[email protected] php-5.4.37]# service php-fpm start
Starting php-fpm [14-May-2015 03:00:25] ERROR: failed to open configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘: No such file or directory (2)
[14-May-2015 03:00:25] ERROR: failed to load configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘
[14-May-2015 03:00:25] ERROR: FPM initialization failed
 failed
[[email protected] ~]# mv /usr/local/php-fpm/etc/{php-fpm.conf.default,php-fpm.conf} -v
"/usr/local/php-fpm/etc/php-fpm.conf.default" -> "/usr/local/php-fpm/etc/php-fpm.conf"
[[email protected] ~]# service php-fpm start
Starting php-fpm  done
3.安装nginx:
[[email protected] nginx-1.6.2]# cd /usr/local/src/
[[email protected] nginx-1.6.2]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[[email protected] nginx-1.6.2]# tar zxvf nginx-1.6.2.tar.gz
[[email protected] nginx-1.6.2]# cd nginx-1.6.2
[[email protected] nginx-1.6.2]# ./configure   --prefix=/usr/local/nginx   --with-pcre
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./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.
[[email protected] nginx-1.6.2]# yum install -y pcre-devel
4.编写nginx启动脚本:
[[email protected] nginx-1.6.2]# vi /etc/init.d/nginx
#!/bin/bash
 # chkconfig: - 30 21
 # description: http service.
 # Source Function Library
 . /etc/init.d/functions
 # Nginx Settings
 
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
 NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
 NGINX_PID="/usr/local/nginx/logs/nginx.pid"
 RETVAL=0
 prog="Nginx"
 
start() {
         echo -n $"Starting $prog: "
         mkdir -p /dev/shm/nginx_temp
         daemon $NGINX_SBIN -c $NGINX_CONF
         RETVAL=$?
         echo
         return $RETVAL
 }
 
stop() {
         echo -n $"Stopping $prog: "
         killproc -p $NGINX_PID $NGINX_SBIN -TERM
         rm -rf /dev/shm/nginx_temp
         RETVAL=$?
         echo
         return $RETVAL
 }
 
reload(){
         echo -n $"Reloading $prog: "
         killproc -p $NGINX_PID $NGINX_SBIN -HUP
         RETVAL=$?
         echo
         return $RETVAL
 }
 
restart(){
         stop
         start
 }
 
configtest(){
     $NGINX_SBIN -c $NGINX_CONF -t
     return 0
 }
 
case "$1" in
   start)
         start
         ;;
   stop)
         stop
         ;;
   reload)
         reload
         ;;
   restart)
         restart
         ;;
   configtest)
         configtest
         ;;
   *)
         echo $"Usage: $0 {start|stop|reload|restart|configtest}"
         RETVAL=1
 esac
 exit $RETVAL
[[email protected] nginx-1.6.2]# chmod a+x /etc/init.d/nginx 
[[email protected] nginx-1.6.2]# chkconfig --add nginx 
[[email protected] nginx-1.6.2]# chkconfig nginx on
5.配置解析php
[[email protected] nginx-1.6.2]# vi  /usr/local/nginx/conf/nginx.conf   
**************************
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
         location ~ \.php$ {
             root           /data/www;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
             include        fastcgi_params;
         }
重新加载 /usr/local/nginx/sbin/nginx -s  reload
[[email protected] ~]# cat /data/www/phpinfo.php 
<?php
 phpinfo();
?>
[[email protected] ~]# curl -x127.0.0.1:80 www.123.com/phpinfo.php -I
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sun, 17 May 2015 13:31:23 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
搭建中运到的问题:
1.安装mysql //在练习lamp时已经安装过
2.php安装
[[email protected] php-5.4.37]# wget  http://cn2.php.net/distributions/php-5.4.37.tar.bz2
[[email protected] php-5.4.37]# tar jxf php-5.4.37.tar.bz2
[[email protected] php-5.4.37]# useradd -s /sbin/nologin php-fpm
[[email protected] php-5.4.37]# cd php-5.4.37
[[email protected] php-5.4.37]# ./configure --prefix=/usr/local/php-fpm   --with-config-file-path=/usr/local/php-fpm/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    --disable-ipv6     --with-curl 
configure: error: Please reinstall the libcurl distribution -
    easy.h should be in <curl-dir>/include/curl/
[[email protected] php-5.4.37]# yum install -y curl-devel
[[email protected] php-5.4.37]# cp php.ini-production /usr/local/php-fpm/etc/php.ini 
拷贝启动脚本:
[[email protected] php-5.4.37]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-5.4.37]# chmod 755 /etc/init.d/php-fpm 
[[email protected] php-5.4.37]# chkconfig --add php-fpm
[[email protected] php-5.4.37]# chkconfig php-fpm on
[[email protected] php-5.4.37]# service php-fpm start
Starting php-fpm [14-May-2015 03:00:25] ERROR: failed to open configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘: No such file or directory (2)
[14-May-2015 03:00:25] ERROR: failed to load configuration file ‘/usr/local/php-fpm/etc/php-fpm.conf‘
[14-May-2015 03:00:25] ERROR: FPM initialization failed
 failed
[[email protected] ~]# mv /usr/local/php-fpm/etc/{php-fpm.conf.default,php-fpm.conf} -v
"/usr/local/php-fpm/etc/php-fpm.conf.default" -> "/usr/local/php-fpm/etc/php-fpm.conf"
[[email protected] ~]# service php-fpm start
Starting php-fpm  done
3.安装nginx:
[[email protected] nginx-1.6.2]# cd /usr/local/src/
[[email protected] nginx-1.6.2]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[[email protected] nginx-1.6.2]# tar zxvf nginx-1.6.2.tar.gz
[[email protected] nginx-1.6.2]# cd nginx-1.6.2
[[email protected] nginx-1.6.2]# ./configure   --prefix=/usr/local/nginx   --with-pcre
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./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.
[[email protected] nginx-1.6.2]# yum install -y pcre-devel
4.编写nginx启动脚本:
[[email protected] nginx-1.6.2]# vi /etc/init.d/nginx
#!/bin/bash
 # chkconfig: - 30 21
 # description: http service.
 # Source Function Library
 . /etc/init.d/functions
 # Nginx Settings
 
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
 NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
 NGINX_PID="/usr/local/nginx/logs/nginx.pid"
 RETVAL=0
 prog="Nginx"
 
start() {
         echo -n $"Starting $prog: "
         mkdir -p /dev/shm/nginx_temp
         daemon $NGINX_SBIN -c $NGINX_CONF
         RETVAL=$?
         echo
         return $RETVAL
 }
 
stop() {
         echo -n $"Stopping $prog: "
         killproc -p $NGINX_PID $NGINX_SBIN -TERM
         rm -rf /dev/shm/nginx_temp
         RETVAL=$?
         echo
         return $RETVAL
 }
 
reload(){
         echo -n $"Reloading $prog: "
         killproc -p $NGINX_PID $NGINX_SBIN -HUP
         RETVAL=$?
         echo
         return $RETVAL
 }
 
restart(){
         stop
         start
 }
 
configtest(){
     $NGINX_SBIN -c $NGINX_CONF -t
     return 0
 }
 
case "$1" in
   start)
         start
         ;;
   stop)
         stop
         ;;
   reload)
         reload
         ;;
   restart)
         restart
         ;;
   configtest)
         configtest
         ;;
   *)
         echo $"Usage: $0 {start|stop|reload|restart|configtest}"
         RETVAL=1
 esac
 exit $RETVAL
[[email protected] nginx-1.6.2]# chmod a+x /etc/init.d/nginx 
[[email protected] nginx-1.6.2]# chkconfig --add nginx 
[[email protected] nginx-1.6.2]# chkconfig nginx on
5.配置解析php
[[email protected] nginx-1.6.2]# vi  /usr/local/nginx/conf/nginx.conf   
**************************
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
         location ~ \.php$ {
             root           /data/www;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
             include        fastcgi_params;
         }
重新加载 /usr/local/nginx/sbin/nginx -s  reload
[[email protected] ~]# cat /data/www/phpinfo.php 
<?php
 phpinfo();
?>
[[email protected] ~]# curl -x127.0.0.1:80 www.123.com/phpinfo.php -I
HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Sun, 17 May 2015 13:31:23 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.4.37
搭建遇到的问题:
[[email protected] ~]# service php-fpm start
Starting php-fpm [15-May-2015 05:22:17] ERROR: unable to bind listening socket for address ‘127.0.0.1:9000‘: Address already in use (98)
[15-May-2015 05:22:17] ERROR: FPM initialization failed
 failed
[[email protected] ~]# killall php-fpm
[[email protected] ~]# !ser
service php-fpm start
Starting php-fpm  done

[[email protected] ~]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] "location" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:65
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
#
        #error_page   500 502 503 504  /50x.html;
        location = /50x.html {                  //把这给注释之后就会报错
            root   html;
        }
***********************
#}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
         location ~ \.php$ {
             root           /data/www;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
             include        fastcgi_params;
         }
[[email protected] ~]# vi +65  /usr/local/nginx/conf/nginx.conf    
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

扩展学习:
Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html
apache和nginx工作原理比较 http://www.server110.com/nginx/201402/6543.html
mod_php 和 mod_fastcgi以及php-fpm的比较 http://wenku.baidu.com/link?url= ... QzFJkh_AElC4Nc-LD03
概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM http://www.nowamagic.net/librarys/veda/detail/1319/

时间: 2024-08-07 13:23:42

LNMP的搭建的相关文章

centos6 LNMP的搭建(linux+nginx+mysql+php)

LNMP的搭建(linux+nginx+mysql+php) 简介 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档

LNMP的搭建及URL重写测试

内容: 1.LNMP的搭建 2.搭建基于LNMP的discuz论坛(www.hill.com) 3.实现https 4.实现访问http时自动跳转至https以及防盗链设置.URL重写测试 一.LNMP的搭建 我们知道,在apache与php的结合方式有三种,而nginx与php的结合目前只有一种是行之有效的:php-fpm 1.yum直接安装快速搭建LNMP,官方下载nginx的预安装包(rpm包),当然也可以编译安装 #yum install -y prce-devel zlib-devel

LNMP环境搭建ZABBIX3.0

1.LNMP环境搭建,这里就不详细介绍了,但是有几点需要注意 1)mysql如果是二进制或者编译安装,php编译的时候需要一下编译参数 --with-mysqli=/application/mysql-5.5.32/bin/mysql_config //后面的路径是你的mysql_config的具体路径,如果不加此参数会导致安装zabbix的时候找不到mysql support 2)mysql建立zabbix数据库的时候要指定utf8建库,再导入zabbix的数据 3)php编译的时候要加下面的

阿里云(ECS)Centos服务器LNMP环境搭建

阿里云( ECS ) Centos7 服务器 LNMP 环境搭建 前言 第一次接触阿里云是大四的时候,当时在校外公司做兼职,关于智能家居项目的,话说当时俺就只有一个月左右的 php 后台开发经验(还是因为无意中选修了一门电子商务的课程,要做课程设计逼迫出来的),因为公司没人接触过后台开发,所以我这个菜鸟就硬着头皮上了.刚开始入门我把精力放在公司业务功能实现上,所用的服务器环境是别人已经配置好的,就是把代码在本地写好,通过 ftp 上传到服务器目录,是用 postman 插件测试一下接口就行了,开

LNMP环境搭建——Apache篇

1.Apache DSO(Dynamic Shared Object) (1) 查看已编译模块: [root@kallen ~]# httpd -M Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared) auth_digest_module (shared) authn_file_modu

LNMP环境搭建 Ubuntu篇

LNMP    就是linux+nginx+mysql+php.  洒家之前一直用apache服务器,还是win7系统,使用的都是xampp,esayphp,wamp等集成环境,周末闲着无聊,抱着尽量提高b格的想法动手配置了一下环境.完成之后还有点小激动.把过程分享出来,希望能帮助一些和我差不多的小白.下面开始环境配置: 首先ctrl+alt+t打开终端 1.更新软件源:  sudo apt-get update2.安装nginx  sudo apt-get install nginx3.启动n

lamp or lnmp 环境搭建之独立安装mysql数据库

lamp or lnmp 环境搭建,如果mysql 是独立安装的则需要授权: 单独一台服务器独立安装mysql 安装后,优化服务器. 授权 实例如下: 创建用户 CREATE USER demo IDENTIFIED BY "passwd123"; 授权使用mysql数据库下面的所有表 GRANT ALL PRIVILEGES ON mysql.* TO 'demo'@'%'IDENTIFIED BY 'passwd123'WITH GRANT OPTION; FLUSH PRIVIL

LNMP环境搭建(基于zabbix监控软件)

LNMP环境搭建(基于zabbix监控软件) 安装依赖包: yum -y install pcre  pcre-devel  openssl openssl-devel 安装nginx [[email protected] media]# tar zxvf nginx-1.6.0.tar.gz [[email protected] media]# cd nginx-1.6.0 [[email protected] nginx-1.6.0]# ./configure --prefix=/usr/l

Linux服务器集群架构部署搭建(四)WEB服务器LNMP/LAMP搭建部署及站点产品安装(1)

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 作者:燁未央_Estelle声明:测试学习,不足之处,欢迎指正. 第一章 集群WEB服务器LNMP生产应用 1.1 Nginx的应用场合:根据功能来进行应用 ①静态服务器(图片,视频服务)国内使用的只有两款,另一个是lighttpd.百度贴吧.豆瓣.html.js.css.flv等. ②动态服务:nginx+fastcgi的方式运行php.jsp.动态的并发很少(根据优化达到500-1500),

LNMP平台搭建---Linux系统安装篇

在互联网网站开发领域,有一个名词,大家一定不陌生,那就是LAMP,经典的Web服务器环境,由Linux+Apache+MySQL+PHP组成,,后来,一个名叫Nginx的Web服务器开源出来了,因其更高的并发性,系统资源利用率更高,在市场上的占有率也逐步提升,在Netcraft网站上看到的数据,在1995年到2015年间,每种服务器的使用趋势: 可以看到,Apache依然是最受欢迎的Web服务器,Nginx属于后起之秀,很快占有市场.Nginx的几大特点如下: 1. 对静态资源的高速并发缓存和访