How to change what PHP version Apache uses? - php

I'm trying to install PHP7 alongside PHP7.4 on my Ubuntu 20.04 server and make Apache use the former. Here's what I tried so far:
Installed PHP 7.0
sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt install php7.0
Changed the defaults
sudo update-alternatives --set php /usr/bin/php7.0
sudo a2dismod php7.4
sudo a2enmod php7.0
Restarted Apache
sudo systemctl restart apache2
I even rebooted the machine a couple times, but when I open the phpinfo() page on my browser, it still shows I'm on 7.4.24. Via CLI however it seems to work fine.
What step did I miss to make Apache use PHP7.0?

Related

PHPMYADMIN Blank Page

I install vesta control panel on my ubuntu EC2 instance on AWS. By default vesta uses php 7.3 but my script demands php 5.6. So i had to downgrade my php version from and followed below method:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.6
php -v
--This may show your old version.
--So now to switching the versions 7.0 > 5.6
sudo a2dismod php7.0
sudo a2enmod php5.6
sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php5.6
--Basically need to install few modules first
sudo apt-get install php5.6-mysql php-gettext php5.6-mbstring php-xdebug libapache2-mod-php5.6
--enabling your required extensions example >>> sudo phpenmod mbstring
sudo apt-get update
sudo update-alternatives --set php /usr/bin/php5.6
sudo service apache2 restart
https://forum.vestacp.com/viewtopic.php?t=6898
After PHP 5.6 is running fine but my phpmyadmin is showing blank page. I tried many online solutions but i couldn't resolve it.

Change version from php 7.0 to 7.1 not working

I have recently change my php version 7.0 to 7.1
I tried
sudo apt-add-repository ppa:ondrej/php
sudo apt install php7.1
sudo a2dismod php7.0
sudo a2enmod php7.1
sudo apt-get install php7.1-xml
Then when i hit localhost/projectname nothing will displays.. and when u hit http://localhost/phpmyadmin/ got
phpMyAdmin - Error The mbstring extension is missing. Please check
your PHP configuration.
then i tried
sudo apt-get install php-mbstring
Nothing change.
finally
sudo service apache2 restart
No change..even i didn't get my project which is worked before.
please help me
Follow list of commands
sudo apt-get install php7.1-mbstring; #version specific mbstring
sudo apt install php7.1-mcrypt;
sudo systemctl restart apache2;
sudo phpenmod mcrypt; #enable mcrypt
sudo phpenmod mbstring; #enable mbstring
sudo systemctl restart apache2;
Caution when you switch version on ubuntu, it automatically removes some version specific extensions. You again have to explicitly
install and enable it
Please try:
sudo apt-get install php7.1-mbstring
sudo service apache2 restart
Hope it helps.

How to switch between PHP 5.6 / 7.2 on Cloud9?

