KNOWNHOST WIKI

User Tools

Site Tools


control-panels:directadmin:wrong-php-version-detected-using-multiple-php-versions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
control-panels:directadmin:wrong-php-version-detected-using-multiple-php-versions [2020/05/26 11:04]
Karson N.
control-panels:directadmin:wrong-php-version-detected-using-multiple-php-versions [2020/06/01 10:18] (current)
Karson N.
Line 1: Line 1:
 ====== Workaround- Wrong PHP Version Detected by WP-CLI When Using Multiple PHP Versions ====== ====== Workaround- Wrong PHP Version Detected by WP-CLI When Using Multiple PHP Versions ======
- 
 \\ \\
  
Line 10: Line 9:
  
 <code> <code>
-[~]# /usr/local/cpanel/bin/rebuild_phpconf --current +  [~]# /usr/local/cpanel/bin/rebuild_phpconf --current 
-DEFAULT PHP: ea-php55 +  DEFAULT PHP: ea-php55 
-ea-php54 SAPI: suphp +  ea-php54 SAPI: suphp 
-ea-php55 SAPI: suphp +  ea-php55 SAPI: suphp 
-ea-php56 SAPI: suphp +  ea-php56 SAPI: suphp 
-ea-php70 SAPI: suphp +  ea-php70 SAPI: suphp 
-ea-php73 SAPI: suphp +  ea-php73 SAPI: suphp 
-[~]# +  [~]# 
 </code> </code>
  
 I had confirmed that the PHP version assigned to the site was PHP 7.3 like so (which works thanks to the PHPRC patch in cPanel). By changing into the user's (username) DOCROOT for the site and then checking the PHP version in use, I was able to confirm that the PHP version assigned to the site was PHP 7.3 and thus concluded that WP-CLI should work perfectly fine with the site: I had confirmed that the PHP version assigned to the site was PHP 7.3 like so (which works thanks to the PHPRC patch in cPanel). By changing into the user's (username) DOCROOT for the site and then checking the PHP version in use, I was able to confirm that the PHP version assigned to the site was PHP 7.3 and thus concluded that WP-CLI should work perfectly fine with the site:
 +<code>
   cd /home/username/public_html   cd /home/username/public_html
   php -v   php -v
 +</code>
 +
 +For cPanel servers, you could alternatively check the
 +<code>
 +  .htaccess/.user.ini/php.ini
 +</code>
  
-For cPanel servers, you could alternatively check the .htaccess/.user.ini/php.ini files local to the document root for the site. If no PHP version is explicitly specified, then the default PHP version is in use.+files local to the document root for the site. If no PHP version is explicitly specified, then the default PHP version is in use.
  
 Note that these commands are written in a manner that allows the root user to execute WP-CLI as the user via a bash shell but still remain logged in as the root user. Thus, the commands are executed with the proper ownership but do not require you to su to the user for the remaining terminal session.  Note that these commands are written in a manner that allows the root user to execute WP-CLI as the user via a bash shell but still remain logged in as the root user. Thus, the commands are executed with the proper ownership but do not require you to su to the user for the remaining terminal session. 
  
