How to config the PHP path


(Xunpeng) #1

I think something like this:




return[

  ['php' => '/usr/local/php7.1/bin/php']

]



Thanks.

Peng


(Alexander Makarov) #2

Please be more specific about what do you want to achieve.


(Xunpeng) #3

My domain is hosted in a virtual server (linux Debian) with root access, no shared enviroment really.

I have installed Yii 2.0.11 advanced with composer and initiated it to the production enviroment. When the webRoot is called, it shown the following erros:


Warning: require(/home/www/ ... /frontend/web/../../vendor/autoload.php): failed to open stream: No such file or directory in /home/www/ ... /frontend/web/index.php on line 5




Fatal error: require(): Failed opening required '/home/www/ ... /frontend/web/../../vendor/autoload.php' (include_path='.:/usr/local/php7.1/lib/php') in /home/www/ .../frontend/web/index.php on line 5

The reason might be:

The server has more PHPs installed and provides different versions in consol(bash) and using scripts.

Alrough I set the PHP to 5.5 or 7.1 in the Controll Panel, the PHP version on the consol is always 5.3.29.

The installation and initiation were not able with PHP 5.3.29, so I had to used:


/usr/local/php7.1/bin/php

to make the processes.

If the path of PHP in Yii2 could be set by config to php7.1 , the problem might be solved.

By the way, the Yii 2.0.7 doesn’t have this problem on the same server.

Screen shoot:

  1. php version

...:~$ php -v

PHP 5.3.29 (cli) (built: Dec 29 2016 12:22:19)

Copyright (c) 1997-2014 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies

In yii2, the php version is 7.1, I have used phpinfo() to confirm it within the SiteController.

  1. root folders

bin  boot  clamav  ctrl  dev  etc  home  lib  lib32  lib64  media  mnt  opt  proc  sbin  selinux  services  srv  start  sys  tmp  usr  var



  1. local/ folders

bin       ei                   games    imagemagick         man           openssl   php5.3-old  php5.6    php7-old      python-3.5  stunnel  Zend5

bzr       etc                  git      include             memcached     php4      php5.4      php5.7    pngquant      ruby-2.2    tmp

c-client  ffmpeg-2.7.2         hg       instantclient_12_1  nodejs        php4-old  php5.4-old  php5-old  python-2.7    sbin        varnish

clamav    ffmpeg-2.7.2.tar.gz  hosting  lib                 nodejs-0.6.8  php5      php5.5      php7      python-2.7.2  share       wget

curl      frontpage            icu      libpq               nodejs4       php5.3    php5.5-old  php7.1    python-3.2.2  src         Zend4



  1. php7.1 folders:

bin  etc  include  lib  php  var



The same error occured if using php7 or php5.5.

Nobody in the hosting company could solve the problem with the php versions.

Thanks in advance.

Peng


(Xunpeng) #4

I think the requeirements are OK:

consol:


... $ /usr/local/php7.1/bin/php requirements.php

Yii Application Requirement Checker

This script checks if your server configuration meets the requirements

for running Yii application.

It checks if the server is running the right version of PHP,

if appropriate PHP extensions have been loaded, and if php.ini file settings are correct.

Check conclusion:


PHP version: OK

Reflection extension: OK

PCRE extension: OK

SPL extension: OK

Ctype extension: OK

MBString extension: OK

OpenSSL extension: OK

Intl extension: OK

ICU version: OK

ICU Data version: OK

Fileinfo extension: OK

DOM extension: OK

PDO extension: OK

PDO SQLite extension: OK

PDO MySQL extension: OK

PDO PostgreSQL extension: OK

Memcache extension: WARNING!!!

Required by: MemCache

APC extension: WARNING!!!

Required by: ApcCache

GD PHP extension with FreeType support: OK

ImageMagick PHP extension with PNG support: WARNING!!!

Required by: Captcha

Memo: Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required for image CAPTCHA.

Expose PHP: WARNING!!!

Required by: Security reasons

Memo: "expose_php" should be disabled at php.ini

PHP allow url include: OK

PHP mail SMTP: OK


Errors: 0 Warnings: 4 Total checks: 23


(Xunpeng) #5

run it on the consol wite PHP7.1, OK:


... :~/www/ ... /frontend/web$ /usr/local/php7.1/bin/php index.php

<!DOCTYPE html>

<html lang="en-US">

<head>

&lt;meta charset=&quot;UTF-8&quot;&gt;


&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;


&lt;meta name=&quot;csrf-param&quot; content=&quot;_csrf-frontend&quot;&gt;


&lt;meta name=&quot;csrf-token&quot; content=&quot;U1dnSGJfR2FhYAkxFmwtLyVnUz8mJi0.PGcRPzYTcBYFZ1QADGYAUQ==&quot;&gt;


&lt;title&gt;My Yii Application&lt;/title&gt;


&lt;link href=&quot;./assets/222c5bd/css/bootstrap.css&quot; rel=&quot;stylesheet&quot;&gt;

<link href="./css/site.css" rel="stylesheet"></head>

<body>