I use AWS Cloud9 Amazon Web Services a.k.a. Cloud9 IDE. I’m trying to achieve a setup where I can easily switch the frontend (not CLI) PHP version with PHPBrew between 5.6 and 7 whenever. For now, I’ve only achieved that the bash has the 5.6.31, the frontend phpinfo() says PHP Version 5.5.9-1ubuntu4.17 which is obviously something I don’t want to see. I’ve already managed to do this on another workspace where it says PHP Version 5.6.31, but I’m afraid to touch that workspace to venture into trying to switch to PHP 7. I have no idea how I achieved to make the PHPBrew version the system level PHP…
I’ve read the related topics and questions but they aren’t helping me. This is how I set it up for now:
curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew
sudo mv phpbrew /usr/local/bin/phpbrew
phpbrew -v
phpbrew init
echo '[[ -e /home/ubuntu/.phpbrew/bashrc ]] && source /home/ubuntu/.phpbrew/bashrc' >> ~/.bashrc
sudo apt-get update
sudo apt-get install apache2-dev
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libmcrypt-dev libreadline-dev
sudo phpbrew install php-5.6.31 +default +dbs +mb +iconv +apxs2=/usr/bin/apxs2
Please note that I have no earthly idea what I’m doing, I never used Linux. I just collected these lines from threads like this and they looked promising, but I must be missing something.
Additional info (requested in comments):
$ cat /etc/apache2/mods-available/php5.load
LoadModule php5_module /usr/lib/apache2/modules/libphp5.6.31.so
$ phpbrew list
* php-5.6.31
I'd ideally switch with phpbrew switch after I have both 5.6.31 and 7 installed. For now, I'd be satisfied if I could just get it to work with 5.6.31
For now, what I did was to switch the "runner" (not sure what that is) from PHP (built-in web server) to Apache httpd (PHP, HTML) here: https://i.snag.gy/Y6eNHy.jpg Then the phpinfo() was actually showing the phpbrew version. Then I also installed PHP 7.2.1 but then everything stopped working. I get lots of errors in the console of c9: https://i.snag.gy/pt5oHN.jpg Beautiful, isn't it? :)
Started apache2
/mnt/shared/bin/run-apache2: line 70: 4813 Segmentation fault apache2
I've completely ditched phpbrew as it's not really for switching Apache's PHP, just CLI (by design). It was never supposed to work, see: this is still a feature request.
Started with a clean Cloud9 PHP/Apache workspace. I followed this article How to Install PHP 5.6, PHP 7.1 on Ubuntu 16.04, 14.04 using PPA and based on that, this is how it turned out:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.6
sudo apt-get install -y php7.2
Then verify:
php5.6 -v
php7.2 -v
I ran into an error after installing php7.2:
$ php7.2 -v
php7.2: symbol lookup error: php7.2: undefined symbol: pcre_jit_exec
That I fixed following the advice "Upgrade your libpcre3 library to version from the repository."
Turns out that was "kept back" so I had to do this:
apt-get install libpcre3 libpcre3-dev
PHP 7.2 started to work! Surprisingly, Cloud9's original PHP is left intact, that lives on under php5 and can be used anytime. So I can now juggle 3 different versions. Yes, phpinfo() shows the version I want every time! Re-running the Cloud9 worker is not even necessary.
The mbstring will be missing for 5.6 (ran into the problem when running phpmyadmin):
sudo apt-get install php5.6-mbstring
The php.ini files are located at:
sudo find . -name 'php.ini'
./php/7.2/apache2/php.ini
./php/7.2/cli/php.ini
./php/5.6/apache2/php.ini
./php/5.6/cli/php.ini
./php5/fpm/php.ini
./php5/apache2/php.ini
./php5/cli/php.ini
Switch from anything to 7.2 PHP
sudo a2dismod php5
sudo a2dismod php5.6
sudo a2enmod php7.2
sudo service apache2 restart
With 1 line:
sudo a2dismod php5 && sudo a2dismod php5.6 && sudo a2enmod php7.2 && sudo service apache2 restart
Switch from anything to 5.6 PHP
sudo a2dismod php5
sudo a2dismod php7.2
sudo a2enmod php5.6
sudo service apache2 restart
With 1 line:
sudo a2dismod php5 && sudo a2dismod php7.2 && sudo a2enmod php5.6 && sudo service apache2 restart
Switch from anything to original PHP from Cloud9
sudo a2dismod php7.2
sudo a2dismod php5.6
sudo a2enmod php5
sudo service apache2 restart
With 1 line:
sudo a2dismod php7.2 && sudo a2dismod php5.6 && sudo a2enmod php5 && sudo service apache2 restart
Now I'm very happy.
// PHP version upgrade (from 5.6 to 7.2)
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update -y
sudo apt-get install php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml -y
sudo mv /etc/apache2/envvars /etc/apache2/envvars.bak
sudo apt-get remove libapache2-mod-php5 -y
sudo apt-get install libapache2-mod-php7.2 -y
sudo cp /etc/apache2/envvars.bak /etc/apache2/envvars
sudo a2dismod php5
sudo a2enmod php7.2
sudo service apache2
sudo service apache2 restart
The following will upgrade to PHP 7.2 on CLoud9:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt-get update -y
sudo apt-get install php7.2 php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml
sudo apt-get install libapache2-mod-php7.2 -y
sudo a2dismod php5
sudo a2enmod php7.2
sudo service apache2 restart
Source: How to upgrade PHP to 7.2 on ubuntu?
You Can do it via .htaccess file by adding a simle lines below:
To switch to PHP 4.4:
AddHandler application/x-httpd-php4 .php
To switch to PHP 5.0:
AddHandler application/x-httpd-php5 .php
To switch to PHP 5.1:
AddHandler application/x-httpd-php51 .php
To switch to PHP 5.2:
AddHandler application/x-httpd-php52 .php
To switch to PHP 5.3:
AddHandler application/x-httpd-php53 .php
To switch to PHP 5.4:
AddHandler application/x-httpd-php54 .php
To switch to PHP 5.5:
AddHandler application/x-httpd-php55 .php
To switch to PHP 5.6:
AddHandler application/x-httpd-php56 .php
To switch to PHP 7:
AddHandler application/x-httpd-php7 .php
To switch to PHP 7.1:
AddHandler application/x-httpd-php71 .php

