How is PHP installed when you use yum or apt-get - php

I always get this weird questions about how stuff works behind the scenes. I know how to compile php from source, and I know that if you compile it from source and forget to add a module/library you need to re-compile php to add it. However, if you install php lets say using yum, and then you want to add another extension, you just need to install that extension. For example, today I was working on a recently installed Fedora 18 machine, and php was missing the DOM library, which is weird, since that library is enabled by default. It seems like yum installs php with that extension disabled. Anyway, since it was missing, I had to do this:
sudo yum install php-xml
And that solved the problem, but it made me wonder, how is the installation process in this case? Is php re compiled? and if so, how does it remember all the other extensions that may have been added before? Or is the xml extension installed separately and somehow linked into php?
I haven't found any info about this, and I'm really curious as to how it works.

When you install php extension packages using a package manager like yum or apt-get, the repositories have the already compiled so extensions for the version of php that came with the system. For example, if you're on Ubuntu 12.04, and you do a apt-get install php-mysqlnd, it fetches the deb package from the repository which contains the pre-compiled mysqlnd.so and a default mysqlnd.ini. This works because the deb package has the compiled version according to the default dependencies that are installed for the 12.04 release. If some dependencies are missing, the precompiled deb packages are fetched for the same, thus eliminating the need for configuration and make. This make it a lot faster and easier. Almost plug and play!

You can build extensions separately, you don't have to rebuild your php every time you need to add a new extension, you just need to define the extensions that needs to be loaded under [extensions] in your php.ini.
When your building php you can specify which extensions you need to be statically (included) in the php binary vs which once you want as a shared library.
configure --enable-http=static --with-openssl=shared
// http extension will be included in PHP
// openssl extension will be compiled as separate DLL

Yum connects to repositories of pre-compiled rpm's. Yum will download the rpm and its dependencies and install them.
Yum will use different repositories for different OS's. For example Fedora 18 has a different repostitory of pre-compiled rpms then Fedora 17 would have.
Yum is just a glorified dependency management system

Related

How to add php 7 extensions using remi on CentOS 7

Please help with php 7 extensions on CentOS 7.
When trying to isntall extension, for example memcache and memcached using the command yum --enablerepo=remi-php74 install php-memcache php-memcached I got the message that this packages are already installed.
php --modules also shows they are present. But I can't find them in /etc/opt/remi/php74/php.d and /opt/remi/php74/root/lib64/php/modules.
I attached screenshot of phpinfo() as well phpinfo, there are no additional extensions...
Please advice what I'm doing wrong, I'm not very strong in this DevOPS things :-)
Also added php --ini response php --ini
For a proper installation please follow the Wizard instructions
If you need a single version, php-* packages are simpler to install and use
If you need multiple versions, php74-php-* are available
You can read the repository FAQ: Difference between php-* and php##-php-* packages ?
So as you are running php74-php you need
yum install php74-php-pecl-memcache php74-php-pecl-memcached
But if you need a single version, probably better to remove all php74* packages and only use php-* ones.

How do I install PHP Statistics extension in my Laravel Project?

I want to invoke the stats_rand_gen_exponential() function but apparently to do so I need to install the Statistics extension.
How do I install extensions using Composer?
UPDATE
I cannot understand what could possibly be wrong.
PHP extensions can't be installed using Composer. You can require them, but all that does is tell Composer that they need them to run, so that they will fail explicitly when someone installs the dependencies for your package. See https://getcomposer.org/doc/01-basic-usage.md#platform-packages for details.
There are a number of ways to install PHP extensions and the best will often depend on your platform. On Linux, there may be packages available for that extension via your package manager, and if so that's the easiest method. PECL looks to be the recommended installation method for this extension, so that would be my second choice if it's not available via a package manager. Or if you're using phpbrew you can probably use phpbrew ext install to install the extension you need.

PHP 5.6 Repository URL for Ubuntu 14.04 Trusty

I have PHP 5.6.18-1+deb.sury.org~trusty+1 and am trying to update to 5.6.19. However, when I do apt-get update && apt-get upgrade, PHP does not get updated.
I have tried add-apt-repository ppa:ondrej/php5-5.6 as well as manually adding in deb http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu trusty main to my sources.list file to no avail.
How can I update PHP to 5.6.19 and make sure I don't run into this problem again in the future?
The ppa:ondrej/php5-5.6 repository is discontinued in favour of just ppa:ondrej/php. At the time of writing, this gives me an up-to-date version of PHP 5.6:
php --version
PHP 5.6.27-1+deb.sury.org~trusty+1
Note that, once you've added the repository, you'll need to uninstall any packages beginning php5* and reinstall php5.6* equivalents; also, you will probably have to switch Apache modules. More information on some of the steps required on this blogpost.
Note that, because of the quirk of the package maintainer's name containing a non-ASCII character, you might also need to install e.g. language-pack-en to fix all your server locales first. There's some other suggestions of what to do on this ServerFault question but for me it was trivial to install the language pack and let that take care of all locale settings.

