php-config shell script needed - php

I want to compile extension for PHP under Windows and I need to run such command:
g++ `php-config --includes` -fPIC -c some_script.cpp
but when I run this command I received an error:
g++: error: `php-config: No such file or directory
g++: error: unrecognized option '--includes`'
where can I get php-config shell script without recompiling PHP (under Windows)

The problem is not that you don't have the script, it's that the Windows shell doesn't know what you're trying to do because it doesn't support backticks. The command wants to run the php-config script and include the output in the command, but instead g++ is being passed \php-configas the first argument, and--includes`` as the second argument, which are not valid arguments to GCC.
You can't run a UNIX shell command in Windows. Either use a UNIX-style shell (e.g. via Cygwin or Mingw32) or just use a different command, e.g. figure out what the necessary include flags are and use them:
g++ -I/some/path -fPIC -c some_script.cpp

Related

PHP app displays error about vendor libraries

I'm trying to install an app called CollectiveAccess on a subdomain, and when I enter the website it pops an error.
Your installation is missing required vendor libraries
It has an option to auto install them or change them, but when I click to change them, it pops another error:
Automatic installation of the required vendor libraries failed: Composer installation failed: Error in argument 1, char 2: option not found r; Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f ]; php-cgi [args...]; -a Run interactively; -b | Bind Path for external FASTCGI Server mode; -C Do not chdir to the script's directory; -c | Look for php.ini file in this directory; -n No php.ini file will be used; -d foo[=bar] Define INI entry foo with value 'bar'; -e Generate extended information for debugger/profiler; -f Parse . Implies `-q'; -h This help; -i PHP information; -l Syntax check only (lint); -m Show compiled in modules; -q Quiet-mode. Suppress HTTP Header output.; -s Display colour syntax highlighted source.; -v Version number; -w Display source with stripped comments and whitespace.; -z Load Zend extension .; -T Measure execution time of script repeated times.; Error in argument 1, char 2: option not found r; ERROR: Invalid installer signature
Help!! There's no info anywhere else.
Composer’s hash changes periodically. You likely have a hard coded hash the installer script is checking against, which does not match the one given. Try reading the docs on how to install programmatically here: https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md

Enable sqlite3 FTS5 for PHP

I'm trying to use SQLite3 FTS5 (full-text search) with PHP on CentOS.. but I couldn't get it successfully after so much time trying.
I'm building a loadable FTS5 Extension for SQlite and tried the following steps (from docs)
in the server terminal (SSH) :
$ yum install libsqlite3x-devel
$ wget -c http://www.sqlite.org/src/tarball/SQLite-trunk.tgz?uuid=trunk -O SQLite-trunk.tgz
$ tar -xzf SQLite-trunk.tgz
$ cd SQLite-trunk
$ ./configure && make fts5.c
$ gcc -g -fPIC -shared fts5.c -o fts5.so
But I'm having the following error in the last step:
fts5_index.c:732:11: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_index.c:732:37: error: ‘SQLITE_PREPARE_NO_VTAB’ undeclared (first use in this function)
fts5_main.c:888:29: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_main.c:1029:31: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_storage.c:139:15: error: ‘SQLITE_PREPARE_PERSISTENT’ undeclared (first use in this function)
fts5_storage.c:140:41: error: ‘SQLITE_PREPARE_NO_VTAB’ undeclared (first use in this function)
The file fts5.so is not produced so I can't use it in the server
So do you have any idea how to fix this error and produce fts5.so file successfully
I found that I have to generate header files before the last step
so the full steps looks like this:
$ yum install libsqlite3x-devel
$ wget -c http://www.sqlite.org/src/tarball/SQLite-trunk.tgz?uuid=trunk -O SQLite-trunk.tgz
$ tar -xzf SQLite-trunk.tgz
$ cd SQLite-trunk
$ ./configure
$ make fts5.c sqlite3.h sqlite3ext.h
$ gcc -g -fPIC -shared fts5.c -o fts5.so
Then I had to load the fts5.so as loadable extension for sqlite
1- Copy the fts5.so file to a new folder on server /sqlite_ext
$ mkdir /sqlite_ext
$ cp fts5.so /sqlite_ext
2- Edit sqlite3.extension_dir in php.ini to point to the same folder like this
sqlite3.extension_dir = "/sqlite_ext"
3- Then in my php file, load the extension :
$db->loadExtension('fts5.so');
Update :
It's better to update server's SQLite as a whole with --enable-fts5 option
$ wget -c https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
$ tar -xzf sqlite-autoconf-3280000.tar.gz
$ cd sqlite-autoconf-3280000
$ ./configure --enable-fts5 --prefix=/usr --disable-static CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_COLUMN_METADATA=1 -DSQLITE_ENABLE_UNLOCK_NOTIFY=1 -DSQLITE_SECURE_DELETE=1 -DSQLITE_SOUNDEX"
$ make
$ make install
Now the latest SQLite is installed for the server but not for PHP, let's do it for PHP
$ mv aclocal.m4 config.m4
$ phpize
Check for your SQLite version in server using $ sqlite3 --version and in PHP using phpinfo();
*notice: the link mentioned in the first step is for the latest sqlite-autoconf amalgamation at the time of this answer. there maybe a more recent version for you . check here

