Установка Elgg на Homestead

Homestead — это отличный образ Vagrant, созданный разработчиками Laravel специально для PHP-разработки. Он позволяет настроить виртуальную машину Ubuntu за считанные минуты, экономя время на установке и настройке сервера Apache и всех остальных инструментов, необходимых для локальной разработки и тестирования.

1. Установка Homestead

Установите одного из предпочтительных провайдеров виртуальных машин, Vagrant и Homestead, следуя инструкциям на https://laravel.com/docs/5.4/homestead

Если у вас установлены виртуальная машина и Vagrant, вы можете использовать следующие команды

vagrant box add laravel/homestead

# navigate to the directory that will hold your Homestead installation, e.g. your home directory
cd ~
git clone https://github.com/laravel/homestead.git Homestead
cd Homestead
# checkout the latest stable release
git checkout <tagged release version>
bash init.sh

Предупреждение

В Windows обязательно запускайте инструмент командной строки от имени администратора.

2. Настройка Homestead

Отредактируйте Homestead.yaml, чтобы включить детали вашего нового проекта(ов) Elgg. В следующем примере мы настроим два приложения Elgg — одно из исходного кода git и одно с использованием стартового проекта. Обратите внимание, что при настройке сайтов вы можете использовать тип сайта «elgg», который автоматически настроит nginx vhosts с помощью скрипта конфигурации оболочки

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/apps/elgg-starter
      to: /home/vagrant/Code/elgg-starter
      type: "nfs"

    - map: ~/apps/elgg-git
      to: /home/vagrant/Code/elgg-git
      type: "nfs"

sites:
    - map: elgg-starter.app
      to: /home/vagrant/Code/elgg-starter/public
      type: elgg

    - map: elgg-git.app
      to: /home/vagrant/Code/elgg-git/public
      type: elgg

databases:
    - elgg-sandbox
    - elgg-git

NFS не поддерживается в Windows, но вы можете попробовать плагин WinNFSd

3. Обновление hosts

Обновите файл hosts, чтобы указать домены, настроенные в Homestead, на IP-адрес коробки Vagrant. Это позволит вам получать доступ к вашим сайтам по доменному имени из браузера

192.168.10.10 elgg-starter.app
192.168.10.10 elgg-git.app

4.a Установка Elgg с использованием starter-project

# create the directory to hold the project on your local machine
cd ~/apps
mkdir elgg-starter

# head to your Homestead installation directory
cd ~/Homestead

# launch the Vagrant box
# this will automatically create all the project directories,
# setup vhosts and create the databases
vagrant up

# SSH into your Vagrant box
vagrant ssh

# you can use the cli tool to also install Elgg without leaving the console
# you can skip this if you want to install Elgg in your browser
composer global require hypejunction/elgg-cli

# new project folder should have automatically created during vagrant up
# this directory should be in full sync with your local machine
cd /home/vagrant/Code/elgg-starter

# create the data directory that will hold Elgg's cache and uploaded files
# when prompted for dataroot during installation, you should set it to /home/vagrant/Code/elgg-starter/data/
mkdir data

# create a new project from Elgg's starter project
# watch out for messages, you may need to add your github token here
# when prompted for installation root during installation, you should set it to /home/vagrant/Code/elgg-starter/public/
composer create project elgg/starter-project:dev-master public

# install composer dependencies
cd public

# run composer install twice! don't ask why
composer install
composer install

# now if you head to your browser at http://elgg-starter.app/ you should should be able to install Elgg
# using the installation interface
# alternatively, use the cli tool we have required previously, and follow the prompts
# note that the default "root" user password for most services on the Homestead box is "secret",
# DB name is "elgg-starter" as seen in Homestead config
elgg-cli install

# run some tests
vendor/bin/phpunit

# if you are planning to use this project for development, you can commit it to git
git init
git add .
git commit -a -m 'Base starter project'
git remote add origin git@github.com:name/project.git
git push -u origin master

composer require elgg/mentions

git add .
git commit -a -m 'Added mentions plugin'
git push origin master

# you can then open the project on your local machine, make changes using an editor, and commit via this console
# this saves you the trouble of installing composer, git et al locally

# to end the ssh session with the box
exit

# after finishing work with the box, you can choose to suspend, halt or destroy it
# https://www.vagrantup.com/intro/getting-started/teardown.html
# destroying the box will wipe the databases, so if you plan to continue using the
# installation, you may want to just halt the box

4.b Установка Elgg из исходного кода

Теперь мы можем установить наш второй git-проект, который можно использовать для внесения кода обратно в ядро.

# create the directory to hold the project on your local machine
cd ~/apps
mkdir elgg-git

# head to your Homestead installation directory
cd ~/Homestead

# we already a vagrant box running, so we need to provision it for the changes to take effect
# in this particular case, we have added a local directory, which will need to be mounted and
# mapped to the directory on the box
vagrant reload --provision

# SSH into your Vagrant box
vagrant ssh

cd /home/vagrant/Code/elgg-git

# create the data directory that will hold Elgg's cache and uploaded files
# when prompted for dataroot during installation, you should set it to /home/vagrant/Code/elgg-git/data
mkdir data

# when prompted for installation root during installation, you should set it to /home/vagrant/Code/elgg-git/public
# fork Elgg/Elgg on github and clone your fork
git clone https://github.com/mygitname/Elgg.git public

# install composer dependencies
cd public
composer install

# now if you head to your browser at http://elgg-git.app/ you should should be able to install Elgg
# using the installation interface
# alternatively, use the cli tool we have required previously, and follow the prompts
# note that the default root password for most services on the Homestead box is "secret"
elgg-cli install

# add upstream to original Elgg repository, so we can later make pull requests
git remote add upstream https://github.com/Elgg/Elgg.git

# create a new branch
git branch my-fix

# add your fixes using an editor on the local machine
# test your changes by visiting http://elgg-git.app/
# run automated tests
# commit and push your changes
vendor/bin/phpunit
git add .
git commit -a -m 'fix(component): describe the fix'

git push origin my-fix

# rebase against upstream if your branch has diverged or you need to squash/edit commits
git fetch upstream
git rebase -i upstream/master
git push --force origin my-fix

exit

5. Другое

cd ~/Homestead
vagrant ssh


# setup cache symlink for improved performance
cd /home/vagrant/Code/elgg-starter/public
ln -l /home/vagrant/Code/elgg-starter/data/views_simplecache/ cache

# you should see the symlink if you do
ls -l


# setup cron jobs
crontab -e
# add the following lines and save
# * * * * * /usr/bin/wget -q http://elgg-starter.app/cron/run/ --spider
# verify that that crontab is set / you can also check Admin > Statistics > Cron to see if the cron is running
crontab -l


# backup the database
cd /home/vagrant/Code/elgg-starter/
mkdir backups
mysqldump -u root -psecret elgg-starter > backups/elgg-starter.sql


# restore the database
mysql -u root -psecret elgg-starter < backups/elgg-starter.sql