Installing PEAR

phpinfo() function shows that my PHP version (5.1.6) is installed --without-pear in the configure command section.
How do I install pear?
The Getting and installing the PEAR package manager page should help you : it gives informations on how to install the PEAR package manager, on both windows, Linux, and Mac.
Basically, if your Linux distribution comes with a PEAP package, you should install it.
For instance, on Ubuntu1, there is a php-pear package ; so, you'd use :
apt-get install php-pear
Else, if it doesn't, with a version of PHP >= 5.3, you should be able to use this :
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar
With PHP 5.1, though, this is not going to work, as phar support has been added in PHP 5.3...
As a sidenote : PHP 5.1 is really outdated !
PHP 5.3 is more than one year and a half old ; even PHP 5.2 is not maintained anymore... maybe you should consider upgrading ?
1It seems you are running some kind of Redhat-based distribution, but I don't have one of those, so I cannot say if there is a PEAR package for it -- there is probably one, though.
--without-pear only means that the PEAR bits were not immediately created when PHP was compiled.
This usually happens when an operating system vendor that provides packages and wants to split off bits and pieces into their own individually installable parts.
Given the age of the PHP you're talking about, you're probably on RHEL or a derivative like CentOS. Check the package manager for a php-pear package.

Overriding yum dependency checks when newer versions of the dependent software exist

I'm using yum on CentOS 5.1 - I hand-compiled PHP 5.2.8 from source, but have other packages installed using yum. I need to install a PHP extension via pecl, and it requires phpize to be installed as well. However, doing the following yields a dependency error:
sudo yum install php-devel
Error: Missing Dependency: php = 5.1.6-20.el5_2.1 is needed by package php-devel
Since I actually have a newer version of PHP already installed, how can I force yum to ignore this? Do I need to hand-compile pecl/phpize from source? I admittedly never had a problem before, it only seems to be because of a combo of compiles and yum installs.
Any thoughts?
Thanks,
Kyle
In general:
If you build it yourself, it goes into /usr/local, and is only accessible to other things in /usr/local.
If you install from RPM/Yum, it goes into /usr, and is accessible to /usr and /usr/local.
So, if you want to install PHP tools using home-compiled PHP, install them into /usr/local as well: typically, with GNU-type software, that'd be something like:
./configure --prefix=/usr/local && make && sudo make install
or
make prefix=/usr/local all && sudo make prefix=/usr/local install
…although most software should default to /usr/local unless you override its prefix setting.
If you want to “hand-build” packages that are based upon RPM's, you can use
yumdownloader --source WHATEVER-PACKAGE
rpm -i WHATEVER-PACKAGE.rpm
rpmbuild -bp ~/rpm/SPECS/WHATEVER-PACKAGE.spec
(your path equivalent to ~/rpm may vary; rpmbuild --showrc will tell you where)
This downloads the .src.rpm package, which contains the upstream (original author's) source (usually a tarball) as well as OS-specific patches; installs the sources into ~/rpm (or your rpmbuild prefix); and then unpacks the sources and applies the patches into ~/rpm/BUILD/WHATEVER-PACKAGE/
From there, you can do the configure/make steps yourself, with the /usr/local prefix
Of course, just installing from RPM's is far easier :-)
yum doesn't know anything about your hand-compiled php version. You can either bypass RPM's dependency resolution by installing the package using rpm --nodeps and hope it works.
Or install the php version you compiled yourself in another directory so it can coexist with the old version from yum, so everyone is happy (not sure if that's possible, I guess it depends on whether your apps use a hardcoded path to php or not).
Or, if you are lucky, a third-party repository like EPEL or RPMForge might have a newer php package, so you don't have to compile your own.
As a rule of thumb, it's better to have one package management in the system, so you'll be better off packaging everything in RPMS and managing it via yum. It will save you lots of time in the long run.
If you absolutely want to have something (fe PHP) compiler from sources by hand, use stow/checkinstall/... or any other solution which would enable you to do rudimentary package management for source-compiled stuff.
Regerding your question, you could try to override dependency checking by downloading RPM of the required package an doing "rpm -i --force file.rpm", since yum does not have any option for forced installations

Categories