LNMP搭建

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章