Wiki

Clone wiki

ember2drupal / Drupal

Работа с Drupal 8

Drupal logo

Bash | VIM | Ubuntu/PHP7-FPM/Nginx/PostgreSQL | Drupal 8 | git flow

Установка ПО:

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update && sudo apt-get install php7.0 php7.0-fpm php7.0-opcache php7.0-gd php7.0-sqlite3 php7.0-pgsql
sudo apt-get install nginx
sudo apt-get install postgresql-9.5 postgresql-client-9.5
sudo apt-get install git git-flow

Bash командная оболочка

Пример настройки приглашения командной строки:

# ~/.bashrc
# Bash long color prompt:
export PS1="\n\[$(tput sgr0)\]\[\033[38;5;8m\]\t\[$(tput sgr0)\]\[\033[38;5;15m\]\n\[$(tput sgr0)\]\[\033[38;5;8m\]\u\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;7m\]@\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;8m\]\H\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;7m\]:\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;7m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]\n\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') \[$(tput sgr0)\]\[\033[38;5;9m\]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"

Обновление окружения:

source ~/.bashrc

Текстовый редактор VIM

Установка менеджера расширений Vundle:

 git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

Конфигурация VIM:

#~/.vimrc
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'scrooloose/nerdtree'
Plugin 'tpope/vim-fugitive'
Plugin 'godlygeek/tabular'
Plugin 'majutsushi/tagbar'
Plugin 'w0ng/vim-hybrid'
Plugin 'StanAngeloff/php.vim'
Plugin 'evidens/vim-twig'
Plugin 'kchmck/vim-coffee-script'
Plugin 'cakebaker/scss-syntax.vim'
Plugin 'plasticboy/vim-markdown'
Plugin 'suan/vim-instant-markdown'
call vundle#end()
set exrc
set number
set t_Co=256
set cursorline
set cursorcolumn
set nocompatible
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
let NERDTreeShowHidden=1
syntax enable
autocmd VimEnter * NERDTree
filetype plugin indent on
colorscheme hybrid

Управление расширениями VIM:

vim ~/.vimrc
:so ~/.vimrc
:PluginInstall
:PluginUpdate
:PluginClean

PHP-FPM Сервер

# /etc/php/7.0/fpm/php-fpm.conf
pid = /run/php/php7.0-fpm.pid
error_log = /var/log/php7.0-fpm.log
include=/etc/php/7.0/fpm/pool.d/*.conf
# /etc/php/7.0/fpm/pool.d/www.conf
user = www-data
group = www-data
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php -v
php -m

WEB сервер

Настройка сервера:

# /etc/nginx/nginx.conf
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
    worker_connections 768;
}
http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  client_max_body_size 12m;
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
  gzip on;
  gzip_disable "msie6";
  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

Настройка виртуального хоста:

# /etc/hosts
127.0.0.1   drupal.local
# /etc/nginx/site-avalible/drupal.local
server {
        server_name drupal.local;
        root /home/YOUR_USER/projects/drupal; ## <-- Your only path reference.
        gzip_static on;
        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }
        location ~* \.(txt|log)$ {
                allow 192.168.0.0/16;
                deny all;
        }
        location ~ \..*/.*\.php$ {
                return 403;
        }
        location ~ ^/sites/.*/private/ {
                return 403;
        }
        location ~ (^|/)\. {
                return 403;
        }
        location / {
                try_files $uri @rewrite;
        }
        location @rewrite {
                rewrite ^ /index.php;
        }
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $request_filename;
                fastcgi_intercept_errors on;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}
sudo ln -s /etc/nginx/sites-available/drupal.local /etc/nginx/sites-enabled/drupal.local
sudo service nginx restart
# options: configtest force-reload reload restart rotate start status stop upgrade

Сервер базы данных

sudo service postgresql status
sudo -i -u postgres
psql
CREATE DATABASE drupal;
CREATE USER drupal WITH password '1234567890';
GRANT ALL privileges ON DATABASE drupal TO drupal;
ALTER DATABASE "drupal" SET bytea_output = 'escape';
\q
exit

Drupal

Установка Composer:

curl -sS https://getcomposer.org/installer | php

Поиск пакетов в Composer:

composer search drupal

Создание нового проекта Drupal:

composer create-project drupal/drupal NAME_OF_YOUR_PROJECT 8.0.1
# or
# composer create-project drupal/drupal NAME_OF_YOUR_PROJECT 8.0.*@dev
composer install
cd NAME_OF_YOUR_PROJECT && vim

Установка Drush:

# ~/.bash_prpfile
export PATH="$HOME/.composer/vendor/bin:$PATH"
source ~/.bash_profile
composer global require drush/drush:dev-master
# Use
drush

Установка Drupal Console:

curl https://drupalconsole.com/installer -L -o drupal.phar
# Or if you don't have curl:
# php -r "readfile('https://drupalconsole.com/installer');" > drupal.phar
sudo mv drupal.phar /usr/local/bin/drupal
sudo chmod +x /usr/local/bin/drupal
drupal list
# Update to the latest version.
sudo drupal self-update

Установка Drupal:

drush site-install standard --db-url=pgsql://DB_USER:DB_USER_PASS@127.0.0.1/DB
# drush site-install --db-url=sqlite://sites/default/files/.ht.sqlite
drush upwd admin --password=ADMIN_PASS
chown -R YOUR_USER:www-data ~/projects/drupal

Контроль версий с git flow

git flow init
git flow feature start initial
git add -A
git commit -am 'Initial'
git flow feature finish initial
git flow release start 1.0
git flow release finish 1.0
git push --tags

Updated