Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installation Error on OS X 10.11.6 #36

Closed
WalkerPnD opened this issue Jan 17, 2017 · 21 comments
Closed

Installation Error on OS X 10.11.6 #36

WalkerPnD opened this issue Jan 17, 2017 · 21 comments

Comments

@WalkerPnD
Copy link

WalkerPnD commented Jan 17, 2017

Hi, @deuill . I'm making a portable server to help my graphic designers friends on FrontEnd development with golang/echo framework. https://github.com/walker-walks/quick_serv
They said it would be useful if the server executes php files. so I was trying to call and execute php from go in a way I don't have License problem..

So I'm trying to use go-php library but
I'm having the same issue with some people when I'm doing go get.

engine/context.go:11:11: error: 'main/php.h' file not found with <angled> include; use "quotes" instead
 #include <main/php.h>
          ^~~~~~~~~~~~
          "main/php.h

I don't know if it's correct but, I downloaded the php source file and put the php-7/main into go-php/engine/main and passed this part and them appeared another error which is.

In file included from engine/context.go:11:
./main/php.h:35:10: fatal error: 'zend.h' file not found
#include "zend.h"
         ^

I moved all the files were in php-7/Zend to go-php/engine/main. and Now I have the issue below that I can't understand.

In file included from engine/context.go:11:
In file included from ./main/php.h:35:
In file included from ./main/zend.h:31:
In file included from ./main/zend_types.h:27:
./main/zend_portability.h:48:11: fatal error: 'zend_config.h' file not found
# include <zend_config.h>

I wold be very happy if you could give me any suggestions.
thanks.

@deuill
Copy link
Owner

deuill commented Jan 18, 2017

Hi @walker-walks, in order to get this compiled, you need to have php installed as a library.

To do this on MacOS, you need to get Homebrew installed, if you haven't yet, then install PHP:

brew install -v homebrew/php/php70 --enable-embed=shared

However, I haven't tested this on MacOS so YMMV. You will most likely need to add the full path to the include/php7 directory that Brew uses into the php7.go file, or wait for a branch for adding MacOS support.

@WalkerPnD
Copy link
Author

I installed php shared library and added the full path.
now the error appears like this.

# github.com/deuill/go-php/engine
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:8:72: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static zval *_receiver_get(zval *object, zval *member, int type, const zend_literal *key);
                                                                       ^~~~~~~~~~~~
                                                                       zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
  ^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:9:74: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static void _receiver_set(zval *object, zval *member, zval *value, const zend_literal *key);
                                                                         ^~~~~~~~~~~~
                                                                         zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
  ^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:10:74: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static int _receiver_exists(zval *object, zval *member, int check, const zend_literal *key);
                                                                         ^~~~~~~~~~~~
                                                                         zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
  ^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:13:86: error: unknown type name 'zend_literal'; did you mean 'zend_label'?
static zend_function *_receiver_method_get(zval **object, char *name, int len, const zend_literal *key);
                                                                                     ^~~~~~~~~~~~
                                                                                     zend_label
/usr/local/Cellar/php70/7.0.7/include/php/Zend/zend_compile.h:179:3: note: 'zend_label' declared here
} zend_label;
  ^
In file included from engine/engine.go:14:
In file included from include/receiver.h:15:
include/php5/_receiver.h:17:8: error: unknown type name 'zend_object_value'
static zend_object_value _receiver_init(zend_class_entry *class_type);
       ^
5 errors generated.

@deuill
Copy link
Owner

deuill commented Jan 19, 2017

Did you build with -tags php7?

i.e.:

go build -tags php7

Unfortunately, you'll have to pass that in any build command that includes go-php, even things that just include it as a dependency. PHP 7.x has been out for a while now, though, so I may just change the default and have PHP 5.x require a tag instead.

@WalkerPnD
Copy link
Author

I was not using build tags.
With -tags php7
appears like below.

github.com/deuill/go-php/engine
# github.com/deuill/go-php/engine
In file included from engine/context.go:12:
include/context.h:17:10: fatal error: '_context.h' file not found
#include "_context.h"
         ^