-((https://make.wordpress.org/cli/handbook/config/))[[https://make.wordpress.org/cli/handbook/config/|WP-CLI documentation]] states that you can specify the PHP version to use via an environment variable **only in non-phar installations**.+((https://make.wordpress.org/cli/handbook/config/)) 
 +[[https://make.wordpress.org/cli/handbook/config/|WP-CLI documentation]] 
 +states that you can specify the PHP version to use via an environment variable **only in non-phar installations**.
  
 So, for a non-phar installation of WP-CLI, one could set the env variable on demand just before your command: So, for a non-phar installation of WP-CLI, one could set the env variable on demand just before your command:
 +<code>
   WP_CLI_PHP=/opt/cpanel/ea-php73/root/usr/bin/php   WP_CLI_PHP=/opt/cpanel/ea-php73/root/usr/bin/php
 +</code>
  
 Running as the user 'username' while logged in as root, you would issue the following command (for a non-phar installation): Running as the user 'username' while logged in as root, you would issue the following command (for a non-phar installation):
 +<code>
    su -s /bin/bash -c "WP_CLI_PHP=/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/cpanel/3rdparty/bin/wp --info" username    su -s /bin/bash -c "WP_CLI_PHP=/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/cpanel/3rdparty/bin/wp --info" username
- +</code> 
 This will give output detailing the environment and PHP binary and information used (in which you'll want to pay close attention to the PHP version detected). Note that when ran with a phar installation of WP-CLI that the PHP binary shown is that which you manually specified in the command, however, the PHP used is still that of the default PHP version, PHP 5.5: This will give output detailing the environment and PHP binary and information used (in which you'll want to pay close attention to the PHP version detected). Note that when ran with a phar installation of WP-CLI that the PHP binary shown is that which you manually specified in the command, however, the PHP used is still that of the default PHP version, PHP 5.5:
  
 <code> <code>
-root@host [/home/username/public_html]# su -s /bin/bash -c "WP_CLI_PHP=/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/cpanel/3rdparty/bin/wp --info" username +  root@host [/home/username/public_html]# su -s /bin/bash -c "WP_CLI_PHP=/opt/cpanel/ea-php73/root/usr/bin/php  
-OS: Linux host.domain.tld 3.10.0-957.12.2.vz7.96.21 #1 SMP Thu Jun 27 15:10:55 MSK 2019 x86_64 +  /usr/local/cpanel/3rdparty/bin/wp --info" username 
-Shell: /bin/bash +  OS: Linux host.domain.tld 3.10.0-957.12.2.vz7.96.21 #1 SMP Thu Jun 27 15:10:55 MSK 2019 x86_64 
-PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php +  Shell: /bin/bash 
-PHP version: 5.5.38 +  PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php 
-php.ini used: /opt/cpanel/ea-php55/root/etc/php.ini +  PHP version: 5.5.38 
-WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli +  php.ini used: /opt/cpanel/ea-php55/root/etc/php.ini 
-WP-CLI vendor dir: phar://wp-cli.phar/vendor +  WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli 
-WP_CLI phar path: /home/username/public_html +  WP-CLI vendor dir: phar://wp-cli.phar/vendor 
-WP-CLI packages dir: +  WP_CLI phar path: /home/username/public_html 
-WP-CLI global config: +  WP-CLI packages dir: 
-WP-CLI project config: +  WP-CLI global config: 
-WP-CLI version: 2.1.0 +  WP-CLI project config: 
-root@host [/home/username/public_html]#+  WP-CLI version: 2.1.0 
 +  root@host [/home/username/public_html]#
 </code> </code>
  
Line 61: Line 71:
  
 I found the following, which worked for me for the cPanel server: I found the following, which worked for me for the cPanel server:
 +<code>
    su -s /bin/bash -c "/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --info" username    su -s /bin/bash -c "/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --info" username
 +</code>
  
 For DirectAdmin, you may want to try the following: For DirectAdmin, you may want to try the following:
 +<code>
   su -s /bin/bash -c "/usr/local/php73/bin/php  /usr/local/bin/wp --info" username   su -s /bin/bash -c "/usr/local/php73/bin/php  /usr/local/bin/wp --info" username
 +</code>
  
 Note that the command above was ran for the user //username// inside the user's site document root (/home/username/public_html/  is the default document root for primary domains in cPanel). Note that the command above was ran for the user //username// inside the user's site document root (/home/username/public_html/  is the default document root for primary domains in cPanel).
Line 73: Line 85:
    
 <code> <code>
-root@host [/home/username/public_html]# su -s /bin/bash -c "/opt/cpanel/ea-php73/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --info" username +  root@host [/home/username/public_html]# su -s /bin/bash -c "/opt/cpanel/ea-php73/root/usr/bin/php  
-OS: Linux 3.10.0-957.12.2.vz7.96.21 #1 SMP Thu Jun 27 15:10:55 MSK 2019 x86_64 +  /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --info" username 
-Shell: /bin/bash +  OS: Linux 3.10.0-957.12.2.vz7.96.21 #1 SMP Thu Jun 27 15:10:55 MSK 2019 x86_64 
-PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php +  Shell: /bin/bash 
-PHP version: 7.3.9 +  PHP binary: /opt/cpanel/ea-php73/root/usr/bin/php 
-php.ini used: /opt/cpanel/ea-php73/root/etc/php.ini +  PHP version: 7.3.9 
-WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli +  php.ini used: /opt/cpanel/ea-php73/root/etc/php.ini 
-WP-CLI vendor dir: phar://wp-cli.phar/vendor +  WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli 
-WP_CLI phar path: /home/username/public_html +  WP-CLI vendor dir: phar://wp-cli.phar/vendor 
-WP-CLI packages dir: +  WP_CLI phar path: /home/username/public_html 
-WP-CLI global config: +  WP-CLI packages dir: 
-WP-CLI project config: +  WP-CLI global config: 
-WP-CLI version: 2.1.0 +  WP-CLI project config: 
-root@host [/home/username/public_html]#+  WP-CLI version: 2.1.0 
 +  root@host [/home/username/public_html]#
 </code> </code>
  
Line 92: Line 105:
  
 \\ \\
- 
 ===== Quick Workaround Reference ===== ===== Quick Workaround Reference =====
  
Line 98: Line 110:
  
 \\ \\
- 
 ==== cPanel ==== ==== cPanel ====
  
 From within the site's document root as the user //username// while logged in terminal as root: From within the site's document root as the user //username// while logged in terminal as root:
 +<code>
    su -s /bin/bash -c "/opt/cpanel/ea-phpXX/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --info" username    su -s /bin/bash -c "/opt/cpanel/ea-phpXX/root/usr/bin/php /usr/local/cpanel/3rdparty/share/cpanel-wp-cli/wp-cli.phar --info" username
 +</code>
  
 \\ \\
- 
 ==== DirectAdmin ==== ==== DirectAdmin ====
  
 From within the site's document root as the user //username// while logged in terminal as root: From within the site's document root as the user //username// while logged in terminal as root:
 +<code>
   su -s /bin/bash -c "/usr/local/phpXX/bin/php  /usr/local/bin/wp --info" username   su -s /bin/bash -c "/usr/local/phpXX/bin/php  /usr/local/bin/wp --info" username
 +</code>
  
control-panels/directadmin/wrong-php-version-detected-using-multiple-php-versions.txt · Last modified: 2020/06/01 10:18 by Karson N.