Why does PHP install so many version folders? - php

new to linux, I installed php on debian9 with the following commands...
sudo apt-get update
sudo apt-get upgrade
wget -q https://packages.sury.org/php/apt.gpg -O- | sudo apt-key add -
echo "deb https://packages.sury.org/php/ stretch main" | sudo tee /etc/apt/sources.list.d/php.list
apt-get update
apt-get install ca-certificates apt-transport-https
apt-get install php7.2 php7.2-cli php7.2-common php7.2-opcache php7.2-curl php7.2-mbstring php7.2-mysql php7.2-zip php7.2-xml
Later I needed XDebug I installed via the following
sudo apt install php-xdebug
phpinfo was displaying xdebug present
and I went configuring /etc/php/7.0/mods-available/xdebug.ini with
I never got remote debugging to work neither from vscode or phpstorm. However, on Windows7 I managed to have more success and fixed my php deprecated code from 5.x to 7.x
Now I needed on curl and mbstring extensions on the linux side.
I enabled those extensions in /etc/php/7.0/apache2/php.ini
extension_dir = "./"
extension=curl
extension=mbstring
and I ALSO run the the following according to a post.
sudo apt-get install php-mbstring # Debian, Ubuntu
I think that's when XDebug disappeared from phpinfo
After a couple of sudo update/upgrade
[![enter image description here][5]][5]
now php -i | grep "php.ini" shows php switched from 7.2 to 7.4 ???
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
yet the 1st line of phpinfo still says 7.0
PHP Version 7.0.33-25+0~20200225.32+debian9~1.gbpa11893
, I am totally confused. php -m lists curl, mbstring, and xdebug.
FileZilla shows me all these folders under php and I have, like 10, php.ini both under cli/ and apache2/ a real frustration as to what to edit???
Summary: simple php runs (eg. echo, phpinfo(), ... ), but my script calls curl and mb_convert_encoding() which I think must be failing.

Related

PHP Extensions activate in Ununtu

Ive installed an extension (rdkafka) to the server (ubuntu)
and added the extension to php.ini
extension=rdkafka.so
but when i go to phpinfo(), the rdkafka is not activated
when i try this command:
phpenmod rdkafka
i got this error:
WARNING: Module rdkafka ini file doesn't exist under /etc/php/7.3/mods-available
on extensions folder,, all the extensions colored green, except rdkafka is white
install PHP pecl and pear
sudo apt install php-pear
Add backports repository. Current ext-rdkafka depends on librdkafka version 0.11.0 or greater. So follow official instructions but use stretch-backports
Install librdkafka-dev package from backports:
sudo apt -t stretch-backports install librdkafka-dev
Update apt:
sudo apt update
Install PECL-package:
sudo pecl install rdkafka
Enable PHP-extension in PHP config. Add to php.ini:
extension=rdkafka.so
Restart apache
sudo apachectl -k restart

PHP Warning: PHP Startup: Unable to load dynamic library 'mcrypt.so'