Add PHP version to lampp

i have a lampp stack on my Ubuntu 14.04 machine. It was installed from an apachefriends.org installer ages ago. As i can see in the binaries it has 2 PHP versions already installed with just a symlink for the actual php. Now i want to add a new PHP version (and keep the ones installed), in this case some 7.x on top of 5.x that are already present.
I think i could download and build/configure PHP but actually i have no idea how it would integrate into lampp with the existing versions. Particularly extensions, and possibly different config files. Would they use the same? Is it possible anyway?
For Ubuntu, follow:
Add PPA:
sudo add-apt-repository ppa:ondrej/php;
sudo apt-get update;
sudo apt-get upgrade;
Install Apache & MySQL (if not already installed):
sudo apt-get install apache2 mysql-server php-gettext php-xdebug;
Install PHP5.6 (if not already installed):
sudo apt-get install php5.6 php5.6-mysql php5.6-mbstring libapache2-mod-php5.6;
Install PHP7.1 (if not already installed):
sudo apt-get install php7.1 php7.1-mysql php7.1-mbstring libapache2-mod-php7.1;
Switching between PHP versions (via commands a2enmod & a2dismod):
Switch PHP Versions (7.1->5.6):
sudo a2dismod php7.1; sudo a2enmod php5.6; sudo service apache2 restart;
Switch PHP Versions (5.6->7.1):
sudo a2enmod php7.1; sudo a2dismod php5.6; sudo service apache2 restart;

phpMyAdmin - Error : (The mysqli extension is missing) after upgrading php 5.6 to php 7

I have a problem with phpmyadmin on ubuntu 16.04 after upgrading php 5.6 to php 7 by this way:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
after this command :
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
phpMyadmin has error :
The mysqli extension is missing. Please check your PHP configuration.
But it does not have error on php5.
I want use phpMyadmin on php7.
Can anyone help me?
You need to do following steps.
php --version
Check your php version and run following command.
sudo apt-get install php5.6-mysql
In my case my version of php is 5.6, you may have different. Replace your version and hit enter.
After installing just run
sudo service apache2 restart
Hope it will help
You first need to install php7 , then install php5.
Completely remove your php and phpmyadmin :
sudo dpkg -P phpmyadmin
sudo rm -f /etc/apache2/conf.d/phpmyadmin.conf
sudo service apache2 restart
sudo apt-get purge php.*
sudo service apache2 restart
Install php7 and php7.0-mysql and ... : https://askubuntu.com/a/705893/424146
Install phpmyadmin (on php7) : install phpmyadmin with lamp stack on ubuntu 16.04
Run these commands again to install php5.6 beside your php7:
Install php5.6 beside php7 : (I got help from this link)
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.0 php5.6 php5.6-mysql php-gettext php5.6-mbstring php-mbstring php7.0-mbstring php-xdebug libapache2-mod-php5.6 libapache2-mod-php7.0
sudo service apache2 restart
Switch PHP version:
From php5.6 to php7.0 :
sudo a2dismod php5.6 ; sudo a2enmod php7.0 ; sudo service apache2 restart
From php7.0 to php5.6 :
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
Reinstall or Reconfigure PHPMyAdmin. The following worked for me:
dpkg-reconfigure phpmyadmin
Solution for Windows PC
Try to check to check your httpd-xampp config file.
Make sure the Make sure the Php-Module conform with your current php version.
example here: IfModule php5_module
Based on your migration you are using php7, so edit all the php5_module tag in your config file to php7_module and restart the apache server.

Categories