zoukankan      html  css  js  c++  java
  • LINUX 编译安装 PHP 环境

    今天终于有时间 总结一下 linux 的编译安装 php 环境
    同学给我发了他写的文档 ,基本就可以实现编译安装了
    我同学文章地址: http://penghui.link/articles/2016/07/php7_lnmp.html
    我就根据他的文章来进行下面的操作:

    1.安装必要的依赖库

     
    yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel enchant-devel pam-devel libc-client libc-client-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
    

    这是所有编译安装文档中必要的一步 , 但是需要根据个人情况添加依赖库;

    安装libmcrypt库

    wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
    tar zxf libmcrypt-2.5.7.tar.gz
    cd libmcrypt-2.5.7
    ./configure
    make && make install
    

    安装php7

    groupadd www
    useradd -g www www 创建www用户到www用户组
    

    下载php7

     wget https://downloads.php.net/~krakjoe/php-7.1.0RC5.tar.gz
     tar -zxvf php-7.1.0beta1.tar.gz
    

    下面的就是检验配置环境 并设置和加载php拓展 后面密密麻麻的都是配置和要加载的拓展

    ./configure  --prefix=/usr/local/php7/  --with-config-file-path=/usr/local/php7/etc  --with-config-file-scan-dir=/usr/local/php7/etc/conf.d  --enable-fpm  --with-fpm-user=web  --with-fpm-group=www  --enable-soap  --with-openssl  --with-openssl-dir  --with-mcrypt  --with-pcre-regex  --with-zlib  --with-iconv  --with-bz2  --enable-calendar  --with-curl  --with-cdb  --enable-dom  --enable-exif  --with-pcre-dir  --enable-ftp  --with-gd  --with-jpeg-dir  --with-png-dir  --with-freetype-dir  --with-gettext  --with-gmp  --with-mhash  --enable-mbstring  --with-libmbfl  --with-onig  --enable-pdo  --with-pdo-mysql  --with-zlib-dir  --with-readline  --enable-session  --enable-shmop  --enable-simplexml  --enable-sockets  --enable-sysvmsg  --enable-sysvsem  --enable-sysvshm  --enable-wddx  --with-libxml-dir  --with-xsl  --enable-zip  --enable-mysqlnd  --with-mysqli  --without-pear
    
    make && make install
    

    我现在是边安装 边别博客 这个安装过程 我也是醉了 太慢了 加载的东西有点多呀
    中间介绍一下我的安装环境 centos6.7 版本 没敢用7.0 版本 因为很多命令都改了 很操蛋 还是用6.7靠谱
    在windows7 虚拟机安装软件,没有多余软件,可以说是从零开始安装

    诶现在已经凌晨1点了 已经安装了5分钟 真是没意思 还好比较欣慰的是目前没有报错, linux 有个原则就是不报错就是对的.
    一会安装好了 我执行下php -m 看看拓展安装了多少

    Generating phar.php
    Generating phar.phar
    PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
    pharcommand.inc
    directorygraphiterator.inc
    invertedregexiterator.inc
    clicommand.inc
    directorytreeiterator.inc
    phar.inc
    
    Build complete.
    Don't forget to run 'make test'.
    
    Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/
    Installing PHP CLI binary:        /usr/local/php7/bin/
    Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
    Installing PHP FPM binary:        /usr/local/php7/sbin/
    Installing PHP FPM config:        /usr/local/php7/etc/
    Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
    Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
    Installing phpdbg binary:         /usr/local/php7/bin/
    Installing phpdbg man page:       /usr/local/php7/php/man/man1/
    Installing PHP CGI binary:        /usr/local/php7/bin/
    Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
    Installing build environment:     /usr/local/php7/lib/php/build/
    Installing header files:           /usr/local/php7/include/php/
    Installing helper programs:       /usr/local/php7/bin/
      program: phpize
      program: php-config
    Installing man pages:             /usr/local/php7/php/man/man1/
      page: phpize.1
      page: php-config.1
    /root/php-7.1.0beta1/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
    ln -s -f phar.phar /usr/local/php7/bin/phar
    Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/
    

    上面就是安装成功后 php配置后的一些插件拓展工具等的路径

    [root@bf php-7.1.0beta1]# which php
    /usr/bin/which: no php in (/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
    

    看下 光是编译安装完了也是没有用的 不能直接在全局环境变量中用

    php的配置文件不能少呀 php7编译包里有现成的可以用 直接copy到php7 软件安装目录

    cp php.ini-production /usr/local/php7/etc/php.ini
    

    下面的配置方面我没看懂为什么但是还是照着办了

    重新命名fpm.conf
    cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
    
    fpm扩展配置文件
    cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
    
    vim配置php-fpm.conf  include选项
    把include路径设置为加载  www.conf的目录  一般不用改动
    
    如果你听不懂我说的什么  那下面的就不用看了 谢谢
    
    vim  www.conf  配置下用户名和用户组
    
    

    启动php-fpm 测试下
    执行php-fpm命令 cd php目录下的sbin目录直接执行即可
    ps aux | grep php 即可看到fpm进程

    [root@bf sbin]# ./php-fpm 
    [root@bf sbin]# ps aux |grep php
    root     28143  0.0  0.3  32148  3232 ?        Ss   12:12   0:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
    www      28144  0.0  0.2  32148  2660 ?        S    12:12   0:00 php-fpm: pool www
    www      28145  0.0  0.2  32148  2660 ?        S    12:12   0:00 php-fpm: pool www
    # 结束进程 即可
    [root@bf sbin]# pkill php-fpm
    [root@bf sbin]# ps aux |grep php
    root     28159  0.0  0.0   6056   788 pts/0    S+   12:16   0:00 grep php
    
    

    将php编译生成的bin目录添加到当前Linux系统的环境变量中

    echo -e '
    export PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH
    ' >> /etc/profile && source /etc/profile
    

    上面这个方法就是将 export PATH=/usr/local/php7/bin:/usr/local/php7/sbin 下所有工具都在环境变量中加载 写入到/etc/profile 中

    编译nginx

    groupadd nginx
    useradd -g nginx nginx 创建nginx用户到nginx用户组
    
    yum -y install pcre*
    yum -y install openssl*
    wget http://nginx.org/download/nginx-1.7.8.tar.gz
    tar -zxvf nginx-1.7.8.tar.gz
    cd nginx-1.7.8
    ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
    make
    make install
    

    诶上面就是安装命令了
    回头有时间 全写道shell里 下次一个脚本就省事了

    添加这样一条开放80端口的规则后保存

    vim /etc/sysconfig/iptables
    -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
    
    /usr/local/nginx/sbin/nginx 执行nginx命令
    vim /usr/local/nginx/conf/nginx.conf 配置nginx
    添加用户  user  nginx; 打开
    添加include 虚拟主机配置目录 /usr/local/nginx/vhost/default.com.conf
    创建mkdir vhost vim default.com.conf 配置
    server
      {
       listen       80;
       server_name  localhost;
       index index.php index.html index.htm;
       root  /usr/local/nginx/html;
    
     location / {
    
            if (!-e $request_filename){
              rewrite ^(.*)$ /index.php?s=/$1 last;
              rewrite ^(.*)$ /index.php/$1 last;
             }
            }
        location ~ .*.(php|php5)
        {
               fastcgi_pass  127.0.0.1:9000;
               fastcgi_index index.php;
               include fastcgi.conf;
            }
    
        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
        {
          expires      30d;
        }
        location ~ .*.(js|css)?$
        {
          expires      1h;
        }
    autoindex on;
    access_log  /usr/local/nginx/logs/default.logs;
    }
    重启nginx即可
    进入/usr/local/nginx/html 创建index.php进行测试即可
    
    这样nginx就把任务交给fpm进程来处理了。
    访问即可看到你熟悉的画面
    ps aux | grep nginx
    以nginx用户身份运行
    
    

    安装redis

    wget http://download.redis.io/redis-stable.tar.gz
    tar xvzf redis-stable.tar.gz
    cd redis-stable
    make
    cd src 下 执行 
    mkdir /usr/local/redis
    cp redis-server /usr/local/redis/
    cp redis-benchmark /usr/local/redis/
    cp redis-cli /usr/local/redis/
    cp redis.conf /usr/local/redis/
    
    配置redis.conf   把daemonize设置为yes(这样redis就可以以守护进程的方式运行了)
    
    启动redis
    ./redis-server  redis.conf
    ps aux | grep redis   查看  进程是否正常启动

    安装memcached

    下载memcached
    http://memcached.org/files/memcached-1.4.31.tar.gz
    解压
    cd memcache
    执行
    ./configure --prefix=/usr/local/memcache --with-libevent=/usr/local/libevent/lib/libevent-1.2.so.1
    如果没有libevent库 先安装libevent
    这个东东是个好东西 可以提高系统的运行性能的  是一个网络库 
    如果不安装有的软件会直接用系统的select模型的 比如workerman  workerman也会用它进行高性能的
    
    如果没安装  启动memcache的时候会报错  根据报错完成安装即可
    make && make install 
    
    cd  /usr/local/memcache/bin
    
    启动
    ./memcached -d -m 900 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid
    
    netstat -an | grep 11211 ok
    
    telnet 127.0.0.1 11211
    ok
    

    中间安装memcache 有问题

      wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
      tar xvzf libevent-2.0.22-stable.tar.gz 
      cd libevent-2.0.22-stable
      ls
      ./configure 
      make && make install
    
  • 相关阅读:
    列表左边左右固定,右边可以左右滚动,且左右两边列表滚动时上下联动
    SQL分组多列统计(GROUP BY后按条件分列统计)
    C# 调用webservice 几种办法(转载)
    解析XML文档
    GDI+中发生一般性错误的解决办法
    所闻所获2:使用块回调来实现代理的功能
    OC基础11:基本的C语言特性2
    OC基础10:基本的C语言特性1
    OC基础9:预处理程序
    OC基础8:分类和协议
  • 原文地址:https://www.cnblogs.com/xiaommvik/p/6054988.html
Copyright © 2011-2022 走看看