I am trying to update laravel using composer update on ubuntu 06.04 but everytime i run composer update this warning always comes up.
PHP Warning: PHP Startup: Unable to load dynamic library 'mcrypt.so' (tried: /usr/lib/php/20170718/mcrypt.so (/usr/lib/php/20170718/mcrypt.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mcrypt.so.so (/usr/lib/php/20170718/mcrypt.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Does anyone knows how to deal it?
I am using php7.2
I faced similar issue when I installed Php7.2 on Ubuntu 18. Though I had installed mcrypt using PECL still I get the error mentioned in the question.
I did following to fix it
sudo apt-get install php-pear php7.2-dev
then uninstalled
pecl uninstall mcrypt
Now reinstall mcrypt
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev
sudo pecl install mcrypt-1.0.1
When you are shown the prompt
libmcrypt prefix? [autodetect] :
Press [Enter] to autodetect.
After success installing mcrypt using pecl, you should add mcrypt.so extension to php.ini.
The output will look like this:
...
Build process completed successfully
Installing '/usr/lib/php/20170718/mcrypt.so' ----> this is our path to mcrypt extension lib
install ok: channel://pecl.php.net/mcrypt-1.0.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=mcrypt.so" to php.ini
Now restart Apache
sudo service apache2 restart
Grab installing path and add to cli and apache2 php.ini configuration.
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"
First, open up a terminal window and install the necessary dependencies with the commands:
sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install php7.2-dev
sudo apt-get -y install libmcrypt-dev
Once the dependencies have been installed, you can install mcrypt with the command:
sudo pecl install mcrypt-1.0.1
And there you go. Mcrypt is now installed. Go back to the process of installing whatever server software that depends upon this extension and you should be good to go.
For (>= PHP 7.3) you can use the following command:
sudo pecl install mcrypt-1.0.2
I faced this problem when I upgraded my PHP to 7.3
I found mcrypt.so was still present in /etc/php/7.3 that should not be as it is deprecated in php 7.3 so just deleting mcrypt.so from /etc/php/7.3 solved issue.
I used following commands:
cd /etc/php/7.3
sudo rm -rf mcrypt.so
sudo service apache2 restart
İts is worked for me.
export LC_ALL="C"
export LANG="C
sudo pecl install mcrypt-1.0.1
Also, if you're using php 7.2 & are getting this error and you know do not want/need mcrypt, but do not know how to exclude it.... You need edit your php.ini file and either comment this out by using a semi-colon in front of it:
; extension=mcrypt.so
or just delete that line entirely.

How can I install mcrypt under PHP7? Laravel needs it

Since Laravel4 requires mcrypt extension, and PHP7 doesn't seem to have mcrypt extension, is there any workaround for this to work?
Had the same issue - PHP7 missing mcrypt.
This worked for me. When asked, keep local PHP configuration files.
sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
sudo apt-get upgrade
Restart FPM (or Apache or NGINX etc.) after installation.
I'm on Mac and with laravel valet I've solved with this:
brew install php70-mcrypt
Even if you enable mcrypt in php.ini, this issue may occur.
Try the following steps.
sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
I am working in ubuntu 16.04 and the following commands also helped me.
whereis php -shows the files with this name
php -v -shows the php version
which php -shows current php version that is running on the server
On ubuntu: According to launchpad.net the package for mcrypt is called php7.0-mcrypt.
sudo apt-get install php7.0-mcrypt to install
Open terminal with Ctrl + Alt + T and run following commands for PHP7.0 on Ubuntu 16.4
sudo apt-get install mcrypt php7.0-mcrypt
sudo service apache2 restart
php7 have mcrypt, you can enable it in php.ini and then everything will work fine.
do like this:
wget http://jp2.php.net/distributions/php-7.0.3.tar.gz
tar zxf php-7.0.3.tar.gz
cd php-7.0.3/ext/mcrypt
/php7-path/bin/phpize (when error such as configure: error: mcrypt.h not found. Please reinstall libmcrypt run apt-get install libmcrypt-dev)
./configure --with-php-config=/php7-path/bin/php-config
(sudo) make && make install .this will install the mcrypt.so in php-7.0.3/ext/mcrypt/modules
cp to the /usr/lib/php/20151012/ what is the shared extensions dir
create a mcrypt.ini in /etc/php/mods-available/ write as extension=mcrypt.so
create link to this such as sudo ln -s /etc/php/mods-available/mcrypt.ini 20-mcrypt.ini in /etc/php/7.0/fpm/conf.d
create link to this such as sudo ln -s /etc/php/mods-available/mcrypt.ini 20-mcrypt.ini in /etc/php/7.0/cli/conf.d
sudo service nginx restart
sudo service php7.0-fpm restart
yes it is.
I use, Dotdeb, an extra repository providing up-to-date all kinds of cool toys for your Debian servers like Nginx, PHP, MySQL, Redis etc.
Update your sources.list
deb http://packages.dotdeb.org {distribution} all
deb-src http://packages.dotdeb.org {distribution} all
GnuPG keys
wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg
Update apt & build something amazing.
sudo apt-get update
PHP7 contains mcrypt extension internally (source-path/ext/mcrypt/).
But it depends on Libmcrypt soft.
Step 1.
Download libmcrypt-x.x.tar.gz from http://mcrypt.sourceforge.net/
and build it.
cd libmcrypt-x.x
./configure
make
make install
Step 2.
Rebuild PHP7 from source and add --with-mcrypt option.
./configure ... --with-mcrypt
Other way without rebuilding PHP7
cd php7-source-path/ext/mcrypt/
/php7-path/bin/phpize
./configure --with-php-config=/php7-path/bin/php-config
make && make install
echo "extension=mcrypt.so" >> /php7-path/ext/php.ini
Restart php

How do you install Libevent for PHP?

I installed the libevent-dev library on my Debian 7 64bit desktop:
$ sudo aptitude install -y libevent-dev
Then I installed the PECL library
$ pecl list
Installed packages, channel pecl.php.net:
=========================================
Package Version State
libevent 0.1.0 beta
I've restarted PHP and the OS but PHP doesn't list libevent as an installed ext in with phpinfo() and I get "PHP Fatal error: Call to undefined function event_base_new()" when I try to use it.
How do you install Libevent?
Install Libevent for PHP 5.X
sudo apt-get install libevent-dev
sudo pecl install libevent-beta
sudo su
sudo echo 'extension=libevent.so' > /etc/php5/mods-available/libevent.ini
exit
sudo ln -s /etc/php5/mods-available/libevent.ini /etc/php5/fpm/conf.d/
sudo ln -s /etc/php5/mods-available/libevent.ini /etc/php5/cli/conf.d/
sudo service php5-fpm restart
Install Libevent for PHP 7.X
At this time pecl package libevent is not available for php 7
https://pecl.php.net/package/libevent
So let's compile it.
Download master:
https://github.com/expressif/pecl-event-libevent
Unpack to: /tmp/install_libevent
cd /tmp/install_libevent/pecl-event-libevent-master
sudo phpize
sudo ./configure
After this step scroll our console window and try find any Warnings or Errors. I got one warning - required to install re2c package.
sudo make
sudo make install
sudo su
sudo echo 'extension=libevent.so' > /etc/php/7.0/mods-available/libevent.ini
exit
sudo ln -s /etc/php/7.0/mods-available/libevent.ini /etc/php/7.0/fpm/conf.d/20-libevent.ini
sudo ln -s /etc/php/7.0/mods-available/libevent.ini /etc/php/7.0/cli/conf.d/20-libevent.ini
sudo service php7.0-fpm restart
I've successfully installed it.
These are the steps:
apt-get install libevent-dev
sudo pecl install libevent
Edit: Press enter when you are asked for the libevent installation directory (autodetect)
; Add extension=libevent.so in the *.ini file where you desire to load it. For example if you want this extension to be loaded always, create a libevent.ini file where your php5 mods are (in my computer they are in /etc/php5/mods-available/) and write extension=libevent.so. Enable this module then with php5enmod libevent. This page may help you.
Add extension=libevent.so to php.ini.

Installing PHP Zip Extension

I'm attempting to install the PHP Zip extension.
My server does not have external internet access, so I downloaded it myself from PECL: http://pecl.php.net/package/zip. I chose 1.10.2, the latest "stable" release, and transferred it to my server.
I ran:
pear install zip-1.10.2.tgz
and added
extension=zip.so
to php.ini as instructed. I can see that zip.so was created and placed in the right extension_dir folder as well. I restarted apache and then checked to see if it was loaded by running:
php -m
Despite all of this, "zip" is still not in that list.
Am I missing a step or doing something wrong? I thought this should be really simple, and I'm starting to feel pretty dumb, haha.
Other probably important stuff:
CentOS
Apache 2.2.3
PHP 5.2.16
This is how I installed it on my machine (ubuntu):
php 7:
sudo apt-get install php7.0-zip
php 5:
sudo apt-get install php5-zip
Edit:Make sure to restart your server afterwards.
sudo /etc/init.d/apache2 restart or sudo service nginx restart
PS: If you are using centOS, please check above cweiske's answer
But if you are using a Debian derivated OS, this solution should help you installing php zip extension.
You may have several php.ini files, one for CLI and one for apache. Run php --ini to see where the CLI ini location is.
Simply use sudo yum install php-zip
for PHP 7.3 / Ubuntu
sudo apt install php7.3-zip
for PHP 7.4
sudo apt install php7.4-zip
1 Step - Install a required extension
sudo apt-get install libz-dev libzip-dev -y
2 Step - Install the PHP extension
pecl install zlib zip
3 Step - Restart your Apache
sudo /etc/init.d/apache2 restart
If does not work you can check if the zip.ini is called in your phpinfo, to check if the zip.so was included.
For php 7.3 on ubuntu 16.04
sudo apt-get install php7.3-zip
The best way to install the Zip extension in php7.2 on CentOS would be as below:
Find the available extention by searching with yum command
yum search zip
This will list all the zip packages. We need to look for the php7.2 zip package
Then if your php version is 7.2 then run the command
yum install ea-php72-php-zip
This will definetly resolve your issue.
Cheers !!
On Amazon Linux 2 and PHP 7.4 I finally got PHP-ZIP to install and I hope it helps someone else - by the following (note the yum install command has extra common modules also included you may not need them all):
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum -y install yum-utils
sudo yum-config-manager --enable remi-php74
sudo yum update
sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
sudo pecl install zip
php --modules
sudo systemctl restart httpd
If you use php5.6 then execute this:
sudo apt-get install php5.6-zip
The PHP5 version do not support in Ubuntu 18.04+ versions, so you have to do that configure manually from the source files. If you are using php-5.3.29,
# cd /usr/local/src/php-5.3.29
# ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=MySQL_LOCATION/mysql --prefix=/usr/local/apache/php --with-config-file-path=/usr/local/apache/php --disable-cgi --with-zlib --with-gettext --with-gdbm --with-curl --enable-zip --with-xml --with-json --enable-shmop
# make
# make install
Restart the Apache server and check phpinfo function on the browser <?php echo phpinfo(); ?>
Note: Please change the MySQL_Location: --with-mysql=MySQL_LOCATION/mysql
I tried changing the repository list with:
http://security.ubuntu.com/ubuntu bionic-security main universe http://archive.ubuntu.com/ubuntu bionic main restricted universe
But none of them seem to work, but I finally found a repository that works running the following command
add-apt-repository ppa:ondrej/php
And then updating and installing normally the package using apt-get
As you can see it's installed at last.
I was trying to install it on CentOS 7 for php 7.1. In my case yum package php-zip was unavailable in remi repo, but I could install it using different name
yum install php-pecl-zip
So if you can't find it by query php-zip, try searching for php-pecl-zip.
For those who need to install the zip extension in a Docker image being built.
Dockerfile:
FROM php:8.1-apache
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& docker-php-ext-install zip

Categories