1 error generated.

@deuill
Copy link
Owner

deuill commented Jan 19, 2017

I believe you may have accidentally removed the following:

#cgo CFLAGS: -Iinclude/php7 -Isrc/php7

Which defines the include paths for the local PHP 7.x headers.

@WalkerPnD
Copy link
Author

I did the whole process from downloading the "go-php" library and I've got the same error message.

In file included from engine/context.go:12:
include/context.h:17:10: fatal error: '_context.h' file not found
#include "_context.h"
         ^
1 error generated.

I'm thinking that OS X version of php is very strange because instead of installing in include/php7 dir it's installed in /usr/local/Cellar/php70/7.0.7/include dir (maybe cos the rootless problem?).
And I couldn't find _context.h file in any version of php installed.

@deuill
Copy link
Owner

deuill commented Jan 20, 2017

The _context.h file is a local include here, and does not belong to PHP itself, hence why you need those relative paths I commented on above, in addition to the absolute paths to /usr/local/Cellar/php70/7.0.7/include etc.

I'll see if I can find a MacOS machine to test support on.

@WalkerPnD
Copy link
Author

I think I got that part.. Now I have another message.
Let me organize what I've done until now.

At first when I just finished to download and do go build -tags php7 I get this message.

# github.com/deuill/go-php/engine
engine/context.go:11:11: fatal error: 'main/php.h' file not found
 #include <main/php.h>
          ^
1 error generated.

so I change engine/context.go file's import with full path

// #cgo CFLAGS: -I/usr/local/Cellar/php70/7.0.7/include/php -I/usr/local/Cellar/php70/7.0.7/include/php/main -I/usr/local/Cellar/php70/7.0.7/include/php/TSRM
// #cgo CFLAGS: -I/usr/local/Cellar/php70/7.0.7/include/php/Zend -Iinclude

The new part is here. this is the new message I've got.

github.com/deuill/go-php/engine
# github.com/deuill/go-php/engine
engine/engine.c:43:10: warning: enumeration values 'SAPI_HEADER_DELETE_ALL' and 'SAPI_HEADER_SET_STATUS' not handled in switch [-Wswitch]
# github.com/deuill/go-php/engine
engine/receiver.c:79:1: warning: control reaches end of non-void function [-Wreturn-type]
# github.com/deuill/go-php/engine
engine/value.c:121:47: warning: incompatible pointer types passing 'unsigned long *' to parameter of type 'zend_ulong *' (aka 'unsigned long long *') [-Wincompatible-pointer-types]
include/php7/_value.h:14:87: note: passing argument to parameter 'num_index' here
# github.com/deuill/go-php/engine
ld: library not found for -lphp7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@deuill
Copy link
Owner

deuill commented Jan 20, 2017

You're getting there! Final piece (hopefully) would require that you go into php7.go and change that line to this (or similar):

// #cgo LDFLAGS: -L/usr/local/Cellar/php70/7.0.7/lib -lphp7

I assume that's where Homebrew installs the PHP libraries.

@WalkerPnD
Copy link
Author

The lib path is that you wrote.
I'm tried adding the path but doesn't compile. so I tried changing the depth of the path like
<path from root>/lib, <path from root>/lib/php, <path from root>/lib/php/build but still getting the same message.

@deuill
Copy link
Owner

deuill commented Jan 20, 2017

It may be that Homebrew installs the libraries as libphp.so and not libphp7.so. Check the relevant folders and see what the name of the .so libraries are. The convention is, a -lphp7 declaration corresponds to a file named libphp7.so, and so forth.

@WalkerPnD
Copy link
Author

inside lib dir looks like this

/lib
└── php
    └── build
        ├── Makefile.global
        ├── acinclude.m4
        ├── config.guess
        ├── config.sub
        ├── libtool.m4
        ├── ltmain.sh
        ├── mkdep.awk
        ├── phpize.m4
        ├── run-tests.php
        ├── scan_makefile_in.awk
        └── shtool

next lib dir there is a libexec dir which contains apache2/libphp7.so
So I tried variations like

