centos服務器搭建 NGINX+PHP+MySQL+Node.js

基於centos7.4(x64)系統的服務器搭建,安裝的主要程序有:javascript

  • NGINX 1.12.1
  • PHP 7.1.10
  • MySQL 5.7
  • Node.js 8.8.1

環境準備

yum -y update    #系統版本和內核升級
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel curl curl-devel libxslt-devel libevent-devel unzip zip    #類庫安裝

經常使用命令:php

lsb_release -a    #查看系統版本

NGINX安裝(源碼)

wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/www --with-http_ssl_module --with-stream --with-http_v2_module    #配置NGINX
make &&  make install    #編譯並安裝
cp /www/sbin/nginx /bin/nginx

#nginx相關操做
nginx    #啓動
nginx -s reload|stop    #重啓/中止

修改NGINX配置文件(/www/conf/nginx.conf),開啓網站壓縮、重定向HTTPScss

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    #開啓網站壓縮
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_comp_level 3;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";

    server {
        listen       80;
        server_name ***.com www.***.com;    #填寫綁定證書的域名
        rewrite ^(.*) https://$host$1 permanent;    #http重定向https
    }

    server {
        listen 443;
        server_name www.***.com ***.com; #填寫綁定證書的域名
        ssl on;
        ssl_certificate cert/1_cinglong.com_bundle.crt;
        ssl_certificate_key cert/2_cinglong.com.key;
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照這個協議配置
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照這個套件配置
        ssl_prefer_server_ciphers on;
        location / {
            root   html;
            index  index.php index.html index.htm;
        }
        location ~* \.php$ {
            fastcgi_index   index.php;
            fastcgi_pass    127.0.0.1:9000;
            include         fastcgi_params;
            fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
            client_max_body_size  50m;
        }
    }

}

相關網站:
NGINX:http://nginx.org/html

PHP安裝(源碼)

#下載並安裝PHP
cd ../    #返回root目錄
wget http://cn2.php.net/distributions/php-7.1.10.tar.gz
tar zxvf php-7.1.10.tar.gz
cd php-7.1.10
./configure --prefix=/php --with-curl --with-mysqli --with-gd --with-freetype-dir  --with-pdo-mysql --with-zlib --enable-shmop --with-gettext --with-pdo-sqlite --with-pear --with-iconv-dir --with-openssl --with-libxml-dir --with-xmlrpc --with-xsl --with-png-dir --enable-gd-native-ttf --enable-fpm --enable-mbstring --enable-libxml --enable-xml --enable-gd-native-ttf --enable-bcmath --enable-pdo --disable-fileinfo --enable-pcntl --enable-mbregex --enable-opcache --enable-zip --enable-sockets --with-jpeg-dir=DIR
make && make install

#配置文件
cp php.ini-development /php/lib/php.ini
cp /php/etc/php-fpm.conf.default /php/etc/php-fpm.conf
cp /php/etc/php-fpm.d/www.conf.default /php/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
cp /usr/local/bin/php-fpm /bin/php-fpm

#PHP相關操做
php-fpm    #啓動
killall php-fpm    #中止

修改PHP配置(/php/lib/php.ini),開啓opachejava

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
zend_extension=/php/lib/php/extensions/no-debug-non-zts-20160303/opcache.so

相關網站:
PHP:http://php.net/node

MySQL安裝(yum)

cd ../
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql-community-server

service mysqld start    #啓動MySQL

#修改密碼
grep 'temporary password' /var/log/mysqld.log    #獲取自動生成密碼
mysql -uroot -p    #用上一步獲取的密碼登陸
ALTER USER 'root'@'localhost' IDENTIFIED BY '***';    #修改MySQL密碼
exit;

相關網站:
MySQL:http://dev.mysql.com/download...mysql

Node.js安裝(官方已編譯版本)

cd ../
wget https://nodejs.org/dist/v8.8.1/node-v8.8.1-linux-x64.tar.xz    #下載
xz -d node-v8.8.1-linux-x64.tar.xz
tar -xvf node-v8.8.1-linux-x64.tar    #解壓

mv node-v8.8.1-linux-x64 /usr/local/node    #位置轉移

vim ~/.bash_profile    #找到 PATH=$PATH:$HOME/bin,在後面添加路徑(:/usr/local/node/bin)

source ~/.bash_profile    #重載

node -v    #版本查看

相關網站:
MySQL:https://nodejs.org/en/downloa...linux

相關文章
相關標籤/搜索