Viewed   87 times

I have two projects on the local server, one project is running PHP5.6 and the other one is running PHP7.0. Now would it be possible to enable this two versions based on the projects? I already tried adding AddHandler application/x-httpd-php7 .php in one of the project htaccess but its not working. Currently, PHP7.0 and PHP5.6-fpm already installed on the server. Below is the screenshot of the phpinfo.

 Answers

5

So after searching on Google for the whole day. I managed to run my two projects in FastCgi on different php versions. Thanks to the guys from this forum. I uninstalled everything including Apache and start over again. Below are the steps I used to enable two versions of PHP on my local server. Btw, my computer is running on Linux Mint 18.

  1. Assuming you already installed Apache, created virtual host for the two projects and added the necessary php PPAs. Let's call the projects site56.local for PHP 5.6 and site70.local for PHP 7.0. Install php5.6-fpm and php7.0-fpm by running:

    sudo apt-get install php5.6-fpm
    sudo apt-get install php7.0-fpm
    
  2. Create two files under /usr/lib/cgi-bin/ (honestly I don't know if this step is still necessary), and save:

    sudo nano /usr/lib/cgi-bin/php56-fcgi
    sudo nano /usr/lib/cgi-bin/php70-fcgi
    
  3. Open php56 conf file /etc/apache2/conf-available/php5.6-fpm.conf, add this config and save:

    <IfModule mod_fastcgi.c>
        AddHandler php56-fcgi .php
        Action php56-fcgi /php56-fcgi
        Alias /php56-fcgi /usr/lib/cgi-bin/php56-fcgi -socket /var/run/php/php5.6-fpm.sock -pass-header Authorization
        Action php70-fcgi /php70-fcgi
        Alias /php70-fcgi /usr/lib/cgi-bin/php70-fcgi -socket /var/run/php/php7.0-fpm.sock -pass-header Authorization
    </IfModule>
    <Directory /usr/lib/cgi-bin>
        Require all granted
    </Directory>
    
  4. Now enable the new apache config:

    sudo a2enconf php5.6-fpm
    
  5. If you installed php5.6 and php5.7, make sure you disable this two and restart apache:

    sudo a2dismod php5.6 php7.0
    sudo systemctl restart apache2
    
  6. Create a .htacces file on the project that should run on php7.0 and add this handler:

    AddHandler php70-fcgi .php
    
  7. Now create a phpinfo file on the two projects and if you see something like this, then congratulations!

PS: Make sure you enable htaccess in your apache2.conf or httpd.conf

site56.local/phpinfo.php:

site70.local/phpinfo.php:

Sunday, November 13, 2022
5

As was determined in the comments above, this was caused by an environmental difference - the HOME env var was set differently inside the executed process. Using proc_open instead of simple exec gave more precise control over said process and explicitly setting that env var solved the issue.

Saturday, October 8, 2022
2

You can make a .htaccess file and enter Options -Indexes this will disable listing of the files in the directory.

If you also need the traffic to originate from your site you will need to make a file say... index.php with code that checks $_SERVER['HTTP_REFERER'] to see if the traffic originates from your site.

EDIT

Oh I forgot you can actually fix it all in the .htaccess:

Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://your-host.com/.*$ [NC]
RewriteRule ^.* /403-page [L,R]

This will do all the work of the script I suggested, so you won't need it anymore.

Friday, August 19, 2022
 
jonosma
 
3

It took me a while to figure out what to do but at the end I found an easy solution :

sudo apt-get install php5.6-fpm

sudo apt-get install php7.0-fpm

sudo a2enconf php5.6-fpm

If you installed php5.6 and php5.7, make sure you disable this two and restart apache.

sudo a2dismod php5.6 php7.0

sudo systemctl restart apache2

At this point all of your sites must work on php 5.6.

For the sites who need php 7, add this line in the vhost :

ProxyPassMatch "^/(.*.php(/.*)?)$" "unix:/var/run/php/php7.0-fpm.sock|fcgi://localhost/path/to/my/main/file"

It should do the trick :)

Sunday, December 4, 2022
 
2

My first remark would be to check that the cookies had the good domain and thus that both apps received them and use the same session. It appears you already checked that and that that is okay.

Now, to determine which user is currently logged in, CWebUser looks for a [some prefix]__id variable in the session. That prefix can either be the CWebUser->stateKeyPrefix or, if empty, an MD5 based on the class name and the Yii application ID.

The Yii application ID in its turn is either specified by the CApplication->id property, or generated based on the base path of the application.

So the simplest way would be to add the same application ID to both your apps, it should then be able to use the same cookie voor both applications and will "detect the logged in user".

Just edit your configuration and add an "id" at the highest level for both your applications:

return array
(
    'id' => 'sharedApplicationId',

    'components' => array( ... ), 
);

This will result in Yii::app()->id returning the same ID, which will make CWebUser::getStateKeyPrefix() generate the same prefix and presto, both applications will find the __id variable in the session.

Alternatively, you can just configure the state key prefix for CWebUser via the configuration:

return array
(
    ...
    'components' => array
    (
       'user' => array
       (
          'stateKeyPrefix' => 'some_shared_prefix',
          ...
       ),
    ),
 );

This will only affect the CWebUser class then. It will then look for session variables like "some_shared_prefix__id" to determine the logged in user instead and not use the application ID. Either way should work.

So basically, even though you are sharing the database (and the sessions), if the prefix CWebUser ends up using differs because of a "bad" configuration, you'll just have application1StateKeyPrefix__id and application2StateKeyPrefix__id in the session and they won't see each others' logged in user.

Monday, October 31, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :