Can't enable php as apache2 module - php

During Ubuntu server setup, I got to the point where I need to enable php as apache2 module. I tried running sudo a2enmod php5, but it returned ERROR: Module php5 does not exist!
After a bit of searching, I stumbled upon this tip by gerard :
If sudo a2enmod php5 returns "$ This module does not exist!", you should purge (not just remove) the libapache2-mod-php5 package and reinstall it.
Be sure to clear your browser's cache before testing your site again."
Running sudo apt-get --purge remove libapache2-mod-php5 however, returned Package libapache2-mod-php5 is not installed, so not removed . Naturally, I tried to install it with sudo apt-get install libapache2-mod-php5, but then I get :
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies.
libapache2-mod-php5 : Depends: libxml2 (>= 2.8.0) but 2.7.8.dfsg-5.1ubuntu4.6 is to be installed
Recommends: php5-cli but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
I tried to update && upgrade in hopes libxml2 would get updated, but didn't happen. I also tried installing php5-cli, but got :
The following packages have unmet dependencies.
php5-cli : Depends: libxml2 (>= 2.8.0) but 2.7.8.dfsg-5.1ubuntu4.6 is to be installed
Depends: libedit2 (>= 2.11-20080614-4) but 2.11-20080614-3ubuntu2 is to be installed
E: Unable to correct problems, you have held broken packages.
At this point I am lost. Running php -v, indicates that php is running, however:
PHP 5.4.17 (cli) (built: Aug 7 2013 11:40:38)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

You can't install PHP 5.4.17 under Ubuntu 12.04, because the required libxml2 library >= v2.8.0 is only available in Ubuntu 12.10 (Quantal quetzal) or higher.
Solution: Get a newer version of Ubuntu.

oh no! You must use
aptitude -y install php5 libapache2-mod-php5 php5-mysql php5-gd
to install php5 with apache.
libapache2-mod-php5 is a module of apache, but you have to install php5 to compile php code

Related

Moodle can't detect my php version

i've installed moodle from github. I'm using php5, then i can't install it.
So, i'm upgrade my php to php7.1, but still error. The error message like this : Moodle 3.4 or later requires at least PHP 7.0.0 (currently using version 5.6.26-1). Some servers may have multiple PHP versions installed, are you using the correct executable?
My php version : PHP 7.1.6-2 (cli) (built: Jun 14 2017 05:31:31) ( NTS )
Can anyone help me?
Your php7 version looks to be the php-cli version and is not the one used by your http server (apache or other) : display a phpinfo(); in your browser.
It looks like you are using debian, first remove php5 : apt-get remove php5* libapache2-mod-php5 and install the 7 version, something like :
apt-get install apache2 php7.0 libapache2-mod-php7.0 php7.0-cli php7.0-zip php7.0-intl php7.0-common php7.0-curl php7.0-imagick php7.0-gd php7.0-json php7.0-ldap php7.0-mcrypt php7.0-memcache php7.0-memcached php7.0-mysql php7.0-pgsql php7.0-readline php7.0-bcmath php7.0-mbstring php7.0-xml
Moodle has no concern with this.
I had the same problem. After upgrading xampp, my problem has solved.

Downgrade from PHP 7 to PHP 5.6 on apache server

