Issue setting up PHP on Virtuoso Server - php

I have a Virtuoso server running on Centos7 and have been trying to be able to execute PHP files from an HTML form (even really basic ones just to test), and have had no luck. I found out I had to install PHP and have been reading the documentation from the virtuoso GitHub README.php5 to setup PHP on the virtuoso server. This is my first time setting up PHP and I have run into an issue when trying to run the make command. I am in directory /etc/php-5.2.10 and have been able to run the configure command with all the flags. The error from the make command I receive is:
/bin/sh /etc/php-5.2.10/libtool --silent --preserve-dup-deps --mode=compile
/etc/php-5.2.10/meta_ccld -I/usr/local/iODBC/include -Iext/odbc/ -I/etc/php-5.2.10/ext/odbc/
-DPHP_ATOM_INC -I/etc/php-5.2.10/include -I/etc/php-5.2.10/main -I/etc/php-5.2.10
-I/usr/local/iODBC/include -I/etc/php-5.2.10/ext/date/lib -I/usr/include/libxml2
-I/etc/php-5.2.10/ext/mbstring/oniguruma -I/etc/php-5.2.10/ext/mbstring/libmbfl
-I/etc/php-5.2.10/ext/mbstring/libmbfl/mbfl -I/etc/php-5.2.10/TSRM -I/etc/php-5.2.10/Zend
-D_REENTRANT -I/usr/include -g -O2 -pthread -DZTS
-c /etc/php-5.2.10/ext/odbc/php_odbc.c -o ext/odbc/php_odbc.lo
In file included from /etc/php-5.2.10/ext/odbc/php_odbc.c:37:0:
/etc/php-5.2.10/ext/odbc/php_odbc_includes.h:104:22: fatal error: iodbcext.h:
No such file or directory
#include <iodbcext.h>
^
compilation terminated.
make: *** [ext/odbc/php_odbc.lo] Error 1
I do not know if these packages are related but for extra information, I have the following packages installed as well:
libiodbc.x86_64 3.52.7-7.el7
libiodbc-devel.x86_64 3.52.7-7.el7
php-odbc.x86_64 5.4.16-36.el7_1
unixODBC.x86_64 2.3.1-10.el7
unixODBC-devel.x86_64 2.3.1-10.el7
I have run sudo find / -iname '*iodbcext.h*' to try and determine where that file may be located and the only result I get back is /usr/include/libiodbc/iodbcext.h. However, I am not sure if that is what make is looking for or if there is supposed to be another one within the php-5.2.10 directory that is used, and if that is the right one, what would I do with it?
Any assistance or advice in getting PHP setup on the Virtuoso server is greatly appreciated.

You have conflicting packages installed, for the iODBC and unixODBC driver managers. It is strongly advised that you choose one or the other. Given that you're using Virtuoso (from my employer, OpenLink Software), I'd advise that you settle on iODBC (also maintained and supported by OpenLink Software, and generally expected to be found by Virtuoso).
PHP doesn't include the iODBC SDK (libiodbc-devel.x86_64), which is where the header file iodbcext.h would be found. I should note that the current version of iODBC is 3.52.10, somewhat later than the package you've installed...
It's not clear what options you passed to configure to get the make script you're running. You may be able to get past the error reported above by editing the second occurrence of -I/usr/local/iODBC/include in the make script, changing it to -I/usr/include/libiodbc ... but this is something of a guess.

Related

Custom PHP Extension Cross Compatibility

I am building my first PHP Extension using https://www.zend.com/resources/writing-php-extensions as a roadmap and running into some interesting (to me) issues.
Installed on the server is PHP 7.2, but the current master version is 7.4. I copied the php-src-master onto the server and do the first step of php ext_skel.php --ext test --dir and then
# phpize
# ./configure
# make
I then get this error:
/bin/bash /root/php-src-master/ext/test/libtool --mode=compile cc -I. -I/root/php-src-master/ext/test -DPHP_ATOM_INC -I/root/php-src-master/ext/test/include -I/root/php-src-master/ext/test/main -I/root/php-src-master/ext/test -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-src-master/ext/test/test.c -o test.lo
libtool: compile: cc -I. -I/root/php-src-master/ext/test -DPHP_ATOM_INC -I/root/php-src-master/ext/test/include -I/root/php-src-master/ext/test/main -I/root/php-src-master/ext/test -I/usr/include/php/20170718 -I/usr/include/php/20170718/main -I/usr/include/php/20170718/TSRM -I/usr/include/php/20170718/Zend -I/usr/include/php/20170718/ext -I/usr/include/php/20170718/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /root/php-src-master/ext/test/test.c -fPIC -DPIC -o .libs/test.o
In file included from /root/php-src-master/ext/test/test.c:10:0:
/root/php-src-master/ext/test/test_arginfo.h:8:2: warning: implicit declaration of function ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE [-Wimplicit-function-declaration]
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, str, IS_STRING, 0, "\"\"")
If I download the src for 7.2, then everything works just fine. I guess I am surprised because I haven't edited any code at all at this point, so I would think this is the equivalent of a Hello World system, which seems like it would have ultimate compatibility between versions and so wouldn't throw an error unless I was calling functions that didn't exist in the installed version. If that is true and a "new" function is being called that wasn't in 7.2, it seems weird that a basic skeleton would be utilizing functions that didn't exist in 7.2 to display "Hello World".
If I were to create and compile in 7.2, would I later be able to compile in 7.4? If I compile in 7.4, will I be able to use it in 7.2?
The extensions I want to build will have very simple jobs, but ones that need to be done rapidly and frequently. Things like formatting phone numbers, filtering json, processing recursive tree relationships, and so on.
Having seen this compatibility issue, I am curious if this is going to lock me into using a specific version of PHP where even when I am not trying to use any new functions in my code, I still have to rewrite it every time we upgrade PHP in the coming years.
The skeletons for a specific PHP version branch may use functionality/internal APIs introduced in said version, if you want to build an extension compatible with a lower PHP version you should work from the PHP extension skeleton of said PHP version, not on from a more recent one.

