LNMP安装

    这里的N指的是,nginx,mysql的安装和lamp的mysql安装是一样的,不在赘述,这里先安装php

    1.安装php

        解压

[root@localhost src]# tar zxvf php-5.3.27.tar.gz

        创建相关账户

[root@localhost src]# useradd -s /sbin/nologin 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

    出现错误:

./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.

    解决

[root@localhost nginx-1.4.4]# yum -y install pcre-devel

    编译php

[root@localhost  php-5.3.27]# make

       有错误

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

解决

[root@localhost  php-5.3.27]#yum install -y libtool-ltdl-devel

    安装php

[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]#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
[12-Sep-2015 01:38:29] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful

看后面出现的successful,说明成功

    启动php-fpm

[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

        出现一个错误

Starting php-fpm [12-Sep-2015 00:46:07] ERROR: An another FPM instance seems to already listen on /tmp/php-fcgi.sock
[12-Sep-2015 00:46:07] ERROR: FPM initialization failed
 failed

    将已有的kill掉

[root@localhost php-5.3.27]# ps -ef
php-fpm  31382 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31383 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31384 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31385 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31386 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31387 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31388 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31389 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31390 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31391 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31392 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31393 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31394 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31395 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31396 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31397 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31398 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31399 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31400 31381  0 00:41 ?        00:00:00 php-fpm: pool www
php-fpm  31401 31381  0 00:41 ?        00:00:00 php-fpm: pool www
````
[root@localhost php-5.3.27]# kill -9 31381
[root@localhost php-5.3.27]# kill -9 31382
[root@localhost php-5.3.27]# kill -9 31383
[root@localhost php-5.3.27]# kill -9 31384
[root@localhost php-5.3.27]# kill -9 31385
[root@localhost php-5.3.27]# kill -9 31386
[root@localhost php-5.3.27]# kill -9 31387
[root@localhost php-5.3.27]# kill -9 31388
[root@localhost php-5.3.27]# kill -9 31389
[root@localhost php-5.3.27]# kill -9 31390
[root@localhost php-5.3.27]# kill -9 31391
[root@localhost php-5.3.27]# kill -9 31392
[root@localhost php-5.3.27]# kill -9 31393
[root@localhost php-5.3.27]# kill -9 31394
[root@localhost php-5.3.27]# kill -9 31395
[root@localhost php-5.3.27]# kill -9 31396
[root@localhost php-5.3.27]# kill -9 31397
[root@localhost php-5.3.27]# kill -9 31398
[root@localhost php-5.3.27]# kill -9 31399
[root@localhost php-5.3.27]# kill -9 31400
[root@localhost php-5.3.27]# kill -9 31401

    再启动,成功

如果想让它开机启动,执行:

chkconfig php-fpm on

检测是否启动:

ps aux |grep php-fpm




    2.nginx的官网:http://nginx.org,在搜狐站点搜:http://mirrors.sohu.com/nginx/ 安装nginx,

解压

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

    错误

./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.

    解决

[root@localhost nginx-1.4.4]# yum -y install pcre-devel

   编译

[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 on    //开机启动

    更改nginx配置

[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

最后显示successful,说明成功

    启动nginx

[root@localhost nginx-1.4.4]#service nginx start



    测试时候能解析php

    创建测试文件

[root@localhost nginx-1.4.4]#vim /usr/local/html/1.php
<?php
        echo "learning lnmp,you come here that you are done the pnmp";
?>

    保存退出,

    测试

[root@localhost nginx-1.4.4]# curl localhost/1.php
learning lnmp,you come here that you are done the pnmp

把防火墙关掉,在浏览器中输入ip,能发现

LNMP安装

测试成功,继续学习


你可能感兴趣的:(LNMP安装)