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

前端之家收集整理的这篇文章主要介绍了centos服务器搭建 NGINX+PHP+MySQL+Node.js前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

基于centos7.4(x64)系统的服务器搭建,安装的主要程序有:

@H_404_3@
  • Nginx 1.12.1
  • PHP 7.1.10
  • MysqL 5.7
  • Node.js 6.11.4(waiting...)
  • 环境准备

    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    #类库安装

    常用命令:

    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),开启网站压缩、重定向HTTPS

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

    相关网站:
    Nginxhttp://nginx.org/

    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),开启opache

    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

    相关网站:
    PHPhttp://php.net/

    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;

    相关网站:
    MysqLhttp://dev.mysql.com/download...

    猜你在找的CentOS相关文章