Compile PHP on Linux or use apt-get / yum? - php

I have been compiling PHP for years with the configuration options I want. I compile extensions I use from source. Is there an advantage to doing this versus installing it from a package manager like apt-get or yum. I assumed it would also give me a leaner binary. I noticed that their are PHP modules in the repos such as "php53-gd". What if there wasn't a package available for something I wanted such as cURL for PHP?
I understand the disadvantages of compiling such as needing to download/install dependencies based on my configuration options. I'm not really concerned with that.
So the question is:
Compile PHP on Linux or just use apt-get / yum? Can I get all the things I need from the repos? Does anyone out there still compile it from source?
Any insight is appreciated! Thanks.

I compile from source every time. It's not hard to corral the mentioned issues with regards to compiling manually. For example, my ./configure settings are saved to a file which is version controlled, so when a new version of PHP is stable and I am ready to make the switch, I download and extract the file, then run this command:
./configure `sh /path/to/my/configure/php.sh`
Not too difficult. And because it's in version control, I can add notes as to why a module was added or removed.
Another benefit of manual compilation is it allows me to keep the PHP footprint as minimal as possible. I pass the --disable-all flag, then add the modules I need. However, there is a downside to this minimalist approach, recently I needed to install Magento, so I had to recompile with --enable-hash and --with-mcyrpt flags. Even though I needed to add new flags, it wasn't difficult to add to the configure file and recompile.

Compiling from source has a few quirks:
There are hundreds of config parameters and flags. And you might not know the optimal ones that need to be used.
if you rely on apt-get's PHP, then you can be assured that you will get the latest patches and security updates if you set up auto-upgrade on your server.
the configuration of php.ini varies a lot. Sometimes your OS may decide some defaults for you which may work better with the rest of the system.
installing extensions like xdebug or other packages are a lot easier with apt.
However, it's worth compiling php from scratch if you want to learn. Also if you don't use some portions of it, you can always disable them in configuration - but then again it might not make much difference to performance.

I compiled php for specific needs only, like :
very small hard disk space so required a minimalist php version
and/or
need only a few specific modules or extensions
and/or
needed for a specific application
and/or
needed to optimize performances: when compiling on the machine where it's used, this allows some performance improvements, if using compile options to get a real tuned version for your system,
and/or
needed multiple and different php versions on the same machine.
and/or
I had a specific nux distro like only a busybox, so no other options than compiling.
But for common usage, e.g. in 80% of the cases, it's not worth spending time to compile and better using the repository version. But I learned a lot by compiling.

Personally, it's a matter of opinion. If you are in a hurry, apt-get it, if you have time to learn and possibly need to reinstall 20 times...compile it.
There are tons of guides out there for PHP compiling. It has a ton of flags for configuration, especially for GD and other libraries. Personally if this is for learning and development, just get LAMP or use apt-get...especially if you need to use Apache

I feel the primary reason for compiling is to have latest version binary (stable or nightly). package managers (most distors) are often annoyingly slow in this respect.
The other reason is that its very common problem that production systems are not wholesale upgraded using package managers. Even if that can be easy. Since package managers create dependency chains and you may not want to upgrade those items. So just to pick one item, compiling is an option. It keeps everything else as it is. You ofcourse have to always study the upgrade issues and make sure nothing else will fail.

Related

Is there a way to change config options after compiling software?

I compiled php 5.4, and am trying to get an existing site ported to it. The problem I'm seeing is that I didn't use the --with-pdo-pgsql option when running ./configure, so I can't connect to my db.
I've already compiled it twice, is there a way to update the configuration without rerunning make and make install?
No, because the shared module was not built to begin with. I don't think PHP allows partial compile of modules, but check the makefile for ability to build modules one at a time. There are builds for just about everything out there already, so maybe consider a prebuilt (and pre-patched) version as well?

How can I avoid 'make install' when building PHP in Unix environment?

I'm attempting to rapidly deploy a PHP application under apache2/PHP on a Unix host. The sysadmin hasn't heard of PHP so I'm looking to build/install myself. Unfortunately root access is two weeks of bureaucracy away so I'm looking for a way to use PHP and its requisite libxml2 without installing.
You can be a non-privileged user and build Apache and PHP. You can have your own prefix paths for the installs, and if the development headers for the necessary libraries are available you can use them. You're going to hit issues in that as not-root you'll have to start Apache on a port > 1024. You're also not going to have the system package management available, so updates will have to be likewise built. In short, it's doable, but depending on which UNIX you're actually using, may not be horrendously pleasant. PHP in particular needs many many libraries (and if you're building from source, runtime isn't enough, you need the dev headers files) to have a usable system.
Good luck.
You can't avoid make install, but you can maybe use --prefix

After compiling PHP from source are the devel libraries still needed?

After compiling PHP from source are the devel libraries still needed?
For example, I am building a newer version of PHP from source than is on our dev servers. I installed alot of [extension i.e. mysql, postgresql, curl, etc]-devel packages in order for the configure from the dev server setup to work. Do i still need these after php has compiled? For example could I make a distro and then distribute the PHP distro to another server without needing these devel dependencies?
I am a bit of a noob to this.
You don't need to ship the devel-libraries.
But my advice is to take some time and learn how the build system of your linux distribution works. And then build a new php package that can be installed by the package manager.
Take a look at how the "original" php packages were built for the distribution. Most likely you can simply copy and edit the existing rule file(s) and then make a new version of that package. This way you take advantage of the dependency mechanisms and the package manager will not remove/overwrite your version so easily when an update shows up in the "official" repositories.

