开发者社区> 问答> 正文

[阿里云免费套餐]在 CentOS7 上安装 OpenResty PHP7.1 MariaDB10.2

来自: https://www.mf8.biz/centos7-openresty-php7-1-mariadb10-2/


系统准备


一、卸载不必须的组件 yum -y groupremove "Basic Web Server" "MySQL Database server" "MySQL Database client" "File and Print Server"

二、安装 EPEL rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

三、防火墙设置
#开启防火墙
systemctl start firewalld.service

#开放 http 80 和 https 443 和 SSH 22 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent

#生效规则
firewall-cmd --reload



四、设置 DNS 服务器(可选)
如果服务器无法访问 Github 的话,需要修改一下公共 DNS
修改 /etc/resolv.conf,添加
nameserver 223.5.5.5
nameserver 223.6.6.6


五、添加用户 useradd www

MariaDB


一、安装 MariaDB 10.2
wget https://gist.githubusercontent.com/ivmm/6e2f08a5ca21cfd3417e0339ac7c79fa/raw/8e25aff87e89c72fe2405e45389366114b8c69c8/MariaDB.repo
yum install MariaDB-server MariaDB-client -y


二、开启并设置开机启动
systemctl start mariadb.service #启动MariaDB
systemctl enable mariadb.service #设置开机启动


三、安全设置并设置密码,SSH 中输入: mysql_secure_installation

过程介绍: 基本上一路 y 即可


Enter current password for root (enter for none):
解释:输入当前 root 用户密码,默认为空,直接回车。
Set root password? [Y/n]  y
解释:要设置 root 密码吗?输入 y 表示愿意。
Remove anonymous users? [Y/n]  y
解释:要移除掉匿名用户吗?输入 y 表示愿意。
Disallow root login remotely? [Y/n]  y
解释:不想让 root 远程登陆吗?输入 y 表示愿意。
Remove test database and access to it? [Y/n]  y
解释:要去掉 test 数据库吗?输入 y 表示愿意。
Reload privilege tables now? [Y/n]  y
解释:想要重新加载权限吗?输入 y 表示愿意。


PHP


一、安装 REMI 源 rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/remi/enterprise/remi-release-7.rpm

二、确认 REMI-PHP 7.1sed -i "/php71\/mirror/{n;s/enabled=0/enabled=1/g}" /etc/yum.repos.d/remi-php71.repo

三、安装 PHP yum install php php-bcmath php-fpm php-gd php-json php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-pdo_dblib php-recode php-snmp php-soap php-xml php-pecl-zip -y

四、开启 PHP systemctl start php-fpm.service #启动 PHP-FPM
systemctl enable php-fpm.service #设置开机启动




OpenResty


一、安装 OpenResty
cd /etc/yum.repos.d
wget https://gist.githubusercontent.com/ivmm/06b18486bfdb908c45616580fecad2c6/raw/4cf71647d2824d2077c1bae9429e0f29d62d3f64/OpenResty.repo

yum install openresty -y



二、开启 OpenResty
systemctl start openresty.service #启动 OpenResty
systemctl enable openresty.service #设置开机启动



三、创建相关目录
mkdir /usr/local/openresty/nginx/conf/vhost -p
mkdir /home/wwwroot/default -p



四、修改 nginx.confc
cd /usr/local/openresty/nginx/conf/
mv nginx.conf nginx_bk.conf
vi nginx.conf

user www www;
worker_processes auto;


error_log /var/log/error_openresty.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;


events {
    use epoll;
    worker_connections 51200;
    multi_accept on;
    }


http {
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 1024m;
    client_body_buffer_size 10m;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 120;
    server_tokens off;
    tcp_nodelay on;


    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;


    #Gzip Compression
    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 6;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_vary on;
    gzip_types
        text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
        text/javascript application/javascript application/x-javascript
        text/x-json application/json application/x-web-app-manifest+json
        text/css text/plain text/x-component
        font/opentype application/x-font-ttf application/vnd.ms-fontobject
        image/x-icon;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";


    #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;




######################## default ############################
    server {
    listen 80;
    server_name _;
    root /home/www/mf8;
    index index.html index.htm index.php;
    location ~ [^/]\.php(/|$) {
        #fastcgi_pass remote_php_ip:9000;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
        expires 30d;
        access_log off;
        }
    location ~ .*\.(js|css)?$ {
        expires 7d;
        access_log off;
        }
    }


########################## vhost #############################
    include vhost/*.conf;
}


五、修改 php-fpm.conf
cd /etc
mv php-fpm.conf php-fpm_bk.conf
wget https://gist.github.com/ivmm/f58683ee553bea14884acbbfaafcbd5a/raw/0f3f15f52f9b235ce884eaa20538c6dfcf5ae70d/php-fpm.conf


六、下载探针一枚
cd /home/wwwroot/default
wget https://gist.github.com/ivmm/b014ad75c834036a44838553ec00b4b7/raw/ba41a0f29847d8d2230aca9ee795a6d02d27a617/tanzhen.php
mv tanzhen.php index.php



七、重启 php 和 Openresty
service php-fpm restart
service openresty restart



八、访问 http://你的公网ip/ 是不是已经是探针了!

展开
收起
妙正灰 2016-12-22 13:35:56 9771 0
1 条回答
写回答
取消 提交回答
  • 静静的看着你们
    不错,学习了
    2016-12-22 14:54:10
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载