美文网首页我爱编程
(从零构建tp5blog一)contOS6.5lnpm的安装

(从零构建tp5blog一)contOS6.5lnpm的安装

作者: 易_3da2 | 来源:发表于2018-05-23 11:07 被阅读0次

    contOS6.5安装lnmp环境

    安装之前需要先说明一点点东西

    1. 端口

    2. 防火墙contOS6为iptables contOS7的话采用的是另一款软件firewalld

    3.服务器厂商的安全策略

    我目前碰到的大概就是这三类情况,这三点都会导致你连接不上你的网站/服务

    先安装nginx

    service这个可以理解为管理系统服务的软件 

    我使用的是国外的服务器,好处是不需要备案...


    yum安装nginx1.14

    yum install nginx

    这个时候会报一个No package nginx available.的错误

    原因是contOS6 yum源里面没有nginx的包

    我们有两个选择,

    一 是去官网下载源码自己编译(我不喜欢编译,毕竟不是专业运维)

    二 更换yum源

        #下载脚本

            wget http://www.atomicorp.com/installers/atomic

        #执行脚本安装

            sh ./atomic

        #更新yum源

            yum check-update

    三 正式安装nginx

    #删除系统自带的软件包

    yum remove httpd* php*

    #安装nginx

    yum install -y nginx

    #设置nginx开机启动

    chkconfig nginx on

    #启动nginx

    service nginx start

    查看nginx版本 

    四 这个时候我们去访问自己的域名却没有反应

           回到之前的提示

    1.  netstat -tunpl   #检查端口以及服务

    服务存在

    1. 检查防火墙

    不要直接把ipyables干掉,留个备份以后少一些麻烦

    如果你觉得不爽直接禁用iptables也可以

    servcie iptables stop   --临时关闭防火墙

    chkconfig iptables off  --永久关闭防火墙 开机不再自启

    yum install vim -y //我习惯vim  vi是一样的

    vim /etc/sysconfig/iptables

    发现确实80端口没开

    那我们就开启80 3306 443 端口 添加

    -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 443 -j ACCEPT

    -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

    修改后

    重启iptables

    /etc/init.d/iptables restart   或者service iptables restart

    重新访问OK

    nginx success

    Nginx所在的地址为/etc/nginx/    /etc/nginx/conf.d/deafult.conf

    默认的index.html 地址为/usr/share/nginx/html


    yum 安装php7

    (现在自己玩肯定是用php7)

    1.拉取php7.的包

    # CentOs 6.x

    rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

    rpm -Uvhhttps://mirror.webtatic.com/yum/el6/latest.rpm

    # CentOs 7.x

    rpm -Uvhhttps://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

    rpm -Uvhhttps://mirror.webtatic.com/yum/el7/webtatic-release.rpm

    2.安装php7.0

    yuminstall php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlndphp70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel -y

    安装memcache和redis 需要的时候再启动

    yum install -y memcached redis

    3.修改配置文件让NGINX将php 文件转给 php-fpm处理

    启动php-fpm

    设置开机自启 chkconfig php-fpm on

    servicephp-fpm start

    vim/etc/nginx/conf.d/deafult.conf

       location / {

            #root  /usr/share/nginx/html;

            root  /var/www/html;

            index index.html index.htm index.php;

    }

            location ~* \.php$ {

                          root   /var/www/html;

                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;

            }

    nginx -s reload //热加载

    vim /var/www/html/index.php

    <?php

    phpinfo();

    保存退出

    :wq

    访问IP


    yum 安装mysql5.5

    (mysql5.6/5.7/8.0,暂时就不折腾了,想装的可以自己百度/Google)

    1.安装

    yum install -y mysql mysql-server

    #启动MySQL

    service mysqld start

    #设为开机启动

    chkconfig mysqld on

    #拷贝配置文件(注意:如果/etc目录下面默认有一个my.cnf,直接覆盖即可)

    cp /usr/share/mysql/my-medium.cnf  /etc/my.cnf

    2. 设置root用户密码

    mysql_secure_installation

    # 回车,根据提示输入Y,输入2次密码,回车,根据提示一路输入Y,最后出现:Thanks for using MySQL!

    #  MySql密码设置完成,重新启动 MySQL:

    #重启

    service mysqld restart

    3.允许远程访问

    mysql -uroot -p

    输入密码

    use mysql

    //允许远程访问  设置的为你远程访问时的账号密码

    GRANT ALL PRIVILEGES ON *.* TO 'yourname'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;

    //刷新

    flush privileges;

    这里尝试远程访问OK

    至此lnmp已经全部装好.

    下篇文章 我会写关于域名解析 https证书 swoole扩展的安装 和版本控制git

    如果这篇文章对你有帮助请点个赞哦.

    相关文章

      网友评论

        本文标题:(从零构建tp5blog一)contOS6.5lnpm的安装

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