Compiling C from PHP with exec error trying to exec 'cc1'

I am trying to compile a C program from PHP with exec, and with the Laravel Framework. But I dont think this is the problem, because I can compile and execute C programs from terminal without problems. And if you know from tinker in Laravel 5, so the problem is from PHP. But I can`t find the error I think the problem is form different versions of GCC but why let me compile from terminal.
I get this error when I do that from PHP. If I compile from terminal it works but from php not.
$path = public_path("testing/cosas.out");
exec("gcc testing/pruebaC.c -o testing/from.out 2>&1",$output,$status);
dd($output,$status); //is like var_dump
AND I GET THIS !!
gcc: error trying to exec 'cc1': execvp: No such file or directory"
I checked the permissions and are right (in fact I did chmod 777 in my desperation).
Also I tried to reinstall everything, but it does not work.
The problem is that your application when invoked through a browser functions through the user that is processing the Apache instance. If this is not the root (or another privileged user), then it may not have access. Also, this will likely dictate what directory the application attempts to execute from.
When you execute from the CLI, the user is whomever owns the instance of the terminal (unless su'd of course).
Here's a minimal example of how to make this work:
First, create a new directory and cd to it. In that directory, create index.php with this content:
<?php
exec("gcc /var/www/html/test.c -o /tmp/a.out 2>&1",$compile_output,$compile_status);
var_dump($compile_output);
var_dump($compile_status);
exec("/tmp/a.out 2>&1",$run_output,$run_status);
var_dump($run_output);
var_dump($run_status);
?>
And create test.c with this content:
#include <stdio.h>
int main(void) {
puts("Hello from C compiled by PHP!");
return 0;
}
Then do docker run -p 8080:80 -v /whatever/directory/you/created:/var/www/html php:apache. Finally, go to http://localhost:8080 and the PHP script will compile and run that C program.
If this works in Docker but not in a "real" environment, then your environment is somehow set up incorrectly. In particular, check the PATH to make sure you're using the gcc that you think you are, and check the output of gcc -print-search-dirs and make sure that cc1 can indeed be found somewhere that it's looking.
If it works from the terminal but not from PHP, then put the debugging commands in the PHP script until you find the difference that's breaking it.
If you're missing cc1 entirely, then do sudo apt --reinstall install build-essential, or whatever the equivalent is to reinstall gcc and its dependencies on your distro.

[RIAK-PHP-CLIENT]: Installing issues from github repository (./config)

beginner with linux here but I am trying to follow some simple instructions for setting up a riak-php-client that will enable me to make my riak database and website communicate, i.e. fetch and display data to the website. The github repository of which I'm following:
https://github.com/basho/riak-php-client
I clone the repository, but at "Quick start" when trying to run
user#user-pc:~/riak-php-client $ ./config --with-curl
I end up getting the message "bash: ./config: No such file or directory", same story when I'm in home/riak-php-client/src. Any ideas on how to fix this?
The instruction to run
./configure --with-curl
is intended to show you how to enable curl in your local build of PHP, when compiling PHP from source. The readme doesn't make that very clear.
The command
php -m | grep curl
will return 'curl' if your local PHP installation has curl enabled, if it is, just continue on with the examples in the readme. If not there are other questions on stack overflow like this one that may help

node.js through FastCGI/PHP: Error: Cannot find module 'less'

I installed node.js from sources (./configure && make && make install) under /usr/local/bin/node. Afterwards I installed the less compiler globally with npm -g install less under /usr/local/lib/node_modules/less/. So node and less are located under their default paths.
I am using kriswallsmith/assetic to compile my less files through PHP, therefore I adjusted path to /usr/local/bin/node. Everytime I run my script I get the error Error: Cannot find module 'less', I had the same behavior through command line. But I found a solution (ln -s /usr/local/lib/node_modules/ ~/.node_libraries) to fix the problem and after this it worked out on command line. Through PHP the problem still persists - PHP is running through FastCGI with the same user I used on command line.
How can I fix this problem through FastCGI/PHP too?
Constructor of assetic's LessFilter accepts an array of nodePaths. Adding /usr/local/lib/node_modules/ as a nodePath solves the problem.

Installing RabbitMQ PHP: Fatal error: Class 'AMQPConnection' not found

I've already installed the RabbitMQ on my server and everything is working fine with it. I already tried to send and receive queued messages with a Java client and everything went perfect.
Now I need to install a PHP RabbitMQ client because I want to communicate a Java program with a PHP webpage, but this time I'm not beign so lucky.
I already followed the steps of the official webpage for this installation, specifically these steps:
# Download the rabbitmq-c library
hg clone http://hg.rabbitmq.com/rabbitmq-c/rev/3c549bb09c16 rabbitmq-c
cd rabbitmq-c
# Add the codegen requirement
hg clone http://hg.rabbitmq.com/rabbitmq-codegen/rev/f8b34141e6cb codegen
# Configure, compile and install
autoreconf -i && ./configure && make && sudo make install
And actually on the console I can see that it was "installed" without any problems. But when I try to open any AMQP Connection I get this error:
Fatal error: Class 'AMQPConnection' not found
Actually if I use the phpinfo(); command I can't see anything related to an AMQP module (like in this question). So I think that it may be a problem with the installation but I tried reinstalling it two times and it keeps saying that everything went well.
Have anyone crossed with this problem too?
Solved it..
The module wasn't being loaded in the right php.ini file. Just added extension=amqp.so at the end of the right php.ini file and restarted Apache.

Categories