服务器配置 centos7.4+nginx+swoole+php7+mysql
1. 用xshell客户端连接你的服务器,
我用的xshell 家庭免费版
下载地址:https://www.softpedia.com/get/Network-Tools/Telnet-SSH-Clients/Xshell-Free.shtml
2. 安装nginx
安装nginx
# yum install nginx
启动nginx
# systemctl start nginx
设置nginx服务器开机自启动
# systemctl enable nginx.service
检查开机自动是否设置成功
# systemctl list-dependencies | grep nginx
在浏览器中输入服务器的ip地址,如果有欢迎的界面说明nginx安装成功
有些阿里云服务器用户可能出现无法访问情况,需要进行安全组配置,添加规则-》允许80端口访问
3. 安装5.7.x的mysql
安装5.7.x的mysql源
# yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
检查mysql源是否安装成功
# yum repolist enabled | grep "mysql.*-community.*"
安装mysql
# yum -y install mysql-community-server install mysql-community-devel
启动mysql
# systemctl start mysqld.service
检查mysql启动是否正常
# systemctl status mysqld
设置mysqld服务开机自启动
# systemctl enable mysqld.service
检查mysqld开机自启动是否设置成功
# systemctl list-dependencies | grep mysqld
这里说明一下mysql5.7以后的增强了安全机制,所以使用yum安装系统会自动生成一个随机的密码
查看mysql的随机密码
# grep 'temporary password' /var/log/mysqld.log
使用查询得到的随机密码在终端登录
# mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位)
# ALTER USER 'root'@'localhost' IDENTIFIED BY '你要设置的密码';
退出mysql客户端,用刚才修改的密码登录确保密码修改成功
# mysql -uroot -pxxxxx
4. 安装最新的php71的源并,安装对应的扩展支持安装最新的php71的源并,安装对应的扩展支持
安装php71的源(地址在工具/原料里面找)
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
检查源是否安装成功
# yum repolist enabled | grep "webtatic*"
安装php71和对应的扩展(上面工具和原料的地址对扩展都有详细的说明)
# yum -y install php71w php71w-fpm
# yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt
# yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel
# yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache
验证php是否安装成功
# php -v
验证对应的扩展是否安装成功
# php -m
设置php-fpm并检测php-fpm的运行状态
启动php-fpm
# systemctl start php-fpm
检查启动是否成功
# systemctl status php-fpm
设置开机自启动
# systemctl enable php-fpm.service
检查开机自启动是否设置成功
# systemctl list-dependencies | grep php-fpm
# ps -ef | grep php-fpm
5. 安装swoole
方法一:PECL安装
swoole项目已收录到PHP官方扩展库,如果不是应用在微信小程序中可以直接使用pecl安装
# pecl install swoole
方法二:编译安装
引用官放文档:
安装swoole前必须保证系统已经安装了下列软件
php-5.3.10 或更高版本
gcc-4.4 或更高版本
make
autoconf
pcre (centos系统可以执行命令:yum install pcre-devel)
补充说明:
微信小程序要求webview中的网址需要https协议,所以需要在编译安装时加入编译参数--enable-openssl 启用ssl支持
具体操作步骤如下:
a). 安装相关依赖
安装gcc
# yum install -y gcc
安装make
# yum install -y make
安装autoconf
# yum install -y autoconf
安装pcre
# yum install -y pcre-devel
安装openssl
# yum install -y openssl install -y openssl-devel
b). 下载源代码包后,在终端进入源码目录,执行下面的命令进行编译和安装
下载地址:https://github.com/swoole/swoole-src/releases
# cd /usr/swoole-2.1.3
# phpize
# ./configure --enable-openssl
# make
# sudo make install
/etc/php.d中加入swoole.ini
; Enable swoole extension module
extension=swoole.so
查看swoole扩展是否安装成功
# php -m
6. 修改nginx配置文件,支持php-fpm、pathinfo、ssl(https协议)
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name www.yourdomain.com; #域名
root /usr/share/nginx/html;
location / {
index index.html index.htm index.php l.php;
autoindex on;
try_files $uri $uri/ /index.php?s=$uri&$args;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 443;
server_name www.funssky.com;
ssl on;
root /usr/share/nginx/html;
ssl_certificate cert/214624*****0908.pem; #ssl 证书
ssl_certificate_key cert/214624*****0908.key; #ssl 私钥
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm index.php l.php;
autoindex on;
try_files $uri $uri/ /index.php?s=$uri&$args;
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
至此服务器准备工作已经完成~