美文网首页
CentOS搭建PHP/Nginx环境

CentOS搭建PHP/Nginx环境

作者: Captain_tu | 来源:发表于2017-07-28 09:44 被阅读78次
    1. 安装mysql
      yum -y install mysql
      yum -y install mysql-devel
      wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
      rpm -ivh mysql-community-release-el7-5.noarch.rpm
      yum install mysql-community-server
      service mysqld restart
    2. 安装nginx
      yum install gcc-c++
      yum install -y pcre pcre-devel
      yum install -y zlib zlib-devel
      yum install -y openssl openssl-devel
      wget https://nginx.org/download/nginx-1.12.1.tar.gz
      tar -zxvf nginx-1.12.1.tar.gz
      cd nginx-1.12.1
      ./configure
      make & make install
      启动nginx
      cd /usr/local/nginx/sbin/
      ./nginx
      ./nginx -s stop 此方式停止步骤是待nginx进程处理任务完毕进行停止。
      ./nginx -s quit 此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
      ./nginx -s reload
      当 ngin x的配置文件 nginx.conf 修改后,要想让配置生效需要重启 nginx,使用-s reload不用先停止 ngin x再启动 nginx 即可将配置信息在 nginx 中生效,如下:
      3.安装composer
      curl -sS https://getcomposer.org/installer | php
      mv composer.phar /usr/local/bin/composer
    3. 【问题】虚拟机VMVare中启动nginx,本地可以ping通但是无法访问?
      CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙
      • 关闭firewall:

        systemctl stop firewalld.service #停止firewall
        systemctl disable firewalld.service #禁止firewall开机启动
        firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
        
      • 改用iptable

          yum install iptables-services
          mv iptables iptables-old
          systemctl restart iptables.service
          systemctl enable iptables.service
          vim /etc/sysconfig/iptables  //add -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
        
    4. 【问题】创建nginx服务,以及开机自动启动nginx
      1. vim /usr/lib/systemd/system/nginx.service

         [Unit]
         Description=nginx - high performance web server
         Documentation=http://nginx.org/en/docs/
         After=network.target remote-fs.target nss-lookup.target
        
         [Service]
         Type=forking
         PIDFile=/run/nginx.pid
         ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
         ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
         ExecReload=/bin/kill -s HUP $MAINPID
         ExecStop=/bin/kill -s QUIT $MAINPID
         PrivateTmp=true
        
         [Install]
         WantedBy=multi-user.target
        
      2. 修改权限
        chmod 754 nginx.service

      3. 开机启动
        systemctl enable nginx.service

      4. 查看系统日志
        journalctl -f -u nginx.service

      5. 【问题】

        • 提示access denied

          [root@localhost system]#  systemctl enable nginx.service
          Failed to execute operation: Access denied
          

          【解决】执行systemctl daemon-reexec

        • centos7 在init.d中创建nginx脚本,执行service start nginx时,脚本没有退出,ctrl+c发现nginx启动成功,但是service stop nginx发现nginx没有停止
          【解决】CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。

      6. 关于systemmd 参考centos7中systemctl的使用
        如上,CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。

        1. 与service对比
          systemctl start [unit type] <==> service [服务] start
          systemctl stop [unit type] <==> service [服务] stop
          systemctl restart [unit type] <==> service [服务] restart
        2. systemctl 还有两个自己的命令参数
          systemctl reload [unit type]:重新加载服务,加载更新后的配置文件(并不是所有服务都支持这个参数,比如network.service)
          systemctl status [unit type]:参数来查看服务运行情况
        3. 原来的chkconfig 命令与 systemctl 命令对比
          chkconfig [服务] on <==> systemctl enable [unit type] 设置服务开机启动
          chkconfig [服务] off <==> systemctl disable [unit type] 设备服务禁止开机启动

    相关文章

      网友评论

          本文标题:CentOS搭建PHP/Nginx环境

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