Robel Tech 🚀

Switch php versions on commandline ubuntu 1604

February 20, 2025

Switch php versions on commandline ubuntu 1604

Managing aggregate PHP variations is a communal demand for net builders, particularly once running with antithetic initiatives oregon bequest purposes. Connected Ubuntu sixteen.04, switching betwixt these variations isn’t conscionable handy—it’s indispensable for sustaining compatibility and leveraging the newest options. This usher supplies a blanket walkthrough of however to effortlessly control PHP variations by way of the bid formation connected Ubuntu sixteen.04, empowering you to streamline your improvement workflow and guarantee optimum show for all task.

Putting in Aggregate PHP Variations

Earlier you tin control betwixt PHP variations, you demand to person them put in. Ubuntu sixteen.04 makes this procedure simple with instruments similar apt. You’ll demand to adhd the due repositories for your desired PHP variations (e.g., PHP 5.6, 7.zero, 7.2, and so on.). This usually includes including PPAs (Individual Bundle Archives) maintained by Ondřej Surý, a famed Debian/Ubuntu bundle maintainer for PHP.

Last including the repositories, you tin instal the desired PHP variations alongside their corresponding extensions. For case, if you privation to instal PHP 7.zero and 7.2, you would usage instructions similar sudo apt-acquire instal php7.zero php7.zero-communal php7.zero-mysql php7.zero-curl and past repetition the procedure substituting 7.2 for 7.zero. This ensures you person each the essential modules for your improvement situation.

The replace-alternate options Bid

The center of PHP interpretation switching connected Ubuntu sixteen.04 lies successful the replace-options bid. This almighty implement manages symbolic hyperlinks, permitting you to designate the most popular interpretation of a bid. Successful the discourse of PHP, replace-options configures which PHP binary and associated modules (similar php-fpm, php-cli) are invoked once you execute PHP instructions.

To configure replace-options for PHP, you usage the --config action. For illustration: sudo replace-options --config php. This bid volition immediate you with a database of put in PHP variations and punctual you to take the default. You tin choice the desired interpretation by getting into its corresponding figure.

Switching PHP-FPM and CLI

Switching PHP variations impacts some the bid-formation interface (CLI) and the FastCGI Procedure Director (FPM), which is generally utilized with net servers similar Nginx and Apache. It’s important to guarantee some the CLI and FPM are aligned with your desired PHP interpretation.

You usage replace-options for php-fpm and associated modules conscionable arsenic you did for the chief PHP binary. For illustration: sudo replace-alternate options --config php-fpm. This ensures your internet server makes use of the accurate PHP interpretation for processing requests. Likewise, configuring the CLI permits you to execute PHP scripts from the bid formation utilizing the chosen interpretation.

Verifying the Progressive PHP Interpretation

Last switching PHP variations, ever confirm the alteration. The easiest manner is to usage the bid php -v. This bid volition output the presently progressive PHP interpretation, confirming that the control was palmy. It’s a bully pattern to tally this bid last all control to debar sudden behaviour successful your initiatives. Treble-checking the PHP interpretation utilized by your net server is besides indispensable. You tin bash this by creating a tiny PHP record (e.g., information.php) containing <?php phpinfo(); ??> and accessing it done your internet browser. This volition show elaborate accusation astir the PHP interpretation moving connected your internet server.

  • Ever confirm the progressive PHP interpretation utilizing php -v last switching.
  • Usage <?php phpinfo(); ??> successful a trial record to cheque the net server’s PHP interpretation.
  1. Adhd the required PHP repositories (PPAs).
  2. Instal the desired PHP variations and extensions utilizing apt.
  3. Usage replace-options --config php to choice the default PHP interpretation.
  4. Configure php-fpm utilizing replace-options.
  5. Confirm the control with php -v and phpinfo().

For a deeper dive into managing PHP variations, mention to the authoritative PHP set up documentation. You tin besides discovery elaborate accusation connected Ubuntu’s PHP activity leaf. Different adjuvant assets is the DigitalOcean tutorial connected putting in aggregate PHP variations.

Switching PHP variations connected Ubuntu sixteen.04 utilizing the bid formation is a cardinal accomplishment for immoderate net developer running with this level. Mastering this method permits you to seamlessly negociate antithetic initiatives with various PHP necessities, guaranteeing compatibility and maximizing show. By pursuing the steps outlined successful this usher, you tin confidently navigate your PHP improvement situation and optimize your workflow.

[Infographic illustrating the procedure of switching PHP variations]

  • PHP Interpretation Direction: Effectual interpretation power is cardinal to palmy PHP improvement.
  • Ubuntu sixteen.04 Server Medication: Knowing server medication is important for managing PHP variations.

Illustration: Ideate you’re running connected a bequest task that requires PHP 5.6, however your capital improvement situation makes use of PHP 7.2. Utilizing replace-alternate options, you tin rapidly control to PHP 5.6 for the bequest task and past control backmost to 7.2 for your another activity with out disrupting both situation. This streamlined attack ensures compatibility and saves invaluable improvement clip. “Appropriate PHP interpretation direction tin importantly better improvement ratio," says Rasmus Lerdorf, creator of PHP.

Mastering the bid-formation attack to PHP interpretation switching empowers you to good-tune your improvement situation in accordance to task wants, making certain creaseless cognition and minimizing compatibility complications. Research our sources to additional heighten your knowing of PHP direction connected Ubuntu sixteen.04 and larn much astir optimizing your improvement workflow.

Often Requested Questions

Q: Tin I instal aggregate PHP variations concurrently?

A: Sure, you tin instal aggregate PHP variations broadside-by-broadside connected Ubuntu sixteen.04. This is dealt with effectively done bundle direction and the replace-alternate options scheme.

Q: What if my net server doesn’t indicate the PHP interpretation alteration?

A: Guarantee you’ve configured php-fpm utilizing replace-options and restart your internet server (e.g., sudo work apache2 restart oregon sudo work nginx restart).

Question & Answer :
I person put in php 5.6 and and php 7.1 connected my Ubuntu sixteen.04

I cognize with Apache arsenic my internet server, I tin bash

a2enmod php5.6 #to change php5 a2enmod php7.1 #to change php7 

Once I disable php7.1 successful Apache modules and change php 5.6, Apache acknowledges the alteration and makes use of php 5.6 interpreter arsenic anticipated.

However once I tally inner php internet server from the commandline:

php -S localhost:8888 

php handles requests utilizing php 7. Truthful however bash I control betwixt php 5.6 and php 7.1 successful the bid formation ?

Interactive switching manner

sudo replace-options --config php sudo replace-options --config phar sudo replace-options --config phar.phar 

Handbook Switching

From PHP 5.6 => PHP 7.1

Default PHP 5.6 is fit connected your scheme and you demand to control to PHP 7.1.

Apache:

$ sudo a2dismod php5.6 $ sudo a2enmod php7.1 $ sudo work apache2 restart 

Bid Formation:

$ sudo replace-alternate options --fit php /usr/bin/php7.1 $ sudo replace-options --fit phar /usr/bin/phar7.1 $ sudo replace-alternate options --fit phar.phar /usr/bin/phar.phar7.1 

From PHP 7.1 => PHP 5.6

Default PHP 7.1 is fit connected your scheme and you demand to control to PHP 5.6.

Apache:

$ sudo a2dismod php7.1 $ sudo a2enmod php5.6 $ sudo work apache2 restart 

Bid Formation:

$ sudo replace-alternate options --fit php /usr/bin/php5.6 

Origin