Linux下安裝PHP的lua擴充庫

來源:互聯網
上載者:User

標籤:compile   figure   php7   安裝   copy   distrib   pre   phpize   out   

 

一、安裝Lua 5.3.4

下載

http://www.lua.org/ftp/lua-5.3.4.tar.gztar xvf lua-5.3.4.tar.gzcd lua-5.3.4

重要:進入解壓縮後的路徑 cd .../lua-5.3.4/src 開啟Makefile檔案 在CFLAG一行 添加選項 -fPIC 像這樣:

找到源檔案的這行替換掉

CFLAGS= -O2 -Wall -DLUA_COMPAT_ALL $(SYSCFLAGS) -fPIC $(MYCFLAGS)

然後編譯、安裝

 make linux  sudo make install

執行完成後安裝lua成功,可以查看lua 版本是否為剛安裝的版本

[email protected]:~/lua-5.3.4$ lua -vLua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio

查看 /usr/local/include/ 路徑下是否有 lua.h, 為該標頭檔建立一個軟鏈

[email protected]:/usr/local/include$ ls lauxlib.h  libssh2.h  libssh2_publickey.h  libssh2_sftp.h  luaconf.h  lua.h  lua.hpp  lualib.h[email protected]:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.hln: 無法建立符號連結‘/usr/include/lua/lua.h‘: 沒有那個檔案或目錄[email protected]:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.hln: 無法建立符號連結‘/usr/include/lua/lua.h‘: 沒有那個檔案或目錄[email protected]:/usr/local/include$ mkdir -P /usr/include/luamkdir:無效選項 -- PTry ‘mkdir --help‘ for more information.[email protected]:/usr/local/include$ mkdir -R /usr/include/luamkdir:無效選項 -- RTry ‘mkdir --help‘ for more information.[email protected]:/usr/local/include$ mkdir - /usr/include/luamkdir: 無法建立目錄"-": 許可權不夠mkdir: 無法建立目錄"/usr/include/lua": 許可權不夠[email protected]:/usr/local/include$ sudo mkdir - /usr/include/lua[email protected]:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.hln: 無法建立符號連結‘/usr/include/lua/lua.h‘: 許可權不夠[email protected]:/usr/local/include$ sudo ln -s /usr/local/include/lua.h /usr/include/lua/lua.h[email protected]:/usr/local/include$ 

將 liblua.a 放到 /usr/lib 目錄下,先尋找liblua.a檔案在哪個位置,一般是在/usr/local/lib/liblua.a

[email protected]:/usr/local/include$ whereis liblua.aliblua: /usr/local/lib/liblua.a[email protected]:/usr/local/include$ cp /usr/local/lib/liblua.a /usr/lib/liblua.acp: 無法建立普通檔案‘/usr/lib/liblua.a‘: 許可權不夠[email protected]:/usr/local/include$ sudo cp /usr/local/lib/liblua.a /usr/lib/liblua.a[email protected]:/usr/local/include$

如果不安裝lua,在./configured的時候提示一下錯誤資訊

configure: error: Please reinstall the lua distribution - lua.h should be in <lua-dir>/include/

二、安裝phplua 擴充

wget http://pecl.php.net/get/lua-2.0.3.tgz

tar xvf lua-2.0.3.tgzcd lua
-2.0.3phpize./configure

編譯、安裝

[email protected]:~/lua-2.0.3$ make/bin/bash /home/tinywan/lua-2.0.3/libtool --mode=compile cc ...[email protected]:~/lua-2.0.3$ sudo make install/bin/bash /home/tinywan/lua-2.0.3/libtool --mode=install cp ./lua.la /home/tinywan/lua-2.0.3/moduleslibtool: install: cp ./.libs/lua.so /home/tinywan/lua-2.0.3/modules/lua.solibtool: install: cp ./.libs/lua.lai /home/tinywan/lua-2.0.3/modules/lua.lalibtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin" ldconfig -n /home/tinywan/lua-2.0.3/modules----------------------------------------------------------------------Libraries have been installed in:   /home/tinywan/lua-2.0.3/modulesIf you ever happen to want to link against installed librariesin a given directory, LIBDIR, you must either use libtool, andspecify the full pathname of the library, or use the ‘-LLIBDIR‘flag during linking and do at least one of the following:   - add LIBDIR to the ‘LD_LIBRARY_PATH‘ environment variable     during execution   - add LIBDIR to the ‘LD_RUN_PATH‘ environment variable     during linking   - use the ‘-Wl,-rpath -Wl,LIBDIR‘ linker flag   - have your system administrator add LIBDIR to ‘/etc/ld.so.conf‘See any operating system documentation about shared libraries formore information, such as the ld(1) and ld.so(8) manual pages.----------------------------------------------------------------------Installing shared extensions:     /usr/lib/php/20151012/

查看lua.so 檔案

[email protected]:/usr/lib/php/20151012$ lsbuild        ctype.so  exif.so      ftp.so      iconv.so  lua.so

修改PHP 設定檔

sudo vim /etc/php/7.0/cli/php.ini#添加一下內容extension=/usr/lib/php/20151012/lua.so[email protected]:/usr/lib/php/20151012$ php -m | grep lualua

安裝完畢

三、測試

檔案test_lua.php

<?php$lua = new Lua();$lua->eval(<<<CODE    function dummy(foo, bar)        print(foo, ",", bar)    endCODE);$lua->call("dummy", array("Lua", "geiliable\n"));$lua->dummy("Lua", "geiliable"); // __call()var_dump($lua->call(array("table", "concat"), array(array(1=>1, 2=>2, 3=>3), "-")));?>

執行結果:

[email protected]:~/PHP7$ php test_lua.php Lua,geiliableLua,geiliablestring(11) "1.0-2.0-3.0"

 

Linux下安裝PHP的lua擴充庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.