// #cgo LDFLAGS: -L/usr/local/Cellar/php70/7.0.7/libexec/ -lphp7
// #cgo LDFLAGS: -L/usr/local/Cellar/php70/7.0.7/libexec/apache2 -lphp7

but results the same.

@deuill
Copy link
Owner

deuill commented Jan 20, 2017

Bah, how stupid. It appears that Homebrew does not support building PHP as a shared library. I assumed passing the --enable-embed=shared option, which works for the PHP source, would be passed in and the libraries installed correctly; it is not.

These are your choices:

  • Fix the Homebrew recipe for php-embed.
  • Build and install PHP from source with the above option, in which case you probably don't need the path hacks above. There's probably some tutorial out there to help out.
  • Build and develop in a Linux container/VM.

@WalkerPnD
Copy link
Author

yah, actually I couldn't notice that. brew didn't give me any feedback..
I don't understand properly about brew.
And I guess docker/VM will not help much. I heard cgo has cross compile difficulty.
I'm going to try compiling from source.

@WalkerPnD
Copy link
Author

hi, I built php from source. Now I have embed lib files but still I have a similar message.
I'm thinking to give up and look for another away.

engine/engine.c:43:10: warning: enumeration values 'SAPI_HEADER_DELETE_ALL' and 'SAPI_HEADER_SET_STATUS' not handled in switch [-Wswitch]
engine/engine.c:97:2: warning: incompatible pointer types initializing 'void (*)(char *, int)' with an expression of type 'void (char *)' [-Wincompatible-pointer-types]
# github.com/deuill/go-php/engine
engine/receiver.c:79:1: warning: control reaches end of non-void function [-Wreturn-type]
# github.com/deuill/go-php/engine
engine/value.c:121:47: warning: incompatible pointer types passing 'unsigned long *' to parameter of type 'zend_ulong *' (aka 'unsigned long long *') [-Wincompatible-pointer-types]
include/php7/_value.h:14:87: note: passing argument to parameter 'num_index' here
# github.com/deuill/go-php/engine
ld: library not found for -lphp
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@aaxx
Copy link

aaxx commented Jan 25, 2017

Hi guys, how did you succeed to build PHP from source on OS X with "--enable-embed=shared"? I constantly got bunch of errors like this:

clang: error: ext/date/php_date.o: No such file or directory

Tried different ways but still no luck.

@deuill
Copy link
Owner

deuill commented Jan 26, 2017

I'm not sure if PHP can be built with Clang. If anything, there's probably documentation out there on how to build.

The real outcome of this is I should probably provide binary packages built against PHP statically, but I need to confirm with the PHP license before I can do that.

@aaxx
Copy link

aaxx commented Jan 26, 2017

I built with gcc-6 too, there are some problems with .o / .dyld file locations on OS X when building with "--enable-embed=shared" option. It is a known bug at PHP.net, but nobody cares. If you could, please release static binary, because "shared PHP" is quite hard to achieve on OS X.

Thanks a lot for the package though :)

@WalkerPnD
Copy link
Author

Hi, I could build PHP on Mac but the problem was to link these files and build with go.
now I'm going to look for a way to link ".so" files. I'm not sure if it's possible but could be another way.
thanks for the help @deuill

@aaxx
Copy link

aaxx commented Jan 29, 2017

@walker-walks Could you tell how did you compile the PHP in shared mode on OS X, please?

@WalkerPnD
Copy link
Author

WalkerPnD commented Jan 29, 2017

Hi @aaxx . To be honest I don't remember exactly. I mixed up some tutorials to do that.
This is what I remember.

  1. Download PHP source file from the official.

PHP Download

  1. configure the make file with build options. like below.
./configure \
  --enable-mod-charset \
  --with-config-file-path=/etc \
  --with-apxs2=/usr/sbin/apxs \
  --disable-cgi \
  --with-libexpat-dir=/usr \
  --with-libxml-dir=/usr \
  --with-openssl \

these options are just an example, for detail you can check here.

PHP Build options

  1. after configuring make file you do make, make test and make install.

I think it was something like this.

borancar pushed a commit to borancar/go-php that referenced this issue Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants