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

Set php version #2488

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ permalink: /docs/en-US/changelog/
* Switch from Ubuntu 18.04 to 20.04 (current LTS release)
* Simplified config folder
* Increased the default PHP memory limit from 128MB to 256MB
* Function to change the global PHP version

### Bug Fixes

Expand Down
13 changes: 13 additions & 0 deletions config/homebin/get_php_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
#
# Get PHP version from config.yml or fallback to the system version
set -eo pipefail

source /srv/provision/provision-helpers.sh

phpversion=$(get_config_value "general.default_php")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is missing the default from VVV.

if [[ ! -z "$phpversion" ]]; then
phpversion=$(php --version | head -n 1 | cut -d " " -f 2 | cut -c 1-3)
fi

echo "$phpversion"
2 changes: 1 addition & 1 deletion config/homebin/vvv_restore_php_default
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

DEFAULTPHP="7.4"
DEFAULTPHP=$(get_php_version.sh)
echo " * Restoring the default PHP CLI version ( ${DEFAULTPHP} )"
update-alternatives --set php "/usr/bin/php${DEFAULTPHP}"
update-alternatives --set phar "/usr/bin/phar${DEFAULTPHP}"
Expand Down
2 changes: 1 addition & 1 deletion config/php-config/php-custom.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ track_errors = Off
html_errors = 1

; Log errors to specified file.
error_log = /var/log/php/php7.4_errors.log
error_log = /var/log/php/phpVVV_PHP_VERSION_errors.log

; Maximum size of POST data that PHP will accept.
post_max_size = 1024M
Expand Down
8 changes: 4 additions & 4 deletions config/php-config/php-fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
; Relative path can also be used. They will be prefixed by:
; - the global prefix if it's been set (-p argument)
; - /usr otherwise
;include=/etc/php/7.4/fpm/*.conf
;include=/etc/php/VVV_PHP_VERSION/fpm/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
Expand All @@ -22,14 +22,14 @@
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /run/php/php7.4-fpm.pid
pid = /run/php/phpVVV_PHP_VERSION-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php/php7.4-fpm.log
error_log = /var/log/php/phpVVV_PHP_VERSION-fpm.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
Expand Down Expand Up @@ -126,4 +126,4 @@ error_log = /var/log/php/php7.4-fpm.log

; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php/7.4/fpm/pool.d/*.conf
include=/etc/php/VVV_PHP_VERSION/fpm/pool.d/*.conf
2 changes: 1 addition & 1 deletion config/php-config/php-www.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ group = www-data
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php7.4-fpm.sock
listen = /var/run/phpVVV_PHP_VERSION-fpm.sock

; Set listen(2) backlog. A value of '-1' means unlimited.
; Default Value: 128 (-1 on FreeBSD and OpenBSD)
Expand Down
4 changes: 2 additions & 2 deletions config/php-config/upstream.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Upstream to abstract backend connection(s) for PHP.
upstream php74 {
server unix:/var/run/php7.4-fpm.sock;
upstream phpVVV_PHP_VERSION {
server unix:/var/run/phpVVV_PHP_VERSION-fpm.sock;
}
2 changes: 1 addition & 1 deletion provision/core/nginx/config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ http {

# Upstream to abstract backend connection(s) for PHP.
upstream php {
server unix:/var/run/php7.4-fpm.sock;
server unix:/var/run/phpVVV_PHP_VERSION-fpm.sock;
}

include /etc/nginx/upstreams/*.conf;
Expand Down
2 changes: 2 additions & 0 deletions provision/core/nginx/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ function nginx_setup() {

vvv_info " * Setup configuration files..."


# Copy nginx configuration from local
vvv_info " * Copying /srv/provision/core/nginx/config/nginx.conf to /etc/nginx/nginx.conf"
cp -f "/srv/provision/core/nginx/config/nginx.conf" "/etc/nginx/nginx.conf"
vvv_php_set_version_file "/etc/nginx/nginx.conf"

vvv_info " * Copying /srv/provision/core/nginx/config/nginx-wp-common.conf to /etc/nginx/nginx-wp-common.conf"
cp -f "/srv/provision/core/nginx/config/nginx-wp-common.conf" "/etc/nginx/nginx-wp-common.conf"
Expand Down
6 changes: 5 additions & 1 deletion provision/core/php/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @description Installs the default version of PHP
set -eo pipefail

VVV_BASE_PHPVERSION=${VVV_BASE_PHPVERSION:-"7.4"}
VVV_BASE_PHPVERSION=$(get_php_version.sh)
function php_register_packages() {
local OSID=$(lsb_release --id --short)
local OSCODENAME=$(lsb_release --codename --short)
Expand Down Expand Up @@ -70,11 +70,14 @@ function phpfpm_setup() {
if [ -d "/etc/php/${VVV_BASE_PHPVERSION}/fpm" ]; then
vvv_info " * Copying PHP configs"
cp -f "/srv/config/php-config/php-fpm.conf" "/etc/php/${VVV_BASE_PHPVERSION}/fpm/php-fpm.conf"
vvv_php_set_version_file "/etc/php/${VVV_BASE_PHPVERSION}/fpm/php-fpm.conf"
if [ -d "/etc/php/${VVV_BASE_PHPVERSION}/fpm/pool.d" ]; then
cp -f "/srv/config/php-config/php-www.conf" "/etc/php/${VVV_BASE_PHPVERSION}/fpm/pool.d/www.conf"
vvv_php_set_version_file "/etc/php/${VVV_BASE_PHPVERSION}/fpm/pool.d/www.conf"
fi
if [ -d "/etc/php/${VVV_BASE_PHPVERSION}/fpm/conf.d" ]; then
cp -f "/srv/config/php-config/php-custom.ini" "/etc/php/${VVV_BASE_PHPVERSION}/fpm/conf.d/php-custom.ini"
vvv_php_set_version_file "/etc/php/${VVV_BASE_PHPVERSION}/fpm/conf.d/php-custom.ini"
fi
fi

Expand Down Expand Up @@ -130,6 +133,7 @@ vvv_add_hook services_restart phpfpm_services_restart
function php_nginx_upstream() {
vvv_info " * Copying /srv/config/php-config/upstream.conf to /etc/nginx/upstreams/php${VVV_BASE_PHPVERSION//.}.conf"
cp -f "/srv/config/php-config/upstream.conf" "/etc/nginx/upstreams/php${VVV_BASE_PHPVERSION//.}.conf"
vvv_php_set_version_file "/etc/nginx/upstreams/php${VVV_BASE_PHPVERSION//.}.conf"
}
vvv_add_hook nginx_upstreams php_nginx_upstream

Expand Down
6 changes: 6 additions & 0 deletions provision/provision-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ vvv_is_apt_pkg_installed() {
return 1
}

# @description change a placeholder text with a custom php version
vvv_php_set_version_file() {
phpversion=$(get_php_version.sh)
sed -i "s/VVV_PHP_VERSION/$phpversion/" "$1"
}

# @description cleans up dpkg lock files to avoid provisioning issues
# based on a fix from https://github.com/Varying-Vagrant-Vagrants/VVV/issues/2150
vvv_cleanup_dpkg_locks() {
Expand Down