<div class="wrap">

&lt;nav id=&quot;w0&quot; class=&quot;navbar-inverse navbar-fixed-top navbar&quot; role=&quot;navigation&quot;&gt;&lt;div class=&quot;container&quot;&gt;&lt;div class=&quot;navbar-header&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;navbar-toggle&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#w0-collapse&quot;&gt;&lt;span class=&quot;sr-only&quot;&gt;Toggle navigation&lt;/span&gt;

<span class="icon-bar"></span>

<span class="icon-bar"></span>

<span class="icon-bar"></span></button><a class="navbar-brand" href="index.php">My Company</a></div><div id="w0-collapse" class="collapse navbar-collapse"><ul id="w1" class="navbar-nav navbar-right nav"><li class="active"><a href="index.php?r=site%2Findex">Home</a></li>

<li><a href="index.php?r=site%2Fabout">About</a></li>

<li><a href="index.php?r=site%2Fcontact">Contact</a></li>

<li><a href="index.php?r=site%2Fsignup">Signup</a></li>

<li><a href="index.php?r=site%2Flogin">Login</a></li></ul></div></div></nav>

&lt;div class=&quot;container&quot;&gt;


                    &lt;div class=&quot;site-index&quot;&gt;





&lt;div class=&quot;jumbotron&quot;&gt;


    &lt;h1&gt;Congratulations&#33;&lt;/h1&gt;





    &lt;p class=&quot;lead&quot;&gt;You have successfully created your Yii-powered application.&lt;/p&gt;





    &lt;p&gt;&lt;a class=&quot;btn btn-lg btn-success&quot; href=&quot;http://www.yiiframework.com&quot;&gt;Get started with Yii&lt;/a&gt;&lt;/p&gt;


&lt;/div&gt;





&lt;div class=&quot;body-content&quot;&gt;





    &lt;div class=&quot;row&quot;&gt;


        &lt;div class=&quot;col-lg-4&quot;&gt;


            &lt;h2&gt;Heading&lt;/h2&gt;





            &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et


                dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip


                ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu


                fugiat nulla pariatur.&lt;/p&gt;





            &lt;p&gt;&lt;a class=&quot;btn btn-default&quot; href=&quot;http://www.yiiframework.com/doc/&quot;&gt;Yii Documentation &amp;raquo;&lt;/a&gt;&lt;/p&gt;


        &lt;/div&gt;


        &lt;div class=&quot;col-lg-4&quot;&gt;


            &lt;h2&gt;Heading&lt;/h2&gt;





            &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et


                dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip


                ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu


                fugiat nulla pariatur.&lt;/p&gt;





            &lt;p&gt;&lt;a class=&quot;btn btn-default&quot; href=&quot;http://www.yiiframework.com/forum/&quot;&gt;Yii Forum &amp;raquo;&lt;/a&gt;&lt;/p&gt;


        &lt;/div&gt;


        &lt;div class=&quot;col-lg-4&quot;&gt;


            &lt;h2&gt;Heading&lt;/h2&gt;





            &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et


                dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip


                ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu


                fugiat nulla pariatur.&lt;/p&gt;





            &lt;p&gt;&lt;a class=&quot;btn btn-default&quot; href=&quot;http://www.yiiframework.com/extensions/&quot;&gt;Yii Extensions &amp;raquo;&lt;/a&gt;&lt;/p&gt;


        &lt;/div&gt;


    &lt;/div&gt;





&lt;/div&gt;

</div>

&lt;/div&gt;

</div>

<footer class="footer">

&lt;div class=&quot;container&quot;&gt;


    &lt;p class=&quot;pull-left&quot;&gt;&amp;copy; My Company 2017&lt;/p&gt;





    &lt;p class=&quot;pull-right&quot;&gt;Powered by &lt;a href=&quot;http://www.yiiframework.com/&quot; rel=&quot;external&quot;&gt;Yii Framework&lt;/a&gt;&lt;/p&gt;


&lt;/div&gt;

</footer>

<script src="./assets/7b02cf58/jquery.js"></script>

<script src="./assets/797f765e/yii.js"></script>

<script src="./assets/222c5bd/js/bootstrap.js"></script></body>

</html>


(Xunpeng) #6

with php5.3.29:


  ...  :~/www/ ... /frontend/web$ php index.php

Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /home/www/ … /frontend/web/index.php on line 17


(Alexander Makarov) #7

Yii 2 requires at least PHP 5.4 so it’s expected to fail with 5.3. If you’re not using PHP 5.3 then I’d suggest replacing binary with a symlink to PHP 7.1.


(Xunpeng) #8

Is there no chance to config php version to be used within Yii2?


(Xunpeng) #9

I made:


alias php='/usr/local/php7.1/bin/php'

but no effect.


(Xunpeng) #10

I would say that is a bug:

see:


(Alexander Makarov) #11

Sorry, I have no idea why it fails. There were no related changes since 2.0.7 as far as I know. If you’ll find out a reason, please report it to issue tracker. Thanks.


(Ganesh Patel) #13

try composer update