• PHP安装配置


    centos6.5下使用yum完美搭建LNMP环境(php5.6)

    1. 配置防火墙,开启80端口、3306端口
      删除原有的 iptables , 添加合适的配置

      rm -rf /etc/sysconfig/iptables
      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保存退出, 重启防火墙使配置生效

      /etc/init.d/iptables restart
    2. 关闭SELINUX

      rm -rf  /etc/selinux/config
      vi /etc/selinux/config

      添加一行内容:

      SELINUX=disabled

      :wq保存退出

      #重启系统
      shutdown -r now
    3. 安装第三方yum源
      #安装下载工具
      yum install wget
      #下载
      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
    二. 安装PHP
    1. 检查当前安装的PHP包
      yum list installed | grep php
      如果有安装的PHP包,先删除他们, 如:
      yum remove php.x86_64 php-cli.x86_64 php-common.x86_64
    2. 配置安装包源:
      # Centos 5.X
      rpm -Uvh http://mirror.webtatic.com/yum/el5/latest.rpm
      # CentOs 6.x
      rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
      # CentOs 7.X
      rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
      rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
      如果想删除上面安装的包,重新安装
      rpm -qa | grep webstatic
      rpm -e  [上面搜索到的包即可]
    3. 执行安装
      yum -y install php56w.x86_64
      yum -y --enablerepo=webtatic install php56w-devel
      yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64
    4. 安装PHP FPM
      yum -y install php56w-fpm
      #设置php-fpm开机启动
      chkconfig php-fpm on
      #启动php-fpm
      /etc/init.d/php-fpm start
      注:如果想更换到php5.5或5.4版本, 直接把上面的56w换成55w或者54w就可以了
    三. 安装 MySQL
    1. 安装
      yum install -y mysql mysql-server
      #启动MySQL
      /etc/init.d/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:
      #重启
      /etc/init.d/mysqld restart
      #停止
      /etc/init.d/mysqld stop
      #启动
      /etc/init.d/mysqld start

    配置

    1. 配置nginx
    rm -rf /etc/nginx/conf.d/*
    vi /etc/nginx/conf.d/default.conf

    添加如下内容 :

    server{
        listen      80;
        server_name _;
        index index.php index.html index.htm;
        root  /var/www;
    
        location ~ .*.(php|php5)?$
        {
                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                fastcgi_pass  127.0.0.1:9000;
                fastcgi_index index.php;
                include fastcgi.conf;
        }
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    }

    说明: /var/www 为web根目录, location / ... 为url的rewrite,隐藏 index.php

    2. 配置php-fpm
    vi /etc/php-fpm.d/www.conf

    将用户和用户组设置为nginx, 如:

    #修改用户为nginx
    user = nginx
     #修改组为nginx
    group = nginx

    开始测试

    cd /var/www
    vi index.php

    添加以下代码

    <?php
    phpinfo();
    ?>

    :wq! 保存退出

    #设置权限
    chown nginx.nginx /var/www -R
    #重启nginx
    service nginx restart
    #重启php-fpm
    service php-fpm restart

    在客户端浏览器输入服务器IP地址(如: 127.0.0.1),可以看到相关的配置信息!
    说明lnmp配置成功!

     

    centos6.8编译安装nginx+PHP7.0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    系统环境:最小化安装centos6.8

    # 安装编译工具:(当前位置/root)
    yum install gcc automake autoconf libtool gcc-c++
    # 安装基础库
    yum install gd zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt libmcrypt-devel  pcre-devel

    安装Nginx

    wget http://nginx.org/download/nginx-1.12.1.tar.gz

    groupadd nginx

    useradd -r -g nginx -s /sbin/nologin nginx

    tar zxf nginx-1.12.1.tar.gz

    cd nginx-1.12.1

    ./configure --prefix=/application/nginx-1.12.1 --user=nginx --group=nginx

    make

    make install

    ln -s /application/nginx-1.12.1 /application/nginx

    # 编译PHP

    1. wget http://cn2.php.net/get/php-7.0.0.tar.bz2/from/this/mirror

    2. mv mirror php-7.0.0.tar.bz2

    3. tar jxf php-7.0.0.tar.bz2

             cd php-7.0.0

    1. ./configure --prefix=/usr/local/php

    2. --with-gd

    3. --with-freetype-dir

    4. --enable-gd-native-ttf

    5. --enable-mysqlnd

    6. --with-pdo-mysql=mysqlnd

    7. --with-openssl

    8. --with-mcrypt

    9. --enable-mbstring

    10. --enable-zip

    11. --enable-fpm

      报错: 缺少libiconv库的报错

      wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz

      tar zxf libiconv-1.14.tar.gz

      cd libiconv-1.14

      ./configure --prefix=/usr/local/libiconv

      make

      make install

      #安装默认yum源无法安装的libmcrypt库(libmcrypt对于在程序运行时添加移除算法是有用的)

      wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

      yum install libmcrypt-devel

      #安装mhash加密扩展库

      yum install mhash

      #安装 mcrypt加密扩展库

      yum install mcrypt

       

      执行上面php   ./configure在执行一次

      make && make install

       

      # 复制配置文件

      cp /root/php-7.0.0/php.ini-development  /usr/local/php/lib/php.ini     

      cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf

      cp /usr/local/php/etc/php-fpm.d/www.conf.default   /usr/local/php/etc/php-fpm.d/www.conf

      整合Nginx + php

      location ~ .php$ {

      root           html;

      fastcgi_pass   127.0.0.1:9000;

      fastcgi_index  index.php;

      fastcgi_param  SCRIPT_FILENAME  $DOCUMENT_ROOT$fastcgi_script_name;

      include        fastcgi_params;

      }

      image

       

      启动php和Nginx

      /application/php/sbin/php-fpm

      /application/nginx/sbin/nginx

      写PHP测试页面
      vim /application/nginx/html/test.php
      <?php

      # /application/nginx/html/a.php

      phpinfo();

       

      访问192.168.0.110/test.php,结果:

       

      image

       

  • 相关阅读:
    nignx简单操作
    nginx的原理
    nginx简单了解
    操作数栈
    静态变量与局部变量
    遇到C语言内存错误怎么办?一定要找准这六个原因
    千万不要以为程序员是靠技术生存!六句话改变你对程序员的认知
    关于C语言Switch语句,先学这些技巧够不够?
    作为一个码农的悲哀:我是架构师,而你不是
    引用不如指针强大?C++引用,为你深度解析
  • 原文地址:https://www.cnblogs.com/pengrj/p/9328568.html
Copyright © 2020-2023  润新知