What does --with-extension in php compiling do? - php

I've just learnt how to compile php modules and things but I'm unsure of something.
My OS X comes with php 5.4.17 and it seems to have various extensions in it without any .sos anywhere (pdo_sqlite, pdo_mysql, curl etc)
If I compile php --with-extension, is that extension then built into the php binaries without need for adding in php? Or something similar.
E.g. I compiled pdo_sqlite and pdo_mysql and it warned that I was trying to include them twice. I unincluded them from php.ini and checked phpinfo() and they were already enabled and nowhere on my system.
I can only assume that the configure command put them in the binaries.
Is this right?

check your phpinfo() output page, whether you have this:
Scan this dir for additional .ini files
Additional .ini files parsed
most probably pdo_sqlite and pdo_mysql are already defined in the Additional .ini files parsed
after running ./configure --with-extension, run grep Configured config.log, you will see the actual configure options used

--with-extension enables the specified extension in your custom php build.
For example
--with-apx2=/usr/local/apache2/bin/apxs
enables apache2 server installed at location /usr/local/apache2/bin/apxs

Related

How Do I load pthreads extension in CLI?

I have built both php and Apache from source on MAC OSX 10.11.
I have been having trouble loading pthreads extension in CLI.. I misunderstood how to load it and now I do not truly understand what should I do.
Here is what I have done so far.
I configured php with the following command:
'./configure'
'--prefix=/Users/username/Terminal/WebServer'
'--with-apxs2=/Users/username/Terminal/WebServer/bin/apxs'
'--enable-maintainer-zts'
'--enable-pthreads=shared'
'--enable-debug'
'--with-tsrm-pthreads'
'--with-config-file-path=/Users/username/Terminal/WebServer/ini'
'--enable-cli'
Apache's loaded Modules:
Compiled in modules:
core.c
mod_so.c
http_core.c
worker.c
So, in /Users/username/Terminal/WebServer/ini directory I created php-cli.ini file and added extension=pthreads.so line, then I ran php -m command, the following is the output:
[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
Phar
posix
<strong>pthreads</strong>
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
I restarted Apache and opened index.php file which has phpinfo() in it.
Notable information
Configuration File (php.ini) Path => /Users/username/Terminal/WebServer/ini
Loaded Configuration File => /Users/username/Terminal/WebServer/ini/php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
Thread Safety => Enabled
phpinfo() doens't include pthreads module information and I don't know whether it should or not.
at this point I open test.php file which includes the following pthreads script:
<?php $thread = new class extends Thread {
public function run() {
echo "Hello World\n";
}
};
$thread->start() && $thread->join();
?>
and the output through apache is:
Fatal error: Class 'Thread' not found in /Users/username/Sites/test.php on line 1
When I run the following command on Terminal
$ php /Users/username/Sites/test.php
The output is : Hello World
So the question is how do I load pthreads extension in CLI properly ?
You already have the desired result, but don't seem to know why ...
The key parts of your configuration are:
configure options
If PHP is being built with Apache DSO SAPI, you must use --enable-pthreads=shared, this causes the build process to create a DSO (shared object, dll in windows speak) from the pthreads library, rather than statically linking pthreads into the Apache DSO.
php.ini configuration
From the PHP manual:
If php-SAPI.ini exists (where SAPI is the SAPI in use, so, for example, php-cli.ini or php-apache.ini), it is used instead of php.ini. The SAPI name can be determined with php_sapi_name().
Having built pthreads shared (pthreads.so), we can simply create php-cli.ini in the same path as php.ini and add extension=pthreads.so to it.
What you have works, however, it's not ideal; You don't really want Apache to use a PHP interpreter that has the overhead of ZTS.
Ideally, you will want to build and install PHP twice:
First Build
configure --with-apxs=... --disable-pthreads --prefix=/system/prefix --with-config-file-path=/system/prefix/etc ...
Replace /system/prefix/ with sensible system prefix like /usr/ ...
When you make install this build, you will create the ideal installation for Apache, which includes a non-thread safe PHP binary at /system/prefix/bin/php, with all related scripts (pecl, phpize, php-config etc.) in /system/prefix/bin.
Second Build
Before this build you need to make clean (if you are using a release tarball), or vcsclean (if you are using local git repository).
configure --enable-maintainer-zts --enable-pthreads=static --prefix=/special/prefix --with-config-file-path=/special/prefix/etc ...
Replace /special/prefix/ with sensible special prefix like /opt/, do not use the same prefix as the first build ...
When you make install the first installation is not touched, instead a new installation is created without support for Apache, but with support for pthreads built statically into the binary (configuration free).
The binary will be at /special/prefix/bin/php with all related scripts in /special/prefix/bin.
Wiring Builds Together
If both builds require the same PECL extensions with the exception of pthreads, you can use the same --with-config-file-scan-dir configure switch for both builds.
If you are really brave, you could use the same --with-config-file-path switch too, but this might have undesired results.
Editing include_path for both builds will also help.

I don't see the extensions directives in php.ini, yet the extensions are loaded

So i have a php.ini for our vps where none of the extensions are defined(ie "extension=php_curl.so"), yet when i look at phpinfo() on the webpage, i see all our modules/extensions are loaded(ie, curl, mbstring, imagick etc). Where/how else can those extensions be loaded?
EDIT
Also in EashApache, in the php extensions section of your build/profile, it shows all the available extensions(enabled/or not).
I'm certain theres a master php.ini of some sort some where on the vps, or maybe the server the vps is on where all default php configurations are loaded by default.
Extensions can be compiled as shared objects which you load via an extension=... directive or (but shouldn't imho) via dl().
Extensions can also be compiled into the php core. Then they are available without further "commands".
phpinfo() gives you information about the php core in its Configure Command section, e.g.
--with-pdo-oci=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared
--with-mcrypt
The pdo_oci module is build as a shared object/dll while the mcrypt module is built into the php core.
Extensions in directory "extension_dir" (definined in php.ini) are automatically included.

symfony2 requirements cant be met

Was trying to play with symfony2. If I hit the web/config.php of my symfony2 installation it shows me the following problems
Install and enable the mbstring extension.
Install and enable the intl extension (used for validators).
Install and enable a PHP accelerator like APC (highly recommended).
Install PDO drivers (mandatory for Doctrine).
I can understand that these are not mandatory ones but question is I fixed these in my php.ini file but still cant see any reflection in this page. Here is how I fixed the above problems
extension=php_intl.dll
extension=php_mbstring.dll
extension=php_pdo_mysql.dll
Didnt install anything for APC so no complain with that. Restarted apache server "thousand" times, but no luck.
Side Note:
I tried to figure out something from phpinfo(). I can see one discrepancy. The phpinfo is showing one of my old php directory path F:\Softwares\Development\PHP\php-5.5.13-x64. This path used to exist in my system PATH variable earlier. But I myself remove this location from System PATH variable. But it is still visible in phpinfo(). But if I print the PATH variable from command prompt or cygwin console, it shows the correct PATH variable.
Also ran php app/check.php. It shows everything OK except the APC, which is completely fine for me. But it also shows that "PHP CLI can use a different php.ini file than the one used with your web server".
Environment Details:
OS: Windows 7
php: php-5.4.30-Win32-VC9-x86
Apache: Win32-2.4.9 VC9
MySQL: mysql-5.6.19-winx64
Not using any xampp/wampp etc.
Few more hear left on my head. Please help.
Make sure that you have these extensions in your ext directory, if not search and put it in the directory (for windows extension file type must be .dll).
APC https://www.dropbox.com/s/hmnrgle8xing3fo/php_apc.dll
INTL https://www.dropbox.com/s/wm14zk0grc6pm6v/php_intl.dll (you also need ICU lib)
mbstring https://www.dropbox.com/s/wm14zk0grc6pm6v/php_intl.dll
PDO mysql https://www.dropbox.com/s/hd5cm02oti8qw3s/php_pdo_mysql.dll
Also, don't forget to restart apache after changes in php.ini

PDO driver exception symfony2

im on ubuntu12.10 using xampp 1.8.1
i was working on a symfony2 project on a windows machine and im currently working on same project from ubuntu machine.
the problem is when i run commands like
php app/console doctrine:schema:update
it gives error
PDO exception:could not find driver
whereas i checked my phpinfo and pdo_mysql is enabled.also there are many select and insert queries in my project which are working fine.
also when i run php -m it shows only PDO and not pdo_mysql
is something wrong with the enviornment variable or something like that?
Its possible that the pdo_mysql extension is not enabled in your php CLI ini file.
Check your ini file for the pdo_mysql extension, you can get your ini file location from php --ini. On ubuntu it should output a list of all loaded ini files, look for
/etc/php5/cli/conf.d/pdo_mysql.ini
and
/etc/php5/cli/conf.d/pdo.ini
If either of these two ini files are not listed, then you haven't installed that extension. If they are present, then make sure they extension is enabled inside those ini files.
Make sure you enable the extensions php_pdo_mysql and php_pdo on php.ini file that your symfony project is using, check this on localhost/path_to_your_project/web/config.php
Tip: check out you Apache error log, there could be something wrong with the load of your extensions. This file is located according to your server configuration.

mongodb PHP extension not found?

I followed the manual, I mpved the php_mongo.dll into the PHP extension folder,
and added extension=php_mongo.dll to the php.ini file and it's given me an error when I try and you rockmango that "To make things right, you must install php_mongo module. Here for installation documents on PHP.net." but I have alread done this any solutions? I am running the lattest version of PHP and mongodb
Check php --ini shows the correct config file being used.
Check php -i (phpinfo) and make sure the module is actually loaded.
Double check you have the right flavour of the module for your version of PHP. (VC6, VC8, VC9, TS, NTS, etc.)
I got my mongo module (1.2.9) for PHP 5.4 32bit on windows from stealth35. It works like a charm.
Often there are multiple PHP locations with different php.ini files.
If you are worried about working in mod_php (through apache) or as a fastcgi then create a file with the following contents.
<?php phpinfo();
Then visit that file in a browser. It will have all the settings and modules listed that are currently being loaded. It will also tell you which php.ini file and modules directory being used.
Please make sure that the ini listed is the one you added mongo dll line.

Categories