美文网首页树莓派/香橙派.Space
(VPS)Centos7 安装LNMP环境

(VPS)Centos7 安装LNMP环境

作者: 不着调的小男生 | 来源:发表于2017-01-16 19:04 被阅读220次

    就最近买了VPS,才有了这些文章.准备开始写博客了.环境我们采用比较流行的,相对百度老的资料,本文还是相对比较新的.也许希望大家给以后的小站支持.
    LNMP:CentOS7+PHP7+Nginx+MariaDB
    如果文章有错,请指出,方便修正!


    软件包更新:

    sudo yum update -y
    

    epel,remi库登记

    sudo yum -y install epel-release
    wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    sudo rpm -ivh remi-release-7.rpm
    

    vim,git安装

    sudo yum install vim git
    

    修改时间(我国外的VPS,所以改不改都无所谓)

    sudo timedatectl set-timezone Asia/xxx
    

    Nginx安装

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

    Nginx的设置

    /etc/nginx/conf.d/default.conf

    server {
        listen       80;
        server_name  example.com;
    
        access_log  /var/log/nginx/laos.access.log;
        error_log  /var/log/nginx/laos.error.log warn;
    
        root   /vagrant/laos/webroot;
        index  index.html index.php;
    
        location / {
            try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args;
        }
    
        location ~ \.php$ {
            try_files      $uri =404;
            fastcgi_pass   unix:/var/run/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
    

    目录位置:/etc/nginx/nginx.conf

    user  nginx;
    worker_processes  auto;
    worker_rlimit_nofile 100000;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  2048;
        multi_accept on;
        use epoll;
    }
    
    
    http {
        server_tokens off;
        include       /etc/nginx/mime.types;
        default_type  text/html;
        charset UTF-8;
    
        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       off;
        tcp_nopush     on;
        tcp_nodelay    on;
    
    
        keepalive_timeout 10;
        client_header_timeout 10;
        client_body_timeout 10;
        reset_timedout_connection on;
        send_timeout 10;
    
        limit_conn_zone $binary_remote_addr zone=addr:5m;
        limit_conn addr 100;
    
        gzip on;
        gzip_http_version 1.0;
        gzip_disable "msie6";
        gzip_proxied any;
        gzip_min_length 1024;
        gzip_comp_level 6;
        gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
        open_file_cache off;
    
        client_max_body_size 20m;
        server_names_hash_bucket_size 64;
        include /etc/nginx/conf.d/*.conf;
    }
    

    Nginx起動

    sudo systemctl start nginx
    sudo systemctl enable nginx
    

    PHP7安装(安装必要的包)

    sudo yum --enablerepo=epel,remi,remi-php70w install php70w php70w-php-mcrypt php70w-php-mbstring php70w-php-fpm php70w-php-gd php70w-php-pecl-xdebug php70w-php-pecl-redis php70w-php-pecl-imagick-devel php70w-php-pecl-imagick php70wphp-mysqlnd php70w-php-intl php70w-php-bcmath php70w-php-pecl-zip php70w-php-xmlrpc php70w-php-xml  php70w-php-pecl-http php70w-php-pecl-http-devel php70w-php-opcache
    

    Nginx通过路劲

    cat /opt/remi/php70/enable
    export PATH=/opt/remi/php70/root/usr/bin:/opt/remi/php70/root/usr/sbin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/opt/remi/php70/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    export MANPATH=/opt/remi/php70/root/usr/share/man:${MANPATH}
    

    ~/.bashrc

    export PATH=/opt/remi/php70/root/usr/bin:/opt/remi/php70/root/usr/sbin${PATH:+:${PATH}}
    export LD_LIBRARY_PATH=/opt/remi/php70/root/usr/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    export MANPATH=/opt/remi/php70/root/usr/share/man:${MANPATH}
    

    source ~/.bashrc

    確認

    /etc/opt/remi/php70/php-fpm.d/www.conf

    user = nginx
    group = nginx
    listen = /var/run/php-fpm.sock
    listen.owner = nginx
    listen.group = nginx
    listen.mode = 0666
    

    php-fpm起動

    /etc/systemd/system/php-fpm.service

    
    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target
    
    [Service]
    Type=simple
    PIDFile=/var/run/php-fpm.pid
    ExecStart=/opt/remi/php70/root/usr/sbin/php-fpm --nodaemonize --fpm-config /etc/opt/remi/php70/php-fpm.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    
    
    [Install]
    WantedBy=multi-user.target
    
    sudo systemctl start php-fpm
    sudo systemctl enable php-fpm
    

    为了能够是HTTP防火墙设置访问

    sudo firewall-cmd --add-service=http --permanent
    sudo firewall-cmd --reload
    

    MariaDB安装(从官方请从网站资料库)

    /etc/yum.repos.d/mariadb.repo

    # MariaDB 10.1 CentOS repository list - created 2017-01-16 10:19 UTC
    # http://downloads.mariadb.org/mariadb/repositories/
    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.1/centos7-amd64
    gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck=1
    

    MariaDB正式安装

    sudo yum install MariaDB-server MariaDB-client MariaDB-devel 
    

    设置

    sudo mkdir /home/mysql
    sudo chown mysql. /home/mysql
    

    /etc/my.cnf.d/server.cnf

    [mysqld]
    character-set-server=utf8
    plugin-load = handlersocket.so
    log-bin=mysql-bin
    expire_logs_days = 30
    secure_file_priv=/home/mysql
    

    起動

    sudo systemctl start mariadb.service
    sudo systemctl enable mariadb.service
    

    初回设定

    mysql_secure_installation
    

    连接

    mysql -u root -p
    CREATE SCHEMA `laos` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
    

    相关文章

      网友评论

        本文标题:(VPS)Centos7 安装LNMP环境

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