1.Mysql安装

Mysql安装在LAMP搭建部分已经记录,此处附上相关博客链接

https://blog.51cto.com/lavender7n/2050883

2.php安装

与LAMP架构中的php模块不同,LNMP架构中的php是以单独的服务php-fpm形式存在。

①下载并解压php包

[root@test_02 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
--2018-01-02 18:54:48--  http://cn2.php.net/distributions/php-5.6.30.tar.gz
正在解析主机 cn2.php.net (cn2.php.net)... 123.125.23.172, 123.125.23.169, 123.125.23.168, ...
正在连接 cn2.php.net (cn2.php.net)|123.125.23.172|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:19274631 (18M) [application/x-gzip]
正在保存至: “php-5.6.30.tar.gz”

100%[===========================================================================>] 19,274,631  1.84MB/s 用时 25s

2018-01-02 18:55:13 (759 KB/s) - 已保存 “php-5.6.30.tar.gz” [19274631/19274631])

②添加用户php-fpm

[root@test_02 src]# useradd -s /sbin/nologin php-fpm

③编译php

[root@test_02 php-5.6.30]# /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-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-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 --with-pear --with-curl  --with-openssl

参数详解:

-prefix=/usr/local/php-fpm :安装路径

--with-config-file-path=/usr/local/php-fpm/etc :配置文件路径

--enable-fpm:启用php-fpm服务

--with-fpm-user=php-fpm :指定用户

--with-fpm-group=php-fpm : :指定用户组

--with-mysql=/usr/local/mysql :指定mysql路径

--with-mysqli=/usr/local/mysql/bin/mysql_config 

--with-pdo-mysql=/usr/local/mysql 

④拷贝&编辑配置文件

[root@test_02 php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
[root@test_02 etc]# vim php-fpm.conf

在配置文件中写入如下内容:

[www]

listen = /tmp/php-fcgi.sock :定义监听方式,监听socket的时候listen.mod的权限 设置才生效

#listen = 127.0.0.1:9000

listen.mode = 666:权限设置

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@test_02 php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@test_02 php-5.6.30]# chmod 755 /etc/init.d/php-fpm
[root@test_02 php-5.6.30]# chkconfig --add php-fpm
[root@test_02 php-5.6.30]# chkconfig php-fpm on
[root@test_02 php-5.6.30]# service php-fpm start
Starting php-fpm  done
[root@test_02 php-5.6.30]# ps aux |grep php-fpm
root      20071  0.2  0.2 123560  4952 ?        Ss   20:05   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm   20072  0.0  0.2 123560  4704 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20073  0.0  0.2 123560  4704 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20074  0.0  0.2 123560  4704 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20075  0.0  0.2 123560  4704 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20076  0.0  0.2 123560  4708 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20077  0.0  0.2 123560  4708 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20078  0.0  0.2 123560  4708 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20079  0.0  0.2 123560  4708 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20080  0.0  0.2 123560  4708 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20081  0.0  0.2 123560  4708 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20082  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20083  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20084  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20085  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20086  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20087  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20088  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20089  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20090  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
php-fpm   20091  0.0  0.2 123560  4712 ?        S    20:05   0:00 php-fpm: pool www
root      20093  0.0  0.0 112680   976 pts/0    S+   20:05   0:00 grep --color=auto php-fpm

3.Nginx安装

①下载解压源码包

[root@test_02 src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
--2018-01-03 20:07:23--  http://nginx.org/download/nginx-1.12.1.tar.gz
正在解析主机 nginx.org (nginx.org)... 95.211.80.227, 206.251.255.63, 2606:7100:1                                     :69::3f, ...
正在连接 nginx.org (nginx.org)|95.211.80.227|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:981093 (958K) [application/octet-stream]
正在保存至: “nginx-1.12.1.tar.gz”

100%[======================================>] 981,093     20.1KB/s 用时 62s

2018-01-03 20:08:25 (15.6 KB/s) - 已保存 “nginx-1.12.1.tar.gz” [981093/981093])

[root@test_02 src]# tar zxf nginx-1.12.1.tar.gz

②编译nginx

[root@test_02 nginx-1.12.1]# ./configure --prefix=/usr/local/nginx
[root@test_02 nginx-1.12.1]# make&&make install

③创建启动脚本并将启动脚本加入服务列表中

[root@test_02 nginx]# vim /etc/init.d/nginx
[root@test_02 nginx]# chmod 755 /etc/init.d/nginx
[root@test_02 nginx]# chkconfig --add nginx
[root@test_02 nginx]# chkconfig nginx on

④编辑nginx配置文件

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;
        }
    }
}