基于centos7.4(x64)系统的服务器搭建,安装的主要程序有:
- 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 #类库安装
常用命令:
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;
}
}
}
相关网站:
NGINX:http://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
相关网站:
PHP:http://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;
相关网站:
MySQL:http://dev.mysql.com/download…
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…