Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Php upgrade #181

Merged
merged 6 commits into from
Apr 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Verified compatibility with Vagrant 2.x and loosened Vagrant version requirement
- Config option 'php_version' should now be used for PHP version selection instead of 'use_php7'
- Upgraded Varnish to v4.1
- Improved Magento re-installation speed by avoiding unnecessary cache cleaning
- Custom code sniffer rules replaced with PSR2

### Added

- PHP 7.1 and PHP 7.2 support
- Support for new location of `generated` directory in Magento 2.2.0
- Basic data generation can be turned off. Added configurable product and customer address generation

Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* [Update Composer dependencies](#update-composer-dependencies)
* [Running Magento tests](#running-magento-tests)
* [Environment configuration](#environment-configuration)
* [Switch between PHP 5.6 and 7.0](#switch-between-php-56-and-70)
* [Switch between PHP versions](#switch-between-php-versions)
* [Activating Varnish](#activating-varnish)
* [Activating ElasticSearch](#activating-elasticsearch)
* [Redis for caching](#redis-for-caching)
Expand Down Expand Up @@ -107,12 +107,6 @@ The software listed below should be available in [PATH](https://en.wikipedia.org
bash init_project.sh
```

:information_source: If you get the following error you may need to change the minimum Vagrant compatibility at the top of your `/Vagrantfile` from `Vagrant.require_version "~> 1.8"` to `Vagrant.require_version ">= 1.8"`.

```
Directory ‘e/magento2/vagrant-magento/etc’ was not mounted as expected by Vagrant. Please make sure ...
```

1. Use the `vagrant-magento` directory as the project root in PHP Storm (not `vagrant-magento/magento2ce`). This is important, because in this case PHP Storm will be configured automatically by [init_project.sh](init_project.sh). If NFS files sync is disabled in [config](etc/config.yaml.dist) and ![](docs/images/windows-icon.png)on Windows hosts [verify the deployment configuration in PHP Storm](docs/phpstorm-configuration-windows-hosts.md).

Use the URL for accessing your Magento storefront in the browser as your Web server root URL. Typically this is the localhost, which refers to your development machine. Depending on how you've set up your VM you may also need a port number, like `hhtp://localhost:8080`.
Expand Down Expand Up @@ -291,9 +285,9 @@ See [draft](https://github.com/paliarush/magento2-vagrant-for-developers/issues/

## Environment configuration

### Switch between PHP 5.6 and 7.0
### Switch between PHP versions

Set "use_php7: 1" for PHP7 and "use_php7: 0" for PHP5.6 in [config.yaml](etc/config.yaml.dist).
Switch between PHP versions using "php_version: <version>" option in [config.yaml](etc/config.yaml.dist). Supported versions are 5.6, 7.0, 7.1 and 7.2.
PHP version will be applied after "vagrant reload".

### Activating Varnish
Expand Down Expand Up @@ -358,7 +352,6 @@ Note: See [Working with npm](https://www.npmjs.com/package/n#working-with-npm) i

### FAQ

1. Upgrade to PHP 7.1 can be done as described [here](https://gist.github.com/paliarush/6d88f3267de3bac636956f4be6bb3cd8#file-steps-to-upgrade-environment-to-php-7-1-md). Keep in mind that this is a temporary hack until proper support is implemented in the box
1. To debug any CLI script in current Vagrant project, set `debug:vagrant_project` option in [config.yaml](etc/config.yaml.dist) to `1`
1. Is Windows 10 supported? Yes, but you may face the same issue as described [here](https://github.com/paliarush/magento2-vagrant-for-developers/issues/36). Also Virtual box may not work on Windows 10 in headless mode, see how to [enable GUI mode](https://www.vagrantup.com/docs/virtualbox/configuration.html)
1. ![](docs/images/linux-icon.png)![](docs/images/osx-icon.png) On OSX and \*nix hosts NFS will be used by default to sync your project files with guest. On some hosts Vagrant cannot configure NFS properly, in this case it is possible to deploy project without NFS by setting `use_nfs` option in [config.yaml](etc/config.yaml.dist) to `0` <br />
Expand Down
17 changes: 9 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version "~> 1.8"
Vagrant.require_version ">= 1.8"

require 'yaml'

Expand Down Expand Up @@ -66,13 +66,14 @@ Vagrant.configure(VAGRANT_API_VERSION) do |config|
end

shell_script_args = [
use_nfs_for_synced_folders ? "1" : "0", #1
guest_magento_dir, #2
magento_host_name, #3
config_data['environment']['use_php7'], #4
host_magento_dir, #5
OS.is_windows ? "1" : "0", #6
host_vagrant_dir #7
use_nfs_for_synced_folders ? "1" : "0", #1
guest_magento_dir, #2
magento_host_name, #3
config_data['environment']['use_php7'] || 0, #4 TODO: Remove legacy parameter, replaced with php_version
host_magento_dir, #5
OS.is_windows ? "1" : "0", #6
host_vagrant_dir, #7
config_data['environment']['php_version'] #8
]

config.vm.provision "fix_no_tty", type: "shell", run: "always" do |s|
Expand Down
4 changes: 2 additions & 2 deletions etc/config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ guest:
forwarded_ssh_port: 3000

environment:
# [To apply changes: vagrant reload] If set to 0, PHP 5 will be installed.
use_php7: 1
# [To apply changes: vagrant reload] Valid versions: 5.6, 7.0, 7.1, 7.2
php_version: "7.0"
composer_prefer_source: 0
# [To apply changes: m-reinstall OR m-varnish enable/disable]
use_varnish: 0
Expand Down
6 changes: 4 additions & 2 deletions scripts/guest/check_mounted_directories
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ incrementNestingLevel

if [[ ! -f "${MAGENTO_ROOT}/bin/magento" ]]; then
error "Directory '${MAGENTO_ROOT}' was not mounted as expected and Magento code base is not accessible on the guest machine.
If your host is OSX or *nix, please make sure that Vagrant is able to mount NFS shares on your environment (see https://github.com/paliarush/magento2-vagrant-for-developers/issues/88#issuecomment-254854019 )"
If your host is OSX or *nix, please make sure that Vagrant is able to mount NFS shares on your environment (see https://github.com/paliarush/magento2-vagrant-for-developers/issues/88#issuecomment-254854019 ).
Also remove any stale declarations from /etc/exports on the host."
exit 1
fi

if [[ ! -f "/vagrant/etc/config.yaml" ]]; then
error "Directory '/vagrant/etc' was not mounted as expected by Vagrant and is not accessible on the guest machine.
Please make sure that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html )"
Please make sure that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html ).
Also remove any stale declarations from /etc/exports on the host."
exit 1
fi

Expand Down
3 changes: 2 additions & 1 deletion scripts/host/check_mounted_directories.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ cd "${vagrant_dir}"
if [[ ! -f "${vagrant_dir}/etc/guest/mysql/my.cnf" ]]; then
error "Directory '${vagrant_dir}/etc' was not mounted as expected by Vagrant.
Please make sure that 'paliarush/magento2.ubuntu' Vagrant box was downloaded successfully (if not, this may help http://stackoverflow.com/questions/35519389/vagrant-cannot-find-box)
And that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html )"
And that Vagrant is able to mount VirtualBox shared folders on your environment (see https://www.vagrantup.com/docs/synced-folders/basic_usage.html ).
Also remove any stale declarations from /etc/exports on the host."
exit 1
fi
vagrant ssh -c "bash /vagrant/scripts/guest/check_mounted_directories" 2> >(logError)
Expand Down
65 changes: 25 additions & 40 deletions scripts/provision/configure_environment_recurring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,10 @@ function process_php_config () {
sed -i "s|display_startup_errors = Off|display_startup_errors = On|g" ${php_ini_path}
sed -i "s|error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT|error_reporting = E_ALL|g" ${php_ini_path}
sed -i "s|;always_populate_raw_post_data = -1|always_populate_raw_post_data = -1|g" ${php_ini_path}

# TODO: Fix for a bug, should be removed in 3.0
sed -i "s|:/vendor/phpunit/phpunit|:${guest_magento_dir}/vendor/phpunit/phpunit|g" ${php_ini_path}
fi
done
}

function init_php56 () {
status "Installing PHP 5.6"
add-apt-repository ppa:ondrej/php 2> >(logError) > >(log)
apt-get update 2> >(logError) > >(log)
apt-get install -y php5.6 php-xdebug php5.6-xml php5.6-mcrypt php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-bcmath php5.6-mbstring php5.6-soap php5.6-zip libapache2-mod-php5.6 2> >(logError) > >(log)
echo '
xdebug.max_nesting_level=200
xdebug.remote_enable=1
xdebug.remote_host=192.168.10.1' >> /etc/php/5.6/mods-available/xdebug.ini
}

function isServiceAvailable() {
all_services="$(service --status-all 2> >(log))"
if [[ ${all_services} =~ ${1} ]]; then
Expand All @@ -46,7 +32,19 @@ function isNodeJsInstalled() {
}

guest_magento_dir=$2
use_php7=$4
use_php7=$4 # TODO: Remove deprecated argument, php_version should be used instead
php_version=$8

# TODO: Remove support for deprecated argument use_php7
if [[ -z ${php_version} ]]; then
if [[ ${use_php7} -eq 1 ]]; then
php_version="7.0"
else
php_version="5.6"
fi
fi


vagrant_dir="/vagrant"

source "${vagrant_dir}/scripts/output_functions.sh"
Expand Down Expand Up @@ -81,29 +79,20 @@ else
fi

status "Setting up PHP"
php_ini_paths=( /etc/php/7.0/cli/php.ini /etc/php/5.6/cli/php.ini )

php_ini_paths=( /etc/php/5.6/cli/php.ini /etc/php/7.0/cli/php.ini /etc/php/7.1/cli/php.ini /etc/php/7.2/cli/php.ini )
process_php_config ${php_ini_paths}

if [[ ${use_php7} -eq 1 ]]; then
status "Configuring PHP 7"
update-alternatives --set php /usr/bin/php7.0
if [[ -d "/etc/php/5.6" ]]; then
a2dismod php5.6 2> >(logError) > >(log)
fi
sed -i "s|xdebug.remote_connect_back=1|xdebug.remote_host=192.168.10.1|g" /etc/php/7.0/cli/conf.d/20-xdebug.ini
a2enmod php7.0 2> >(logError) > >(log)
# TODO: Fix for a bug, should be removed in 3.0
sed -i "/zend_extension=.*so/d" /etc/php/7.0/cli/conf.d/20-xdebug.ini
echo "zend_extension=xdebug.so" >> /etc/php/7.0/cli/conf.d/20-xdebug.ini
if [[ ${php_version} == "5.6" ]] || [[ ${php_version} == "7.0" ]] || [[ ${php_version} == "7.1" ]] || [[ ${php_version} == "7.2" ]]; then
status "Configuring PHP ${php_version}"
update-alternatives --set php "/usr/bin/php${php_version}"
a2dismod php5.6 2> >(logError) > >(log) && a2dismod php7.0 2> >(logError) > >(log) && a2dismod php7.1 2> >(logError) > >(log) && a2dismod php7.2 2> >(logError) > >(log)
a2enmod "php${php_version}" 2> >(logError) > >(log)
sed -i "s|xdebug.remote_connect_back=1|xdebug.remote_host=192.168.10.1|g" "/etc/php/${php_version}/cli/conf.d/20-xdebug.ini"
else
status "Configuring PHP 5.6"
if [[ ! -d "/etc/php/5.6" ]]; then
init_php56
fi
update-alternatives --set php /usr/bin/php5.6 && a2dismod php7.0 && a2enmod php5.6 2> >(logError) > >(log)
rm -rf /etc/php/5.6/apache2
ln -s /etc/php/5.6/cli /etc/php/5.6/apache2
sed -i "s|xdebug.remote_connect_back=1|xdebug.remote_host=192.168.10.1|g" /etc/php/5.6/mods-available/xdebug.ini
error "PHP version specified in the etc/config.yam is not supported."
decrementNestingLevel
exit 1
fi
service apache2 restart 2> >(logError) > >(log)

Expand All @@ -118,11 +107,7 @@ if [[ ${is_elastic_search_installed} -eq 0 ]]; then
fi

status "Enabling email logging"
if [[ ${use_php7} -eq 1 ]]; then
php_ini_file="/etc/php/7.0/cli/php.ini"
else
php_ini_file="/etc/php/5.6/cli/php.ini"
fi
php_ini_file="/etc/php/${php_version}/cli/php.ini"
pattern=";sendmail_path"
php_config_content="$(cat ${php_ini_file})"
if [[ ${php_config_content} =~ ${pattern} ]]; then
Expand Down
85 changes: 85 additions & 0 deletions scripts/provision/upgrade_environment_recurring.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,91 @@ if [[ ${is_redis_installed} -eq 0 ]]; then
echo -n | sudo utils/install_server.sh 2> >(logError) > >(log)
fi

function install_php71 () {
status "Installing PHP 7.1"

apt-get update

# Setup PHP
apt-get install -y language-pack-en-base
LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
apt-get update

# Install PHP 7.1
apt-get install -y php7.1 php7.1-mcrypt php7.1-curl php7.1-cli php7.1-mysql php7.1-gd php7.1-intl php7.1-xsl php7.1-bcmath php7.1-mbstring php7.1-soap php7.1-zip libapache2-mod-php7.1

# Install XDebug
apt-get install -y php7.1-dev
cd /usr/lib
rm -rf xdebug71
git clone git://github.com/xdebug/xdebug.git xdebug71
cd xdebug71
phpize
./configure --enable-xdebug
make
make install
## Configure XDebug to allow remote connections from the host
mkdir -p /etc/php/7.1/cli/conf.d
touch /etc/php/7.1/cli/conf.d/20-xdebug.ini
echo 'zend_extension=/usr/lib/xdebug71/modules/xdebug.so
xdebug.max_nesting_level=200
xdebug.remote_enable=1
xdebug.remote_host=192.168.10.1
xdebug.idekey=phpstorm' >> /etc/php/7.1/cli/conf.d/20-xdebug.ini
echo "date.timezone = America/Chicago" >> /etc/php/7.1/cli/php.ini
rm -rf /etc/php/7.1/apache2
ln -s /etc/php/7.1/cli /etc/php/7.1/apache2
}

function install_php72 () {
status "Installing PHP 7.2"

apt-get update

# Setup PHP
apt-get install -y language-pack-en-base
LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
apt-get update

# Install PHP 7.2
apt-get install -y php7.2 php7.2-curl php7.2-cli php7.2-mysql php7.2-gd php7.2-intl php7.2-xsl php7.2-bcmath php7.2-mbstring php7.2-soap php7.2-zip libapache2-mod-php7.2

# Install XDebug
apt-get install -y php7.2-dev
cd /usr/lib
rm -rf xdebug72
git clone git://github.com/xdebug/xdebug.git xdebug72
cd xdebug72
phpize
./configure --enable-xdebug
make
make install
## Configure XDebug to allow remote connections from the host
mkdir -p /etc/php/7.2/cli/conf.d
touch /etc/php/7.2/cli/conf.d/20-xdebug.ini
echo 'zend_extension=/usr/lib/xdebug72/modules/xdebug.so
xdebug.max_nesting_level=200
xdebug.remote_enable=1
xdebug.remote_host=192.168.10.1
xdebug.idekey=phpstorm' >> /etc/php/7.2/cli/conf.d/20-xdebug.ini
echo "date.timezone = America/Chicago" >> /etc/php/7.2/cli/php.ini
rm -rf /etc/php/7.2/apache2
ln -s /etc/php/7.2/cli /etc/php/7.2/apache2
}


if [[ ! -d "/etc/php/7.1" ]]; then
install_php71
fi

if [[ ! -d "/etc/php/7.2" ]]; then
install_php72
fi

# TODO: Fix for a bug, should be removed in 3.0
sed -i "/zend_extension=.*so/d" /etc/php/7.0/cli/conf.d/20-xdebug.ini
echo "zend_extension=xdebug.so" >> /etc/php/7.0/cli/conf.d/20-xdebug.ini

status "Fixing potential issue with MySQL being down after VM power off"
service mysql restart 2> >(logError) > >(log)

Expand Down