what are the Advantages and disadvantages of running php on windows

the linux environment is natural to php,
what are the Advantages and disadvantages with run php on windows ?
Are there some limits in windows ?
what is the best (lamp/wamp) in term of performance ?
thanks
It's not so much that it is natural on Linux but the tendency was for developers to use PHP in the earlier days as the ASP on Linux. For years MS never even mentioned PHP and never gave it any support and so most development work happened in the Linux arena with the result that it is more advanced as it has simply had more development hours spent on it.
Again in the early days it was more difficult to get PHP running on ISS but apache makes it easier but then you need to install it. I rarely develop on Windows but i think the environment has changed for the better with more integration.
The emergence of packages such as XAMPP and WAMPP make installation and running a lot easier but as Karsten says not really for the production environment as they are not geared for it in performance and especially on the security level, because of this i also doubt if they are geared for performance, they are geared for ease of install and development.
Case sensitivity can be a problem if you develop in Windows and later move to Linux.
Well, there's the obvious problem of trying to compile PECL extensions on a Windows platform, and the problems associated with not having sendmail running and trying to use the mail function.
Other than that, as long as the source has been ported correctly, it should do fine.
There is an Site from Microsoft for this http://php.iis.net/
For good Performance also check out http://www.iis.net/expand/fastcgi
I can't give you performance statistics. Would guess that an extremely stripped-down version of Linux or BSD is best from that standpoint.
There are two main disadvantages of Windows. One is that you're likely to have to build some of the lesser-used extensions yourself, if you need them. (There are Windows builds of the common stuff - APC, etc. - available on the net for 32-bit, though. For 64-bit Windows... well, it's a jungle out there.) The other is that you're going to be in the minority, so expect all the things that go hand-in-hand with that. (If you run into configuration difficulty, for example, there will probably be fewer people able to help you.)
The advantage is that (especially if your favorite IDE is something like Visual Studio) you can run all your favorite Windows stuff on the machine. This is really only an advantage if this is, say, a development box - something you're going to use for other purposes as well, not just as a server.
If you are working in an windows environment, running your application/php scripts there makes a lot of sense if you want to debug locally.
I wouldn't use WAMP for production environments, because its nature is in linux imho.
XAMPP solves the sendmail issue amphetamachine is talking about by installing mercury mail.
It also comes with prebuilt xdebug, apc and memcache modules, which are for me the usual pecl compiled extensions.
An obvious problem with PHP on Windows/Apache is not being able to configure PHP APC for current versions of PHP. Hence, no way to create elegant file uploads with progress bar.
Most and main PHP developers (I mean, those that create the language) seem to work under Unix platform. Also, almost all Linux distros take care of building, packing and fixing PHP to suit their systems. And this also applies to auxiliary software like Apache. As a result:
There's always some functionality that doesn't work on Windows, e.g. strptime() or has more bugs.
Windows binaries are not optimized for your system. You can't even get 64 bit binaries unless you compile them yourself.
The MSI installers are not as polished as they should.
Installing PECL extensions is very complicate since there aren't official DLLs.
Of course, there's also Windows-only functionality in PHP, such as Windows only extensions or third-party extensions like the Microsoft SQL Server Driver for PHP, or functionality that's way easier to use under Windows, such as ODBC.
Talking about performance itself, it's difficult to make a fair comparison. The operating systems themselves have very different hardware requirements and it'd be misleading to compare optimized Unix builds with generic Windows binaries. My intuition says that the decision of choosing either platform should be based in other considerations, such as budget, required features or ease of maintenance.
There are many quirks across platforms with PHP, and I don't recommend switching between LAMP / BAMP / SAMP and WAMP / WIMP.
For one thing, permissions are completely different -> usually being a lot harder to work with in Unix/Linux (as Windows doesn't seem to care all that much about permissions as far as I have ever seen). This is a good thing, in my opinion, though (I'm relatively safety paranoid).
Here are a couple more things that differ:
http://php.net/touch (could't change windows directory modified times until 5.3)
http://php.net/flush (still can't flush or ob_flush from some win32 machines)
Both have system specific issues that were just SUPER recently worked out or haven't been fixed yet...

PHP APC and Imagick with cpanel

I currently purchased a dedicated server hosted at iWeb and got it administered by them.
I recently asked after registration to add php_apc and php_imagick to the available libraries. It seems according to them that it is not possible as it is not supported with cPanel.
I would apparently need to do that myself... is there any risks to install those two libraries ? What kind of problem could it raise if there is any ? In case I would have to debug this myself.
Installing Imagemagick to your system in itself won't be too much of a problem.
However, adding support for it and APC to PHP may be a tricky procedure; it may be best for you to just no longer use the PHP provided by cPanel and install PHP yourself, which will go into /usr/local, and run the configure script for it yourself, compiling in whatever extensions you need. It'll mean that you'll need to keep PHP up to date yourself, but it'll also mean that you won't have all your customisations to it wiped the next time cPanel upgrades it.
If there are better suggestions I'd also be interested to hear them.

Categories