资讯专栏INFORMATION COLUMN

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

codergarden / 1760人阅读

摘要:基于系统的服务器搭建,安装的主要程序有环境准备系统版本和内核升级类库安装常用命令查看系统版本安装源码配置编译并安装相关操作启动重启停止修改配置文件开启网站压缩重定向开启网站压缩

</>复制代码

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

  2. NGINX 1.12.1

  3. PHP 7.1.10

  4. MySQL 5.7

  5. Node.js 8.8.1

环境准备

</>复制代码

  1. yum -y update #系统版本和内核升级
  2. 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 #类库安装

常用命令:

</>复制代码

  1. lsb_release -a #查看系统版本
NGINX安装(源码)

</>复制代码

  1. wget http://nginx.org/download/nginx-1.12.1.tar.gz
  2. tar zxvf nginx-1.12.1.tar.gz
  3. cd nginx-1.12.1
  4. ./configure --prefix=/www --with-http_ssl_module --with-stream --with-http_v2_module #配置NGINX
  5. make && make install #编译并安装
  6. cp /www/sbin/nginx /bin/nginx
  7. #nginx相关操作
  8. nginx #启动
  9. nginx -s reload|stop #重启/停止

修改NGINX配置文件(/www/conf/nginx.conf),开启网站压缩、重定向HTTPS

</>复制代码

  1. worker_processes 1;
  2. events {
  3. worker_connections 1024;
  4. }
  5. http {
  6. include mime.types;
  7. default_type application/octet-stream;
  8. sendfile on;
  9. keepalive_timeout 65;
  10. #开启网站压缩
  11. gzip on;
  12. gzip_min_length 1k;
  13. gzip_buffers 4 16k;
  14. gzip_comp_level 3;
  15. gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
  16. gzip_vary off;
  17. gzip_disable "MSIE [1-6].";
  18. server {
  19. listen 80;
  20. server_name ***.com www.***.com; #填写绑定证书的域名
  21. rewrite ^(.*) https://$host$1 permanent; #http重定向https
  22. }
  23. server {
  24. listen 443;
  25. server_name www.***.com ***.com; #填写绑定证书的域名
  26. ssl on;
  27. ssl_certificate cert/1_cinglong.com_bundle.crt;
  28. ssl_certificate_key cert/2_cinglong.com.key;
  29. ssl_session_timeout 5m;
  30. ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
  31. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置
  32. ssl_prefer_server_ciphers on;
  33. location / {
  34. root html;
  35. index index.php index.html index.htm;
  36. }
  37. location ~* .php$ {
  38. fastcgi_index index.php;
  39. fastcgi_pass 127.0.0.1:9000;
  40. include fastcgi_params;
  41. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  42. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  43. client_max_body_size 50m;
  44. }
  45. }
  46. }

相关网站:
NGINX:http://nginx.org/

PHP安装(源码)

</>复制代码

  1. #下载并安装PHP
  2. cd ../ #返回root目录
  3. wget http://cn2.php.net/distributions/php-7.1.10.tar.gz
  4. tar zxvf php-7.1.10.tar.gz
  5. cd php-7.1.10
  6. ./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
  7. make && make install
  8. #配置文件
  9. cp php.ini-development /php/lib/php.ini
  10. cp /php/etc/php-fpm.conf.default /php/etc/php-fpm.conf
  11. cp /php/etc/php-fpm.d/www.conf.default /php/etc/php-fpm.d/www.conf
  12. cp sapi/fpm/php-fpm /usr/local/bin
  13. cp /usr/local/bin/php-fpm /bin/php-fpm
  14. #PHP相关操作
  15. php-fpm #启动
  16. killall php-fpm #停止

修改PHP配置(/php/lib/php.ini),开启opache

</>复制代码

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

相关网站:
PHP:http://php.net/

MySQL安装(yum)

</>复制代码

  1. cd ../
  2. wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
  3. rpm -ivh mysql57-community-release-el7-11.noarch.rpm
  4. yum -y install mysql-community-server
  5. service mysqld start #启动MySQL
  6. #修改密码
  7. grep "temporary password" /var/log/mysqld.log #获取自动生成密码
  8. mysql -uroot -p #用上一步获取的密码登录
  9. ALTER USER "root"@"localhost" IDENTIFIED BY "***"; #修改MySQL密码
  10. exit;

相关网站:
MySQL:http://dev.mysql.com/download...

Node.js安装(官方已编译版本)

</>复制代码

  1. cd ../
  2. wget https://nodejs.org/dist/v8.8.1/node-v8.8.1-linux-x64.tar.xz #下载
  3. xz -d node-v8.8.1-linux-x64.tar.xz
  4. tar -xvf node-v8.8.1-linux-x64.tar #解压
  5. mv node-v8.8.1-linux-x64 /usr/local/node #位置转移
  6. vim ~/.bash_profile #找到 PATH=$PATH:$HOME/bin,在后面添加路径(:/usr/local/node/bin)
  7. source ~/.bash_profile #重载
  8. node -v #版本查看

相关网站:
MySQL:https://nodejs.org/en/downloa...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/30663.html

相关文章

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

    摘要:基于系统的服务器搭建,安装的主要程序有环境准备系统版本和内核升级类库安装常用命令查看系统版本安装源码配置编译并安装相关操作启动重启停止修改配置文件开启网站压缩重定向开启网站压缩 基于centos7.4(x64)系统的服务器搭建,安装的主要程序有: NGINX 1.12.1 PHP 7.1.10 MySQL 5.7 Node.js 8.8.1 环境准备 yum -y update...

    lushan 评论0 收藏0

发表评论

0条评论

codergarden

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<