Linux lampp/xampp环境Elasticsearch-PHP安装笔记

①检查依赖

本地是Ubuntu18.04环境,简易安装的lampp环境。Elasticsearch-PHP依赖于PHP7,先查看一下lampp自带的PHP版本。

root@ubuntu:~# whereis php
php: /opt/lampp/bin/php
root@ubuntu:~# ls -l /opt/lampp/bin/ | grep php
-rwxr-xr-x 1 root root      240 Oct 13 18:36 gen_php_doc.sh
-rwxr-xr-x 1 root root      107 Oct 13 18:34 html_template_phplibtool
lrwxrwxrwx 1 root root       10 Nov 19 18:34 php -> php-7.2.11
-rwxr-xr-x 1 root root 15922272 Oct 13 18:37 php-7.2.11
lrwxrwxrwx 1 root root       14 Nov 19 18:34 php-cgi -> php-cgi-7.2.11
-rwxr-xr-x 1 root root 15869312 Oct 13 18:37 php-cgi-7.2.11
lrwxrwxrwx 1 root root       17 Nov 19 18:34 php-config -> php-config-7.2.11
-rwxr-xr-x 1 root root     4396 Oct 13 18:27 php-config-7.2.11
-rwxr-xr-x 1 root root 16098880 Oct 13 18:37 phpdbg
lrwxrwxrwx 1 root root       13 Nov 19 18:34 phpize -> phpize-7.2.11
-rwxr-xr-x 1 root root     4547 Oct 13 18:27 phpize-7.2.11
-rwxr-xr-x 1 root root     1941 Oct 13 18:36 phpunit
-rwxr-xr-x 1 root root   158280 Oct 13 18:37 swftophp
root@ubuntu:~# /opt/lampp/bin/php -v
PHP 7.2.11 (cli) (built: Oct 13 2018 09:27:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

②配置composer

root@ubuntu:~# cd /opt/lampp/htdocs/
root@ubuntu:/opt/lampp/htdocs# vim composer.json
root@ubuntu:/opt/lampp/htdocs# cat composer.json
{
	"require": {
		"elasticsearch/elasticsearch": "~6.0"
	}
}

③安装composer

root@ubuntu:/opt/lampp/htdocs# cd ../bin/
root@ubuntu:/opt/lampp/bin# wget http://getcomposer.org/installer
root@ubuntu:/opt/lampp/bin# ./php installer

④安装Elasticsearch-PHP

root@ubuntu:/opt/lampp/bin# cd ../htdocs/
root@ubuntu:/opt/lampp/htdocs# ../bin/php ../bin/composer.phar install --no-dev
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies
Package operations: 5 installs, 0 updates, 0 removals
  - Installing psr/log (1.1.0): Downloading (100%)         
  - Installing react/promise (v2.7.1): Downloading (100%)         
  - Installing guzzlehttp/streams (3.0.0): Downloading (100%)         
  - Installing guzzlehttp/ringphp (1.1.1): Downloading (100%)         
  - Installing elasticsearch/elasticsearch (v6.1.0): Downloading (100%)         
Writing lock file
Generating autoload files

⑤测试安装

root@ubuntu:/opt/lampp/htdocs# vim es.php
root@ubuntu:/opt/lampp/htdocs# cat es.php 
<?php
require 'vendor/autoload.php';

use Elasticsearch\ClientBuilder;

$client = ClientBuilder::create()->build();


$params = [
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
    'body' => ['testField' => 'abc']
];

$response = $client->index($params);
print_r($response);
?>

打开浏览器,查看发现index插入成功。

 

 

参考:

https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_installation_2.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值