Linux – CentOS6 – PHP – Compile command line only

centoslinuxPHP

I just setup a new server which will host a solr daemon. As it stands now the solr index is empty, but I have a php script available to pull data from a MySQL store and populate the solr index to facilitate my fulltext searching requirements.

So I'm wondering, is it possible to compile PHP to be command line only? It seems a waste to have to install apache just to get PHP to work.

— Edit —

A little more clarification. When I run make install on CentOS, the make attempts to add PHP footprint to /etc/httpd/conf. Is it ok to simply ignore this? Or is there a flag I can pass to ignore apache?

Best Answer

If you must compile on Red Hat, CentOS or other Red Hat-derivatives, I recommend you use rpmbuild -bb (I'll explain in the moment) with the .spec.in provided in the php source either by Red Hat or by upstream developer (PHP). Here is a sample from the upstream:

%define version @VERSION@
%define so_version 5
%define release 0

Name: php
Summary: PHP: Hypertext Preprocessor
Group: Development/Languages
Version: %{version}
Release: %{release}
Copyright: The PHP license (see "LICENSE" file included in distribution)
Source: http://www.php.net/get/php-%{version}.tar.gz/from/a/mirror
Icon: php.gif
URL: http://www.php.net/
Packager: PHP Group <group@php.net>

BuildRoot: /var/tmp/php-%{version}

%description
PHP is an HTML-embedded scripting language. Much of its syntax is
borrowed from C, Java and Perl with a couple of unique PHP-specific
features thrown in. The goal of the language is to allow web
developers to write dynamically generated pages quickly.

%prep

%setup

%build
set -x
./buildconf
./configure --prefix=/usr --with-apxs \
    --disable-debug \
    --with-xml=shared \

# figure out configure options options based on what packages are installed
# to override, use the OVERRIDE_OPTIONS environment variable.  To add
# extra options, use the OPTIONS environment variable.

#test rpm -q MySQL-devel >&/dev/null && OPTIONS="$OPTIONS --with-mysql=shared"
#test rpm -q solid-devel >&/dev/null && OPTIONS="$OPTIONS --with-solid=shared,/home/solid"
#test rpm -q postgresql-devel >&/dev/null && OPTIONS="$OPTIONS --with-pgsql=shared"
test rpm -q expat >&/dev/null && OPTIONS="$OPTIONS --with-xml=shared"

if test "x$OVERRIDE_OPTIONS" = "x"; then
    ./configure --prefix=/usr --with-apxs=$APXS $OPTIONS
else
    ./configure $OVERRIDE_OPTIONS
fi

See where it says "--with-apxs"? That is part of development interfaces for the Apache HTTP server. If that is not installed, you will get when running configure (and I believe that is what you are seeing):

Configuring SAPI modules
checking for AOLserver support... no
checking for Apache 1.x module support via DSO through APXS... 

Sorry, I was not able to successfully run APXS.  Possible reasons:

1.  Perl is not installed;
2.  Apache was not compiled with DSO support (--enable-module=so);
3.  'apxs' is not in your path.  Try to use --with-apxs=/path/to/apxs
The output of apxs follows
./configure: line 4092: apxs: command not found
configure: error: Aborting

To compile without apxs support (and thus avoiding the need for apache), you would change that to:

--without-apxs

And it will get that pass that point.

Now back to building with a spec file. if you build it with a spec file, rpmbuild will tell you what dependencies you need that will allow you to install. And from there, it will build a package for you and you can install it with:

yum localinstall php.rpm

Which will then allow you to install as well as satisfy the other requirements. That will save you lot of grief by managing your system properly with a packaging system rather than trying to build and install manually.

(or you can follow embobo's advice and install just php-cli ;) ).