I just recently launched LAMP version 7.0 using bitnami on google app engine.
I couldn't find the older version of 5.6.
Any idea how i can downgrade the default PHP 7 to PHP 5.6 on my server
upon running this commandphp --version
i get this output
PHP 7.0.22 (cli) (built: Sep 6 2017 14:14:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.22, Copyright (c) 1999-2017, by Zend Technologies
kindly note that i have also installed PHP 5 using sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
but the dafault PHP version remains PHP 7.0.22
It is possible just to install the version of php you need. and change the set-up.
ssh into your VM from your console or
gcloud compute ssh [INSTANCE NAME] --ZONE [INSTANCE ZONE]
Inside your VM do:
If add-apt-repository is not installed
sudo apt-get install software-properties-common python-software-properties
then:
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install 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
Apache:
sudo a2dismod php7.0 ; sudo a2enmod php5.6 ; sudo service apache2 restart
CLI:
sudo update-alternatives --set php /usr/bin/php5.6
Bitnami Stacks are self-contained. That means that they include every component they need (e.g. Apache, PHP, PHP-FPM, MySQL, etc.).
Those components are not installed using the System Package Manager of the Distro (e.g. yum on Centos or apt on Debian). Therefore, if you install a different version of PHP on your Image, you'll have two different PHPs installed. The one in the system and the one in the Stack. However, every component included in the Stack will use the PHP included in the Stack (no matter what version you installed in the system).
You can find the PHP in the LAMP Stack at /opt/bitnami/php. If you want to use PHP 5.X you have several options:
A. Download and install the LAMP Stack with PHP 5.6.x from https://bitnami.com/stack/lamp/installer on your server. After that, remove the previous LAMP Stack with PHP 7.
B. Install PHP using the System Package Manager. Then, modify the environment to remove /opt/bitnami/php from the PATH and also edit the file /opt/bitnami/scristps/setenv.sh to avoid including /opt/bitnami/php again in the PATH.

How to Install Php5.6 in amazon linux

I'm trying to install php 5.6 on Amazon linux using the following command:
$ yum install php56
No package php56 available.
Error: Nothing to do
Is there a repository I need to add in order to do this? I've searched for this but couldn't find any source. I'd also like to know which Apache versions work with this version of php?
Below are the steps I have used to update PHP version from 5.3 to 5.6 in Amazon Linux
Steps (Use sudo only if required)
1) Remove OLD Apache
sudo service httpd stop
sudo yum erase httpd httpd-tools apr apr-util
2) Remove OLD PHP
sudo yum remove php-*
3) Install PHP 5.6 (Apache 2.4 will be automatically installed with this)
sudo yum install php56
4) Make sure all the required PHP extensions are installed
yum list installed | grep php
5) If not then install them using
sudo yum install php56-xml php56-xmlrpc php56-soap php56-gd
6) To list the other available php extensions
yum search php56
7) PHP 5.6 MySQL extension (Assume you have already installed MySQL)
sudo yum install php56-mysqlnd
(NOTE: it is not php56-mysql)
8) Start / Restart Apache
sudo service httpd start
sudo service httpd restart
9) Check the version
php -v
httpd -v
AWS has not yet packaged php 5.6. You need to install php 5.5 from the ALAMI repositories, or build 5.6 from source.
To list the available 5.5 packages use yum search php55
The php55 is the base package, but you may need others listed as well.
When 5.6 is ready, you'll be able to find it with
yum search php56
You can find information on building the source at php.net, specifically Installation on Unix Systems / Apache 2.x on Unix Systems
Just to mantain update the answers,
I tryed the proposed solution and didn't work.
Quite hard to install 5.6
I found the right command nowaday to install 7.2 is
amazon-linux-extras install php7.2
it install and upgrade everything without complications.
Try this:
sudo yum -y update
sudo yum install –y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo wget https://centos7.iuscommunity.org/ius-release.rpm
sudo rpm -Uvh ius-release*.rpm
sudo yum -y update
When you install the package you'll need to add a u to the end of php56. Here is an example of some packages you could install.
sudo yum -y install php56u php56u-opcache php56u-xml \
php56u-mcrypt php56u-gd php56u-devel php56u-mysql \
php56u-intl php56u-mbstring php56u-bcmath php56u-soap
Successfully installed php56 and required php-module on amazonlinux2 with the repo epo.ius.io.
sudo yum -y update
sudo yum install –y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://repo.ius.io/ius-release-el7.rpm
sudo rpm -Uvh ius-release*.rpm
sudo yum -y update
sudo yum install --enablerepo=ius-archive php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath php56u-soap
Check PHP version with below command
[root#ip-10-10-1-47 ~]# php -v
PHP 5.6.40 (cli) (built: Jan 11 2019 10:27:04)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
To install php module
yum install --enablerepo=ius-archive php56u-{Module Name}
Validate the module name
php -m
php -m | grep {Module Name}
example to check php yaml module
php -m | grep yaml
Reference URL : https://forums.aws.amazon.com/thread.jspa?threadID=284157
Additional part from #Daniele post for resloving this problem.
This is more help than question, but to help other with problem which I had in my case. I need to install Wordpress site on EC2, but when I tried to run it with public IP address, it was problem. I tried to install php 5.6, but it was not possible.
I find solution to install php 7.2, using command:
**amazon-linux-extras install php7.2**
TO check that is really version php 7.2, use:
php -version or php -v
After this, you need to stop apache service, command for stop is:
service httpd stop
Start again apache service:
service httpd start
In your AWS console, go to Instance, find public IP address, copy and open in browser. You should see the WordPress page. You can install WordPress in Advanced part (bootstraping), when you create EC2 instance.

Upgrading PHP on CentOS 6.5 (Final)

I'm trying to update my PHP (currently v:5.3.3 to the latest stable PHP build) but it's not playing ball and it's saying there is nothing to update.
Any help would be useful.
Keeps saying:
No Packages marked for Update
As Jacob mentioned, the CentOS packages repo appears to only have PHP 5.3 available at the moment. But these commands seemed to work for me...
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
yum remove php-common # Need to remove this, otherwise it conflicts
yum install php56w
yum install php56w-mysql
yum install php56w-common
yum install php56w-pdo
yum install php56w-opcache
php --version # Verify version has been upgraded
You can alternatively use php54w or php55w if required.
CAUTION!
This may potentially break your website if it doesn't fully resolve all your dependencies, so you may need a couple of extra packages in some cases. See here for a list of other PHP 5.6 modules that are available.
If you encounter a problem and need to reset back to the default, you can use these commands:
sudo yum remove php56w
sudo yum remove php56w-common
sudo yum install php-common
sudo yum install php-mysql
sudo yum install php
(Thanks Fabrizio Bartolomucci)
For CentOS 6, PHP 5.3.3 is the latest version of PHP available through the official CentOS package repository. Keep in mind, even though PHP 5.3.3 was released July 22, 2010, the official CentOS 6 PHP package was updated November 24, 2013. Why? Critical bug fixes are backported. See this question for more information: "Why are outdated packages installed by yum on CentOS? (specifically PHP 5.1) How to fix?"
If you'd like to use a more recent version of PHP, Les RPM de Remi offers CentOS PHP packages via a repository that you can add to the yum package manager. To add it as a yum repository, follow the site's instructions.
Note: Questions of this variety are probably better suited for Server Fault.
I managed to install php54w according to Simon's suggestion, but then my sites stopped working perhaps because of an incompatibility with php-mysql or some other module. Even frantically restoring the old situation was not amusing: for anyone in my own situation the sequence is:
sudo yum remove php54w
sudo yum remove php54w-common
sudo yum install php-common
sudo yum install php-mysql
sudo yum install php
It would be nice if someone submitted the full procedure to update all the php packet. That was my production server and my heart is still rapidly beating.
This is the easiest way that worked for me: To install PHP 5.6 on CentOS 6 or 7:
CentOS 6. Enter the following commands in the order shown:
yum -y update
yum -y install epel-release
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget https://centos6.iuscommunity.org/ius-release.rpm
rpm -Uvh ius-release*.rpm
yum -y update
yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath
CentOS 7. Enter the following commands in the order shown:
yum -y update
yum -y install epel-release
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
wget https://centos7.iuscommunity.org/ius-release.rpm
rpm -Uvh ius-release*.rpm
yum -y update
yum -y install php56u php56u-opcache php56u-xml php56u-mcrypt php56u-gd php56u-devel php56u-mysql php56u-intl php56u-mbstring php56u-bcmath
Sorry - I'm unable to post the source URL - due to reputation
Verify current version of PHP
Type in the following to see the current PHP version:
php -v
Should output something like:
PHP 5.3.3 (cli) (built: Jul 9 2015 17:39:00)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
Install the Remi and EPEL RPM repositories
If you haven’t already done so, install the Remi and EPEL repositories
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm && rpm -Uvh epel-release-latest-6.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && rpm -Uvh remi-release-6*.rpm
Enable the REMI repository globally:
nano /etc/yum.repos.d/remi.repo
Under the section that looks like [remi] make the following changes:
[remi]
name=Remi's RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Also, under the section that looks like [remi-php55] make the following changes:
[remi-php56]
name=Remi's PHP 5.6 RPM repository for Enterprise Linux 6 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/6/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/6/php56/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Type CTRL-O to save and CTRL-X to close the editor
Upgrade PHP 5.3 to PHP 5.6
Now we can upgrade PHP. Simply type in the following command:
yum -y upgrade php*
Once the update has completed, let’s verify that you have PHP 5.6 installed:
php -v
Should see output similar to the following:
PHP 5.6.14 (cli) (built: Sep 30 2015 14:07:43)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
Steps for upgrading to PHP7 on CentOS 6 system. Taken from install-php-7-in-centos-6
To install latest PHP 7, you need to add EPEL and Remi repository to your CentOS 6 system
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm
Now install yum-utils, a group of useful tools that enhance yum’s default package management features
yum install yum-utils
In this step, you need to enable Remi repository using yum-config-manager utility, as the default repository for installing PHP.
yum-config-manager --enable remi-php70
If you want to install PHP 7.1 or PHP 7.2 on CentOS 6, just enable it as shown.
yum-config-manager --enable remi-php71
yum-config-manager --enable remi-php72
Then finally install PHP 7 on CentOS 6 with all necessary PHP modules using the following command.
yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo
Double check the installed version of PHP on your system as follows.
php -V
IUS offers an installation script for subscribing to their repository and importing associated GPG keys. Make sure you’re in your home directory, and retrieve the script using curl:
curl 'https://setup.ius.io/' -o setup-ius.sh
sudo bash setup-ius.sh
Install Required Packages-:
sudo yum install -y mod_php70u php70u-cli php70u-mysqlnd php70u-json php70u-gd php70u-dom php70u-simplexml php70u-mcrypt php70u-intl

How to install bcmath module?

How do I install the bcmath module on a server? I tried
yum update php-bcmath
but it said it found nothing.
Try yum install php-bcmath.
If you still can't find anything, try yum search bcmath to find the package name
ubuntu and php7.1
sudo apt install php7.1-bcmath
ubuntu and php without version specification
sudo apt install php-bcmath
yum install php72-php-bcmath.x86_64
cp /etc/opt/remi/php72/php.d/20-bcmath.ini /etc/php.d/
cp /opt/remi/php72/root/usr/lib64/php/modules/bcmath.so /usr/lib64/php/modules/
systemctl restart httpd
Not sure why I had to go so deep considering the yum install gave me bcmath in phpinfo()
Worked great on CentOS 6.5
yum install bcmath
All my calls to bcmath functions started working right after an apache restart
service httpd restart
Sweet!
When using the official PHP images of Docker, use docker-php-ext-install bcmath.
Source: https://hub.docker.com/_/php?tab=description#php-core-extensions
Was getting call to undefined function bcmod()
yum install php-bcmath
systemctl restart httpd.service
you should then see something similar to /etc/php.d/bcmath.ini listed under phpinfo.
Centos 7
Plesk 12
PHP 5.4.16
If you have installed php 7.1
then this line work on your system.
sudo apt install php7.1-bcmath
check your php version in your system on ubuntu 16.04
php -v
and then result show there..
PHP 7.1.x+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Aug 19 2018
07:16:12) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine
v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.9-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
The following worked for me on Centos 7.4 with PHP 7.1 using remi repository.
First find out which PHP version I have:
[kiat#reporting ~]$ php --version
PHP 7.1.33 (cli) (built: Oct 23 2019 07:28:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies
Then search for bcmath extension in remi-php71 repository:
[kiat#reporting ~]$ yum search php71 | grep bcmath
php71-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
php71u-bcmath.x86_64 : A module for PHP applications for using the bcmath
Now install the first matching extension:
[kiat#reporting ~]$ sudo yum --enablerepo=remi-php71 install php-bcmath
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00
.
.
.
Finally, restart php and nginx:
[kiat#reporting ~]$ sudo systemctl restart php-fpm nginx
I found that the repo that had the package was not enabled. On OEL7,
$ vi /etc/yum.repos.d/ULN-Base.repo
Set enabled to 1 for ol7_optional_latest
$ yum install php-bcmath
and that worked...
I used the following command to find where the package was
$ yum --noplugins --showduplicates --enablerepo \* --disablerepo \*-source --disablerepo C5.\*,c5-media,\*debug\*,\*-source list \*bcmath
If you want to enable any extension then you have to install an extension first, extension maybe enabled but not installed, so taking the example of bcmath
yum search php-bcmath
Then ensure the php version in which u want to install this extension
You will get output like after yum search command>>
yum search php-bcmath**
Loaded plugins: fastestmirror, universal-hooks
Loading mirror speeds from cached hostfile
EA4: 66.71.244.18
cpanel-addons-production-feed: 66.71.244.18
base: mirror.nodesdirect.com
epel: mirror.coastal.edu
extras: www.gtlib.gatech.edu
nux-dextop: mirror.li.nux.ro
updates: mirror.jaleco.com
**============================================================== N/S matched: php-bcmath ===============================================================
ea-php54-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php55-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php56-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php70-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php71-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
ea-php72-php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
If I wanna install for php71 then the command will be like yum install ea-php71-php-bcmath.x86_64 or yum install php71-bcmath.
You can install any extension from the above steps.
In Ubuntu PHP 7.3
sudo apt install php7.3-bcmath
To enable bcmath in Arch Linux or Manjaro
Edit php.ini
nano /etc/php/php.ini
Uncomment bcmath (remove semicolon)
extension=bcmath
If you are using Apache server reload the server by
sudo systemctl reload apache.server
Or
sudo systemctl realod httpd
If you don't use Apache
sudo systemctl reload php-fpm.service
To see the activated modules
php -m
To make sure the bcmath is installed and activated, search for it
php -m | grep bcmath
This worked for me install php72-php-bcmath.x86_64
Then,
systemctl restart php72-php-fpm.service
For PHP 7+ version you can use only:
sudo apt install php-bcmath
I just tried below package for php v5.6 and it worked for me.
yum install php56w-bcmath
apt repo have this extension, just run the below command from your terminal ::
sudo apt-get install php7.2-bcmath*
If still anyone is not getting how to install bcmath as it has lots of other dependant modules to install like php7.2-common, etc.
Try using synaptic application, to install the same. fire command.\
sudo apt-get install synaptic
Open the synaptic application and then click on search tab.
search for bcmath
search results will show all the packages depends on php.
Install as per your convenience.
and install with all auto populated dependancies it required to install.
That's it.
For Centos 7 with php7.0
Install CentOS SCLo RH repository: yum install centos-release-scl-rh
Install rh-php71-php-bcmath rpm package: yum install rh-php71-php-bcmath
systemctl restart httpd.service
If you want to install PHP extensions in ubuntu.
first know which PHP version is active.
php -v
After that install needed plugin using this command.
sudo apt install php7.0-bcmath
you can replace php7.0-bcmath to php-PHPVersion-extensionName

Categories