1. 升级Mac自带的PHP至7.2版本
$ brew install php -会将PHP版本更新到最新版本
命令运行结束后,打开 /etc/apache2/httpd.conf ,将红框内容加到文件中,保存。
$ brew services start php -启动PHP
$ sudo /usr/sbin/apachectl restart -重启Apache
$ php -v -检查是否显示为最新版本
新版本PHP的ini文件位置:/usr/local/etc/php/7.2/php.ini
2. 搭建Homestead环境
下载并安装 VirtualBox和Vagrant,都是可视化操作。
Vagrant是一个基于Ruby的虚拟机的管理工具,通过命令和配置文件,部署虚拟化开发环境,并可以打包传播。
Vagrant配置参考 https://blog.csdn.net/u011781521/article/details/80291765
假设我们已经从代码仓库clone下来了一个Laravel框架的项目,进入项目根目录,引入homestead。
$ composer require laravel/homestead --dev
该命令很可能因为内存大小的限制而执行失败
$ php -r "echo ini_get('memory_limit').PHP_EOL;" --查看内存限制
$ php -d memory_limit=-1 /usr/local/bin/composer require laravel/homestead --dev --解决方法
homestead会安装在vendor文件夹,接下来需要生产Homestead.yaml文件
$ vendor/bin/homestead make
$ vagrant up --vagrant的执行需要读取Homestead.yaml中的配置,暂不确定执行vagrant up时是否需要手动打开VirtualBox。
默认用户名 : vagrant , 登录密码 : vagrant
如果在虚拟机上访问不到代码所在的共享文件夹,可以关闭再启动
$ vagrant halt
$ vagrant up
$ vagrant provision 更新配置后执行此命令
$vagrant reload
另外,Homestead中的mysql/postgres数据库
用户名:homestead
密码:secret
3.在Homestead环境中安装Elasticsearch
# Login as root
vagrant@healthcomps:~# sudo -s
# Update Aptitude
root@healthcomps:~# apt-get update
# Install Java
root@healthcomps:~# apt-get install default-jre
# Download and install Elasticsearch Public Signing Key
root@healthcomps:~# wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
# Install Elasticsearch
root@healthcomps:~# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.1.tar.gz
# Unzip
root@healthcomps:~# tar -xzvf elasticsearch-6.5.1.tar.gz
# Start Elasticsearch server
root@healthcomps:~# ./elasticsearch-6.5.1/bin/elasticsearch
提示不可以用root启动elasticsearch
root@healthcomps:~# exit
vagrant@healthcomps:~$ ./elasticsearch-6.5.1/bin/elasticsearch -d
错误提示:Exception in thread "main" java.nio.file.AccessDeniedException
sudo chown vagrant ./elasticsearch-6.5.1 -R
再次启动成功
打开另一个窗口(Win+F2) 测试一下Elasticsearch是否已启动: