美文网首页
linux centos 7.2 lnmp+redis搭建

linux centos 7.2 lnmp+redis搭建

作者: henryspace | 来源:发表于2017-11-20 16:42 被阅读0次

    一、配置防火墙,开启80端口、3306端口

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

    1、关闭firewall:

    systemctl stop firewalld.service #停止firewall

    systemctl disable firewalld.service #禁止firewall开机启动

    2、安装iptables防火墙

    yum install iptables-services #安装

    vi /etc/sysconfig/iptables #编辑防火墙配置文件

    # Firewall configuration written by system-config-firewall
    
    # Manual customization of this file is not recommended.
    
    *filter
    
    :INPUT ACCEPT [0:0]
    
    :FORWARD ACCEPT [0:0]
    
    :OUTPUT ACCEPT [0:0]
    
    -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
    
    -A INPUT -p icmp -j ACCEPT
    
    -A INPUT -i lo -j ACCEPT
    
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
    
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
    
    -A INPUT -j REJECT --reject-with icmp-host-prohibited
    
    -A FORWARD -j REJECT --reject-with icmp-host-prohibited
    
    COMMIT
    

    :wq! #保存退出

    systemctl restart iptables.service #最后重启防火墙使配置生效

    systemctl enable iptables.service #设置防火墙开机启动

    二、关闭SELINUX

    vi /etc/selinux/config

    #SELINUX=enforcing #注释掉
    
    #SELINUXTYPE=targeted #注释掉
    
    SELINUX=disabled #增加
    

    :wq! #保存退出

    setenforce 0 #使配置立即生效

    Lnmp安装

    1.安装nginx

    yum install yum-priorities -y
    wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
    rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
    yum install nginx

    2.启动nginx

    systemctl start nginx.service #启动nginx
    systemctl stop nginx.service #停止
    systemctl restart nginx.service #重启
    systemctl enable nginx.service #设置开机启动
    server 配置

    server {
        listen 80;
        server_name api.xxx.com;
    
        root /www/projectname/public;
    
        location /api {
            index index.php index.html index.htm;
    
            if (!-e $request_filename) {
                rewrite . /index.php last;
            }
        }
    
        location ~ \.php$ {
            root /www/projectname/public;
            
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME /www/projectname/public$fastcgi_script_name;
            
            include fastcgi_params;
        }
    }
    

    3.安装mariadb(MySQL)

    yum install mariadb mariadb-server #询问是否要安装,输入Y即可自动安装,直到安装完成
    systemctl start mariadb.service #启动MariaDB
    systemctl stop mariadb.service #停止MariaDB
    systemctl restart mariadb.service #重启MariaDB
    systemctl enable mariadb.service #设置开机启动

    4.安装php
    CentOS/RHEL 7.x:

    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

    如果是centos6,那么执行以下代码:
    CentOS/RHEL 6.x:

    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

    yum -y install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel

    5,安装redis
    yum install -y redis

    [root@localhost bin]# whereis redis-cli
    redis-cli: /usr/bin/redis-cli

    [root@localhost bin]# whereis redis-server
    redis-server: /usr/bin/redis-server

    redis-server &

    https://www.cyberciti.biz/faq/how-to-install-php-7-2-on-centos-7-rhel-7/

    相关文章

      网友评论

          本文标题:linux centos 7.2 lnmp+redis搭建

          本文链接:https://www.haomeiwen.com/subject/mugvvxtx.html