PHP exec on local script

Hello i have a PHP script, and its added to cron, it is possible to execute from this script shell command (with exec() or something) without enabling it on php.ini? I don't want to enable exec on my site
It's called PHP CLI, check here
Usually when you install php, there's option to install php_cli too.
So long you can run php on shell prompt, then it can work.
Open bash (or other shell), try this:
php -v
If the version printed, then it's working.
Then you can
php -f phpfile
or put
#!/usr/bin/php
At the beginning of your php file as a line, and chmod +x file.php, and then
./file.php
#or
/path/to/file.php
to run it.
(Note /usr/bin/php is the usual place of php executable, it might change, eg in unix is ually /bin/php. Use whereis php to check its place.)

Compile PHP extension using SWIG on Windows

I'd like to create a PHP wrapper for an existing C++ library. I found a tutorial online that uses gcc but I'd like to do the same thing using the Visual Studio command line on windows.
I started doing this:
swig -php example.i
Which worked well. Then I have to build the created wrappers as an extension. The SWIG tutorial suggests the following:
gcc `php-config --includes` -fpic -c example_wrap.c
gcc -shared example_wrap.o -o example.so
What is the VS equivalent to those two calls? I'd use cl and link instead of gcc obviously but what to put instead of 'php-config --includes'? The VS command prompt does not recognize the php-config command as well as the '--'.
Thanks for you help.
The section of that command enclosed in backticks isn't a gcc argument, per se. The expression in the backticks is evaluated by the shell, and then that expression (including the backticks) is replaced by its result before actually being executed.
In this case, php-config --includes gives the arguments gcc needs to include all the appropriate php-related headers. On my install, the result is:
I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib
That won't necessarily be valid for your computer. Just run php-config --includes to get what you what you need, take that output, and put it in the place of the 'php-config --includes' in the example you found.

PHP exec function on nginx doesn't recognize system environment variables

I try to use exec function in PHP to compile a source file with gcc with the following code.
<?php
exec("gcc -o hello hello.c 2>&1", $output, $return_value);
echo $output[0];
I got the following output when calling via web browser (I use nginx as a web server).
gcc: error trying to exec 'cc1': execvp: No such file or directory
However, if I run gcc -o hello hello.c on the command shell directly or call with php my_file.php on the shell directly, both ways compile successfully.
If I append the absolute path to gcc in my PHP code like this:
<?php
exec("/usr/bin/gcc -o hello hello.c 2>&1", $output, $return_value);
echo $output[0];
I got the following output.
collect2: fatal error: cannot find 'ld'
So, I think the problem is my webserver (nginx) doesn't know the system path environment variable to find /usr/bin which gcc and other gcc-dependencies resides in.
How can I let PHP exec function recognize system environment variables on nginx?
OS: Ubuntu 14.04
nginx: 1.6.2
PHP 5.5.9
I'm stuck on the same problem (exactly the same...) using nginx 1.10 and PHP 5.6 on Arch Linux.
The same PHP code was working on Apache/Debian.
When trying the Arch/Nginx server, I had the cc1 error... I replaced gcc by /usr/bin/gcc.... and I am now stuck on "collect2: fatal error: cannot find 'ld'"
The same compilation works with a shell... and ld is in /usr/bin. It just does not work when using "exec" in PHP.
Not satisfying (but working...) solution
By running gcc -v .....(just add -v to your compilation line) I could see :
...
COLLECT_GCC_OPTIONS='-v' '-D' 'exit=noexit' '-D' '_exit=noexit' ...
/usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/collect2 -plugin ... (<= very long line)
collect2: fatal error: cannot find 'ld'
Then I did :
cd /usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/ # <- path to collect2 (see above)
ln -s /usr/bin/ld ld
Now ld prog is available in the same dir as collect2.
And it works.
I am now looking for a better solution... :)
Set the PATH variable for PHP, as it may rely on its own environment variables and ignore the system's PATH variable.
For example, I have the following line at the bottom of my .env file:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
With this, executing gcc (without giving the full path /usr/bin/gcc) works correctly.
Duplicate of How compile GCC from php. Thought I'd post the answer here as well, since this question received a lot more attention than the other one.

Categories