1. 程式人生 > >php原始碼編譯安裝

php原始碼編譯安裝

PHP安裝

要用swoole,首先需要有PHP環境。由於swoole的某些特性,最好是能夠從原始碼編譯安裝PHP,這樣在使用過程中可以避免很多不必要的錯誤。PHP下載地址:http://php.net/在這裡挑選你想用的版本即可。下載原始碼包後,解壓至本地任意目錄(保證讀寫許可權),留待使用。安裝PHP前,需要安裝編譯環境和PHP的相關依賴。下面是相關命令:Ubuntu環境下:

sudo apt-get install build-essential gcc g++ autoconf libiconv-hook-dev libmcrypt-dev libxml2-dev libmysqlclient-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev

CentOS環境下:

yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel

(注:以上命令是我在實際使用中驗證過的可以使用的,可能會和其他教程提供的命令不同)當上述命令執行後,即可開始安裝PHP。命令如下:

cd php-5.5.10/
./configure --prefix=/usr/local/php --with-config-file-path=/etc/php --enable-fpm --enable-pcntl --enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg --enable-sysvsem  --enable-sysvshm --enable-shmop --enable-zip --enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath --disable-debug --disable-fileinfo --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pcre-regex --with-iconv --with-zlib --with-mcrypt --with-gd --with-openssl --with-mhash --with-xmlrpc --with-curl --with-imap-ssl
sudo make
sudo make install
sudo cp php.ini-development /etc/php/

至此,PHP已經成功安裝,但是此時在終端裡是無法直接通過php --version檢視php版本的還需要將PHP的可執行目錄新增到環境變數中。使用Vim/Sublime開啟~/.bashrc,在末尾新增如下內容:

export PATH=/usr/local/php/bin:$PATH
export PATH=/usr/local/php/sbin:$PATH

儲存後,終端輸入命令:

source ~/.bashrc

此時即可通過php --version檢視php版本,看到如下內容:

PHP 5.5.10 (cli) (built: Apr 26 2014 09:46:14) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

即說明安裝成功。

memcached擴充套件:

1、wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz

2、tar -zxvf libmemcached-1.0.18.tar.gz 

    ./configure     make && make install

3、 wget http://pecl.php.net/get/memcached-2.2.0.tgz

tar -zxvf  memcached-2.2.0.tgz

phpize

        ./configure     make && make install

vi /etc/php/php.ini

extension = memcached.so

redis擴充套件:

1、https://github.com/phpredis/phpredis.git

cd phpredis/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

vi /etc/php/php.ini

extension=redis.so

mongo擴充套件:

1、wget http://pecl.php.net/get/mongo-1.5.8.tgz

tar -zxvf mongo-1.5.8.tgz 

/usr/local/php/bin/phpize

       ./configure --with-php-config=/usr/local/php/bin/php-config

      make

      make install

vi /etc/php/php.ini

         extension=mongo.so