Linux下安裝PHP的lua擴充套件庫
一、安裝Lua 5.3.4
下載
http://www.lua.org/ftp/lua-5.3.4.tar.gz tar xvf lua-5.3.4.tar.gz cd 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 版本是否為剛安裝的版本
tinywan@tinywan:~/lua-5.3.4$ lua -v Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
檢視 /usr/local/include/ 路徑下是否有 lua.h, 為該標頭檔案建立一個軟鏈
tinywan@tinywan:/usr/local/include$ ls lauxlib.h libssh2.h libssh2_publickey.h libssh2_sftp.h luaconf.h lua.h lua.hpp lualib.h tinywan@tinywan:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.h ln: 無法建立符號連結`/usr/include/lua/lua.h`: 沒有那個檔案或目錄 tinywan@tinywan:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.h ln: 無法建立符號連結`/usr/include/lua/lua.h`: 沒有那個檔案或目錄 tinywan@tinywan:/usr/local/include$ mkdir -P /usr/include/lua mkdir:無效選項 -- P Try `mkdir --help` for more information. tinywan@tinywan:/usr/local/include$ mkdir -R /usr/include/lua mkdir:無效選項 -- R Try `mkdir --help` for more information. tinywan@tinywan:/usr/local/include$ mkdir - /usr/include/lua mkdir: 無法建立目錄"-": 許可權不夠 mkdir: 無法建立目錄"/usr/include/lua": 許可權不夠 tinywan@tinywan:/usr/local/include$ sudo mkdir - /usr/include/lua tinywan@tinywan:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.h ln: 無法建立符號連結`/usr/include/lua/lua.h`: 許可權不夠 tinywan@tinywan:/usr/local/include$ sudo ln -s /usr/local/include/lua.h /usr/include/lua/lua.h tinywan@tinywan:/usr/local/include$
將 liblua.a 放到 /usr/lib 目錄下,先查詢liblua.a檔案在哪個位置,一般是在/usr/local/lib/liblua.a
tinywan@tinywan:/usr/local/include$ whereis liblua.a liblua: /usr/local/lib/liblua.a tinywan@tinywan:/usr/local/include$ cp /usr/local/lib/liblua.a /usr/lib/liblua.a cp: 無法建立普通檔案`/usr/lib/liblua.a`: 許可權不夠 tinywan@tinywan:/usr/local/include$ sudo cp /usr/local/lib/liblua.a /usr/lib/liblua.a tinywan@tinywan:/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.tgz cd lua-2.0.3 phpize ./configure
編譯、安裝
tinywan@tinywan:~/lua-2.0.3$ make /bin/bash /home/tinywan/lua-2.0.3/libtool --mode=compile cc ... tinywan@tinywan:~/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/modules libtool: install: cp ./.libs/lua.so /home/tinywan/lua-2.0.3/modules/lua.so libtool: install: cp ./.libs/lua.lai /home/tinywan/lua-2.0.3/modules/lua.la libtool: 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/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify 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 for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Installing shared extensions: /usr/lib/php/20151012/
檢視lua.so 檔案
tinywan@tinywan:/usr/lib/php/20151012$ ls build 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 tinywan@tinywan:/usr/lib/php/20151012$ php -m | grep lua lua
安裝完畢
三、測試
檔案test_lua.php
<?php $lua = new Lua(); $lua->eval(<<<CODE function dummy(foo, bar) print(foo, ",", bar) end CODE ); $lua->call("dummy", array("Lua", "geiliable ")); $lua->dummy("Lua", "geiliable"); // __call() var_dump($lua->call(array("table", "concat"), array(array(1=>1, 2=>2, 3=>3), "-"))); ?>
執行結果:
tinywan@tinywan:~/PHP7$ php test_lua.php Lua,geiliable Lua,geiliablestring(11) "1.0-2.0-3.0"
相關文章
- Linux 上安裝 PHP 擴充套件LinuxPHP套件
- PHP Linux安裝擴充套件(編譯安裝)PHPLinux套件編譯
- CentOS 下安裝 PHP Swoole 擴充套件CentOSPHP套件
- PHP 擴充套件安裝PHP套件
- linux與windows下 安裝 ImageMagick 及其 php imagick擴充套件LinuxWindowsPHP套件
- MAC下安裝php-redis擴充套件MacPHPRedis套件
- Linux下給php7安裝memcached擴充套件的步驟LinuxPHP套件
- php mysql擴充套件安裝PHPMySql套件
- php amqp擴充套件安裝PHPMQ套件
- PHP 安裝 yaconf 擴充套件PHP套件
- (MAC) PHP擴充套件安裝MacPHP套件
- PHP安裝redis擴充套件PHPRedis套件
- php以及php擴充套件memcache 安裝PHP套件
- 在Windows下為PHP安裝redis擴充套件WindowsPHPRedis套件
- centos安裝php的oracle擴充套件CentOSPHPOracle套件
- Homestead 安裝 PHP Redis 擴充套件PHPRedis套件
- laradock 中安裝 PHP 擴充套件PHP套件
- docker PHP 安裝 Redis 擴充套件DockerPHPRedis套件
- Laravel homestead 安裝 PHP 擴充套件LaravelPHP套件
- php 擴充套件安裝(隨筆)PHP套件
- PHP 安裝 amqp、rabbitmq 擴充套件PHPMQ套件
- PHP:php7.2.3 安裝pcntl 擴充套件PHP套件
- 【PHP】php安裝bcmath擴充套件指令碼PHP套件指令碼
- Centos6下給PHP安裝Qconf擴充套件CentOSPHP套件
- php怎麼安裝fileinfo擴充套件PHP套件
- [轉貼][php擴充套件-amqp]安裝PHP套件MQ
- php7 安裝rabbitmq 擴充套件PHPMQ套件
- CentOS安裝RabbitMQ及PHP擴充套件CentOSMQPHP套件
- PHP安裝ssh2擴充套件PHP套件
- php7.2 安裝phpredis擴充套件PHPRedis套件
- php7 安裝 imagick 擴充套件PHP套件
- Mac 下使用 pecl 安裝 PHP 的 swoole 擴充套件實踐MacPHP套件
- Mac下使用Pecl安裝PHP的Swoole擴充套件實踐MacPHP套件
- Mac下安裝pthread擴充套件Macthread套件
- 在windows的php中安裝grpc擴充套件WindowsPHPRPC套件
- Linux下編寫一個PHP擴充套件LinuxPHP套件
- PHP-擴充套件-安裝前讀我PHP套件
- docker內給php安裝zmq擴充套件DockerPHPMQ套件
- Docker 安裝 PHP7.4 GD擴充套件DockerPHP套件