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 版本是否为刚安装的版本

[email protected]:~/lua-5.3.4$ lua -v
Lua 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.h
ln: 无法创建符号链接‘/usr/include/lua/lua.h‘: 没有那个文件或目录
[email protected]:/usr/local/include$ ln -s /usr/local/include/lua.h /usr/include/lua/lua.h
ln: 无法创建符号链接‘/usr/include/lua/lua.h‘: 没有那个文件或目录
[email protected]:/usr/local/include$ mkdir -P /usr/include/lua
mkdir:无效选项 -- P
Try ‘mkdir --help‘ for more information.
[email protected]:/usr/local/include$ mkdir -R /usr/include/lua
mkdir:无效选项 -- R
Try ‘mkdir --help‘ for more information.
[email protected]:/usr/local/include$ mkdir - /usr/include/lua
mkdir: 无法创建目录"-": 权限不够
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.h
ln: 无法创建符号链接‘/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.a
liblua: /usr/local/lib/liblua.a
[email protected]:/usr/local/include$ cp /usr/local/lib/liblua.a /usr/lib/liblua.a
cp: 无法创建普通文件‘/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.tgz

cd lua-2.0.3

phpize

./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/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 文件

[email protected]:/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

[email protected]:/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\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,geiliable
Lua,geiliablestring(11) "1.0-2.0-3.0"
时间: 2024-10-20 02:45:36

Linux下安装PHP的lua扩展库的相关文章

linux下安装php的svn扩展

首先,下载svn,默认下载路径是当前操作的目录下: wget http://pecl.php.net/get/svn-1.0.2.tgz 解压svn: tar -zxf svn-1.0.1.tgz 进入到svn目录下: cd svn-1.0.1 然后,依次运行命令: /usr/local/php5.5/bin/phpize ./configure--with-php-config=/usr/local/php5.5/bin/php-config make makeinstall 注意:我用的是p

Linux下安装PHP的GD支持库

Linux下安装PHP的GD支持库 1.安装 zlib  wget ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/zlib-1.2.3.tar.gz tar -zxf zlib-1.2.3.tar.gz cd zlib-1.2.3 ./configure –prefix=/usr/local/zlib make make install 2.安装 jpeg wget ftp://ftp.sunfreeware.com/pub/freeware/SO

Linux下安装Python3.x和第三方库

如果本机安装了python2,尽量不要管他,使用python3运行python脚本就好,因为可能有程序依赖目前的python2环境, 比如yum!!!!! 不要动现有的python2环境! 不要动现有的python2环境! 不要动现有的python2环境! 重要的使用说三遍! 一.安装python3.6 1. 安装依赖环境 # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readli

Linux下安装PHP的mcrypt扩展

首先下载,并安装 libmcrypt-2.5.8.tar.gz 下载地址: http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459 mhash-0.9.9.tar.gz 下载地址: http://sourceforge.net/project/showfiles.php?group_id=4286&package_id=4300&releas

Linux下安装redis以及redis扩展

//安装redis //下载redis wget http://download.redis.io/releases/redis-2.8.3.tar.gz //解压 tar xzf redis-2.8.3.tar.gz//进入解压后的文件 cd redis-2.8.3//编译 make //安装成功 //自己创建一个新的文件夹(任何位置)mkdir /usr/redis //移动redis.conf到新目录下 cp redis.conf  /usr/redis //再进入redis安装目录 cd

Linux下安装Python3.6和第三方库

一.安装Python-3.6.2.tgz 安装依赖环境 最小化安装Redhat6.4环境下 yum -y install    gcc make zlib-devel bzip2-devel  ncurses-devel  readline-devel (yum -y install  gcc make zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel db4-devel

linux下安装redis和phpredis扩展

一.安装redis 1.下载redis-3.2.3.tar.gz wget http://download.redis.io/releases/redis-3.2.3.tar.gz 2.解压redis-3.2.3.tar.gz tar -zxvf redis-3.2.3.tar.gz 3.解压完成后,安装 cd redis-3.2.3 make && make install 4.切换到utils,执行redis初始化脚本install_server.sh cd utils ./insta

linux下安装opcache扩展

linux下安装opcache扩展 参考:http://www.php.net/manual/zh/opcache.installation.php 1 2 3 4 5 6 7 wget http://pecl.php.net/get/zendopcache-7.0.2.tgz tar zxvf zendopcache-7.0.2.tgz cd zendopcache-7.0.2 /usr/local/php/bin/phpize ./configure --with-php-config=/u

linux 下安装 php kafka 扩展

我们使用官方推荐 php kafka 扩展 phpkafka,由于该扩展是基于 librdkafka 开发,所以我们首先需要安装 librdkafka 下载地址:http://kafka.apache.org/downloads PHP 扩展:https://github.com/arnaud-lb/php-rdkafka 1.解压 librdkafka,执行 linux 下安装三部曲:./configure --> make --> make install ,此时在 /usr/local/