码迷,mamicode.com
首页 > 其他好文 > 详细

LNMP

时间:2016-04-09 16:37:23      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:

一、安装MySQL

参照本博配置LAMP文章 http://www.cnblogs.com/frankielf0921/articles/5371611.html

 

=====================我是分割线。========================

二、安装php

针对Nginx的php安装和针对apache的php安装是有区别的,

因为Nginx中的php是以fastcgi的方式结合nginx的,

可以理解为nginx代理了php的fastcgi,

而apache是把php作为自己的模块来调用的。

[rot@localhost ~]# cd /usr/local/src
[root@localhost src]# wget http://am1.php.net/distributions/php-5.3.27.tar.gz
[root@localhost src]# tar zxf php-5.3.27.tar.gz
[root@localhost src]# useradd -s /sbin/nologin php-fpm //账号用来运行php-fpm服务
[root@localhost src]# cd php-5.3.27
[root@localhost php-5.3.27]# ./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
[root@localhost  php-5.3.27]# make
[root@localhost  php-5.3.27]# make install
[root@localhost  php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini  //拷贝配置文件

//此配置文件全为注释,可以留着查看 
//也可将其清空后再添加新内容
[root@localhost  php-5.3.27]# > /usr/local/php/etc/php-fpm.conf  
[root@localhost  php-5.3.27]# vim /usr/local/php/etc/php-fpm.conf
//写入以下内容
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
[root@localhost  php-5.3.27]# /usr/local/php/sbin/php-fpm -t  //检测配置文件是否有错误
//出现诸如 “test is successful” 字样,说明配置没有问题。
[root@localhost  php-5.3.27]# cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝启动脚本
[root@localhost  php-5.3.27]# chmod 755 /etc/init.d/php-fpm  //修改权限
[root@localhost  php-5.3.27]# service php-fpm start  //启动php-fpm
[root@localhost  php-5.3.27]# chkconfig php-fpm on
[root@localhost  php-5.3.27]# ps aux |grep php-fpm

 

安装php会遇到的错误:--其他错误可查看LAMP配置文章

 

// 编译时遇到的错误 

/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] 

--> yum install -y libtool-ltdl-devel

// 修改配置文件后,检测是否正确时的错误

[03-Mar-2016 01:23:38] ERROR: [/usr/local/php/etc/php-known entry pid
[03-Mar-2016 01:23:38] ERROR: failed to load configurar/local/php/etc/php-fpm.con
[03-Mar-2016 01:23:38] ERROR: FPM initialization failed

--> cd /usr/local/php/etc
--> ls
pear.conf    php-fpm.conf.default
php-fpm.conf   php.ini

--> mv php-fpm.conf.default php-fpm.conf
是否覆盖"php-fpm.conf"? y 

OR 

--> rm -rf /usr/local/php/etc/php-fpm.conf.default

 

=====================我是分割线。========================

三、安装nginx   -- 如果Apache正在运行,把Apache停掉。  { 有时两者会进行干扰 }

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget http://nginx.org/download/nginx-1.4.4.tar.gz
[root@localhost src]# tar zxvf nginx-1.4.4.tar.gz
[root@localhost src]# cd nginx-1.4.4
[root@localhost nginx-1.4.4]# ./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
[root@localhost nginx-1.4.4]# make 
[root@localhost nginx-1.4.4]# make install 
[root@localhost nginx-1.4.4]# vim /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
[root@localhost nginx-1.4.4]# chmod 755 /etc/init.d/nginx
[root@localhost nginx-1.4.4]# chkconfig --add nginx
[root@localhost nginx-1.4.4]# chkconfig nginx on 
[root@localhost nginx-1.4.4]# > /usr/local/nginx/conf/nginx.conf
[root@localhost nginx-1.4.4]# vim /usr/local/nginx/conf/nginx.conf
//// 加入内容
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
{
    use epoll;
    worker_connections 6000;
}

http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip $remote_addr $http_x_forwarded_for [$time_local]
    $host "$request_uri" $status
    "$http_referer" "$http_user_agent";
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
    }

}

}
[root@localhost nginx-1.4.4]# /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

[root@localhost nginx-1.4.4]# service nginx start
[root@localhost nginx-1.4.4]# ps aux|grep nginx

 

安装nginx会遇到的错误:

 

//编译安装时遇到的错误

1.  ./configure:
 error: the HTTP rewrite module requires the PCRE library.

--> yum -y install pcre-devel

2.   /configure: error: the HTTP cache module requires md5 functions

from OpenSSL library.   You can either disable the module by using

--without-http-cache option, or install the OpenSSL library into the system,

or build the OpenSSL library statically from the source with nginx by using

--with-http_ssl_module --with-openssl=<path> options.

--> yum -y install openssl openssl-devel

 

=====================我是分割线。========================

四、测试是否解析php文件---虽说nginx和php都启动了,但要想两者结合,必须配置

[root@localhost nginx]# vim /usr/local/nginx/html/2.php
//加入以下内容
<?php
    echo "php works";
?>
[root@localhost nginx]# curl localhost/2.php
php works[root@localhost nginx]#

 

LNMP

标签:

原文地址:http://www.cnblogs.com/frankielf0921/p/5371688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!