Linux (測試環境 Ubuntu 12.04 Server X86_64)
1. 安裝編譯工具及所需類庫
$ sudo apt-get install build-essential gcc g++ autoconf libjpeg62 libjpeg62-dev libpng12-0 libpng12-dev libfreetype6 libfreetype6-dev libxml2 libxml2-dev zlib1g zlib1g-dev bzip2 libbz2-dev openssl libssl-dev curl libcurl4-openssl-dev libpcre3 libpcre3-dev libevent-1.4-2 libevent-dev libmcrypt4 libmcrypt-dev mcrypt libltdl-dev libldap2-dev libsasl2-dev libmhash-dev libc-client2007e libc-client2007e-dev
2. 安裝MySQL
$ sudo apt-get install mysql-server libmysqlclient-dev
3. 安裝PHP
Linux下多版本PHP共存需要自己手工編譯安裝。
下載PHP源文件到/opt/src目錄
$ mkdir /opt/src
$ cd /opt/src
$ wget http://museum.php.net/php5/php-5.2.17.tar.bz2 -O php-5.2.17.tar.bz2
$ wget http://cn2.php.net/get/php-5.3.28.tar.bz2/from/this/mirror -O php-5.3.28.tar.bz2
$ wget http://cn2.php.net/get/php-5.4.29.tar.bz2/from/this/mirror -O php-5.4.29.tar.bz2
$ wget http://cn2.php.net/get/php-5.5.14.tar.bz2/from/this/mirror -O php-5.5.14.tar.bz2
創建PHP各版本安裝目錄
$ mkdir -p /opt/php/{5217,5328,5429,5514}
安裝PHP 5.2.17
$ cd /opt/src
$ tar -xvjf php-5.2.17.tar.bz2
$ cd php-5.2.17
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/libpng.so
$ sudo ln -s /usr/lib/x86_64-linux-gnu/libkrb5.so /usr/lib/libkrb5.so
$ wget -O debian_patches_disable_SSLv2_for_openssl_1_0_0.patch 「https://bugs.php.net/patch-display.php?bug_id=54736&patch=debian_patches...」
$ patch -p1 < debian_patches_disable_SSLv2_for_openssl_1_0_0.patch
$ ./configure --prefix=/opt/php/5217 --with-config-file-scan-dir=/opt/php/5217/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-mime-magic --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-recommended /opt/php/5217/lib/php.ini
安裝PHP 5.3.28
$ cd /opt/src
$ tar -xvjf php-5.3.28.tar.bz2
$ cd php-5.3.28
$ ./configure --prefix=/opt/php/5328 --with-config-file-scan-dir=/opt/php/5328/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-development /opt/php/5328/lib/php.ini
安裝PHP 5.4.29
$ cd /opt/src
$ tar -xvjf php-5.4.29.tar.bz2
$ cd php-5.4.29
$ ./configure --prefix=/opt/php/5429 --with-config-file-scan-dir=/opt/php/5429/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-development /opt/php/5429/lib/php.ini
安裝PHP 5.5.14
$ cd /opt/src
$ tar -xvjf php-5.5.14.tar.bz2
$ cd php-5.5.14
$ ./configure --prefix=/opt/php/5514 --with-config-file-scan-dir=/opt/php/5514/etc/php.d --with-mysql --with-pdo-mysql --with-mysqli --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-ftp --disable-debug --disable-ipv6 --disable-short-tags --enable-calendar --with-imap --with-imap-ssl --with-kerberos
$ make
$ sudo make install
$ cp php.ini-development /opt/php/5514/lib/php.ini
4. 安裝Apache
$ sudo apt-get install apache2
啟用相應模塊
$ a2enmod headers
$ a2enmod expires
$ a2enmod actions
$ a2enmod rewrite
5. 配置Apache
$ sudo vi /etc/apache2/httpd.conf
追加如下腳本映射和虛擬主機配置,原理同Windows的配置說明。
ServerName localhost
AddType application/x-httpd-php .php
ScriptAlias /php-5217/ "/opt/php/5217/bin/"
ScriptAlias /php-5328/ "/opt/php/5328/bin/"
ScriptAlias /php-5429/ "/opt/php/5429/bin/"
ScriptAlias /php-5514/ "/opt/php/5514/bin/"
<Directory /var/www/sites>
Options Indexes FollowSymLinks Includes ExecCGI
DirectoryIndex index.php index.html
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/sites/5217>
Action application/x-httpd-php "/php-5217/php-cgi"
</Directory>
<Directory /var/www/sites/5328>
Action application/x-httpd-php "/php-5328/php-cgi"
</Directory>
<Directory /var/www/sites/5429>
Action application/x-httpd-php "/php-5429/php-cgi"
</Directory>
<Directory /var/www/sites/5514>
Action application/x-httpd-php "/php-5514/php-cgi"
</Directory>
# Virtualhosts
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5217/test.local"
ServerName php5217.local
ErrorLog "/var/log/apache2/php5217.local-error.log"
CustomLog "/var/log/apache2/php5217.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5328/test.local"
ServerName php5328.local
ErrorLog "/var/log/apache2/php5328.local-error.log"
CustomLog "/var/log/apache2/php5328.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5429/test.local"
ServerName php5429.local
ErrorLog "/var/log/apache2/php5429.local-error.log"
CustomLog "/var/log/apache2/php5429.local-access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/sites/5514/test.local"
ServerName php5514.local
ErrorLog "/var/log/apache2/php5514.local-error.log"
CustomLog "/var/log/apache2/php5514.local-access.log" common
</VirtualHost>
保存配置後,創建各站點的DocumentRoot目錄,再往每個目錄放置一個phpinfo的測試文件,完成後重啟Apache伺服器並在本地hosts文件加入域名解析,現在就可以訪問各站點來測試多版本PHP共存了。
好了,基本的多版本PHP共存解決方案已經完成,如果還需要添加其他的PHP類庫支持,後續自己再調用對應php目錄下的pecl, php_config等腳本編譯安裝就可以了。
Ⅱ 怎麼在linux運行php文件
在命令行運行的話來,linux和Windows環境下自一樣,如果你的PHP已經設置為全局的,可以直接
php 後跟文件名,如果不是全局的就進入php安裝bin目錄下,就是有php.exe文件那個目錄下執行 php+文件名
Ⅲ php7 linux上使用 call_user_func_array 報錯
php __call()與call_user_func_array()理解 1. mixed __call ( string name, array arguments )The magic method __call() allows to capture invocation of non existing methods. That way __call() can be used to implement user defined method handling that depends on the name of the actual method being called. This is for instance useful for proxy implementations. The arguments that were passed in the function will be defined as an array in the $arguments parameter. The value returned from the __call() method will be returned to the caller of the method. 譯文: 這個魔術方法允許用戶調用類中不存在的方法,它用於實現那些 依賴於在被調用時的真正方法名的方法. 典型的例子是用來實現代理. 方法的參數$arguments是一個數組 ,__call()的返回值返回給方法調用者白話文: 這個方法主要是用來實現動態方法調用, 如果再一個類定義了__call()這個方法, 當用戶調用這個類的一個不存在的方法時,他可以使用調用的那個不存在的方法的方法名和參數做出用戶定義在__call()方法體內的相應操作,此時__call()方法的參數就是被調用的那個不存在的方法的方法名和參數例子<?phpclass Person{function talk( $sound ){echo $sound;}function __call( $method , $args ){echo 'you call method ' . $method . '
';echo 'and the arguments are
';var_mp( $args );}}$person = new Person();$person->test( 1 , TRUE );?>程序輸出引用you call method testand the arguments are array 0 => int 1 1 => boolean true2. mixed call_user_func_array ( callback function, array param_arr )Call a user defined function with the parameters in param_arr. 參數functionThe function to be called. param_arrThe parameters to be passed to the function, as an indexed array. 返回值Returns the function result, or FALSE on error. 此方法可以通過傳入類名,類中得方法名和方法參數達到動態調用方法的效果例子<?php class Person{function talk( $sound ){echo $sound;}function __call( $method , $args ){echo 'you call method ' . $method . '
';echo 'and the arguments are
';var_mp( $args );}} $person = new Person();call_user_func_array( array( $person , 'talk' ) , array( 'hello' ) );?>程序輸出引用hello兩個方法共用,實現代理模型 class Person{function talk( $sound ){echo $sound;}function __call( $method , $args ){echo 'you call method ' . $method . '
';echo 'and the arguments are
';var_mp( $args );}}class PersonProxy{private $person;function __construct(){$this->person = new Person();}function __call( $method , $args ){call_user_func_array( array( $this->person , $method ) , $args );}}$person_proxy = new PersonProxy(); $person_proxy->talk( 'thank you' );程序輸出引用thank yo
Ⅳ PHP7安裝intl擴展和linux安裝icu
一 PHP intl 是國際化擴展,是ICU 庫的一個包裝器。所以在安裝PHP intl擴展前要先安裝ICU庫,安裝ICU庫的具體步驟::
二 安裝intl擴展
1:進入php7.2.5源碼:
2:運行:phpize ,找不到命令時,將路徑補全:/usr/local/php7/bin/phpize(是php的安裝路徑),出現如下:
Configuring for:
PHP Api Version: 20100412
Zend Mole Api No: 20100525
Zend Extension Api No: 220100525
3:運行配置
./configure --enable-intl --with-icu-dir=/usr/local/icu/ --with-php-config=/usr/local/php7/bin/php-config
注陵手:前面路徑為icu的安裝路徑,後面路徑為php的安裝路徑。
4:編譯擴展:make
5:復制擴展到目標文件夾
cp /user/local/php/php7.2.5/ext/intl/moles/intl.so /user/local/php7/lib/php/extensions/no-debug-non-zts-20170718
注意中汪坦:也可賣桐以find / -name intl.so 查找。
6:設置擴展加入配置文件中:
[intl]
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20170718/"
extension=intl.so
大坑:::採用phpinfo()時,無法找到配置的intl擴展,說明配置沒有生效。。。。。。
原因:在編譯php時沒有 --with-config-file-path=PATH 指定php.ini路徑,默認的路徑為/usr/local/php7/lib,只需要將php.ini放入這個默認的路徑即可。你也可以安裝配置php時加入,如下:
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath -enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-pcntl --with-curl --with-fpm-user=nginx --enable-ftp --enable-session --enable-xml --with-apxs2=/usr/bin/apxs
訪問:index.php中phpinfo()文件。
Ⅳ 如何讓PHP有許可權執行Linux下的命令
最近幫一個朋友搞個東西,但是用的是比較笨的方法,代碼如下--------主要是讓PHP獲取專更大的許可權屬去執行LINUX命令,有許可權去重啟nginx服務或者重啟Apache服務。
<?php
// 作用取得客戶端的ip、地理信息、瀏覽器、本地真實IP
//此文檔編碼類型:utf-8
//程序使用:
//include("XXX.php") //引入類
// $gifo = new get_gust_info();//實例化
// $gifo->GetBrowser(); //獲得訪客瀏覽器類型
// $gifo->GetLang(); //獲得訪客瀏覽器語言
// $gifo->GetOs(); //獲取訪客操作系統
// $gifo->Getip(); //獲得訪客真實ip
// $gifo->get_onlineip(); //獲得本地真實IP
// $gifo->Getaddress($ip); //參數 $ip 是可選的,默認返回一個二維數組包含當前訪客所在地的相關信息
//
Ⅵ Linux的PHP服務要怎麼啟動
linux如何啟動php服務?我們一起來了解一下吧。
1、打開linux系統,在linux的桌面的空白處右擊。
2、在彈出的下拉選項里,點擊打開終端。
3、輸入/etc/init.d/php-fpmstart命令,回車即可開啟PHP服務。
以上就是小編的分享,希望能幫助到大家。
Ⅶ PHP怎麼調用Linux命令終端
首先先要給大家介紹PHP執行linux系統命令的幾個基本函數。
system函數
說明:執行外部程序並顯示輸出資料。
語法:string system(string command, int [return_var]);
返回值: 字元串
詳細介紹:
本函數就像是 C 語中的函數 system(),用來執行指令,並輸出結果。若是 return_var 參數存在,則執行 command 之後的狀態會填入 return_var 中。同樣值得注意的是若需要處理用戶輸入的資料,而又要防止用戶耍花招破解系統,則可以使用 EscapeShellCmd()。若 PHP 以模塊式的執行,本函數會在每一行輸出後自動更新 Web 伺服器的輸出緩沖暫存區。若需要完整的返回字元串,且不想經過不必要的其它中間的輸出界面,可以使用 PassThru()。
實例代碼:
< ?php
$last_line = system('ls', $retval);
echo 'Last line of the output: ' . $last_line;
echo '<hr/>Return value: ' . $retval;
?>
exec函數
說明:執行外部程序。
語法:string exec(string command, string [array], int [return_var]);
返回值: 字元串
詳細介紹:
本函數執行輸入 command 的外部程序或外部指令。它的返回字元串只是外部程序執行後返回的最後一行;若需要完整的返回字元串,可以使用 PassThru() 這個函數。
要是參數 array 存在,command 會將 array 加到參數中執行,若不欲 array 被處理,可以在執行 exec() 之前呼叫 unset()。若是 return_var 跟 array 二個參數都存在,則執行 command 之後的狀態會填入 return_var 中。
值得注意的是若需要處理使用者輸入的資料,而又要防止使用者耍花招破解系統,則可以使用 EscapeShellCmd()。
實例代碼:
< ?php
echo exec('whoami');
?>
popen函數
說明:打開文件。
語法:int popen(string command, string mode);
返回值: 整數
詳細介紹:
本函數執行指令開檔,而該文件是用管道方式處理的文件。用本函數打開的文件只能是單向的 (只能讀或只能寫),而且一定要用 pclose() 關閉。在文件操作上可使用 fgets()、fgetss() 與 fputs()。若是開檔發生錯誤,返回 false 值。
實例代碼:
< ?
$fp = popen( "/bin/ls", "r" );
?>
通過上述函數,PHP可以執行linux系統的shell命令。