LINUX 編譯安裝 PHP 環境

今天終於有時間 總結一下 linux 的編譯安裝 php 環境
同窗給我發了他寫的文檔 ,基本就能夠實現編譯安裝了
我同窗文章地址: http://penghui.link/articles/2016/07/php7_lnmp.html
我就根據他的文章來進行下面的操做:php

1.安裝必要的依賴庫css

 
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

這是全部編譯安裝文檔中必要的一步 , 可是須要根據我的狀況添加依賴庫;html

安裝libmcrypt庫mysql

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
linux

groupadd www
useradd -g www www 建立www用戶到www用戶組

下載php7nginx

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

下面的就是檢驗配置環境 並設置和加載php拓展 後面密密麻麻的都是配置和要加載的拓展c++

./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 虛擬機安裝軟件,沒有多餘軟件,能夠說是從零開始安裝git

誒如今已經凌晨1點了 已經安裝了5分鐘 真是沒意思 還比如較欣慰的是目前沒有報錯, linux 有個原則就是不報錯就是對的.
一會安裝好了 我執行下php -m 看看拓展安裝了多少github

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配置後的一些插件拓展工具等的路徑web

[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 '\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n' >> /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
相關文章
相關標籤/搜索