0

I have two versions of PHP:

macabeus@macabeus-acer ~ $ whereis php
php: /usr/bin/php /usr/bin/X11/php /usr/share/php /opt/php-my-version-7.0/bin/php /usr/share/man/man1/php.1.gz

macabeus@macabeus-acer ~ $ php -v
PHP 5.5.9-1ubuntu4.19 (cli) (built: Jul 28 2016 19:31:33) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies

And, I want to use /opt/php-my-version-7.0/bin/php, but, my system is using the version from /usr/bin/php by default. How to change to my system to use version from /opt/php-my-version-7.0/bin/php by default?

1
  • I also noticed your path for which php is very long. Default path= /usr/bin/php
    – CJ Dana
    Commented Sep 16, 2016 at 4:07

2 Answers 2

1

You can choose which modules of php that may be served by apache
/opt/local/apache2/conf/httpd.conf

This is the global configuration file for apache, apache modules are imported from here.

However
To set the php version for your project, in the main directory's .htaccess
AddHandler application/x-httpd-php7 .php

1

If you are talking about running from the command line it is going to use the first one it finds in $PATH. You can change your $PATH variable so that /opt/php-my-version-7.0/bin appears at the front.

 export PATH=/opt/php-my-version-7.0/bin:$PATH

If you add this line to ~/.profile it will make each new login shell you start run that automatically.

For Apache CGI support (unusual for php) you can set path in /etc/apache2/envvars just add the same line to that file.

If you want Apache to load mod_php from there you will need to change the apache configuration to load that version of the libphp7.so file (assuming you have a version that was built with mod_php support). Look for an example file in your install documentation.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .