matiasdelellis / facerecognition

Nextcloud app that implement a basic facial recognition system.
GNU Affero General Public License v3.0
510 stars 46 forks source link

installation with php 8.2 (Nextcloud 26+) #693

Closed johnhelt closed 8 months ago

johnhelt commented 1 year ago

This is not really an issue, but I wasn't sure where to put this, so here goes:

When updating to nextcloud 26, the php is also updated to 8.2.x. This breaks the installation of pdlib inside docker! I found out as nextcloud was saying pdlib wasn't installed. The error code you receive when building with docker-php-ext-install is:

error "DLIB_NO_GUI_SUPPORT is defined so you can't use the GUI code. Turn DLIB_NO_GUI_SUPPORT off if you want to use it."

After a bit of experimentation, I propose this new recipe for building pdlib, which is needed for face recognition:

sudo apt update \
  && sudo apt install -y wget gnupg2 unzip

# install dlib

sudo apt-get install libx11-dev -y

git clone https://github.com/davisking/dlib.git
cd dlib/dlib
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install

# Install pdlib extension

wget https://github.com/goodspb/pdlib/archive/master.zip \
  && mkdir -p /usr/src/php/ext/ \
  && unzip -d /usr/src/php/ext/ master.zip \
  && rm master.zip
docker-php-ext-install pdlib-master

sudo apt-get install -y libbz2-dev
docker-php-ext-install bz2

# Increase memory limits
echo memory_limit=1024M > /usr/local/etc/php/conf.d/memory-limit.ini

# These last lines are just for testing the extension.. You can delete them.
wget https://github.com/matiasdelellis/pdlib-min-test-suite/archive/master.zip \
  && unzip -d /tmp/ master.zip \
  && rm master.zip
cd /tmp/pdlib-min-test-suite-master \
    && make

I ran the test-suite without any problems. I hope this is useful for someone here who experienced the same issues. Feel free to add this to the wiki. Thanks for a great job with the app and I hope the work is continued !

kabaga commented 1 year ago

Is this for docker instance of Nextcloud?

johnhelt commented 1 year ago

Yes, sorry for not mentioning that

kabaga commented 1 year ago

Do you know how to do if there is a similar approach for a full VM instance?

matiasdelellis commented 1 year ago

sudo apk install libpng openblas lapack wget https://github.com/matiasdelellis/pdlib/releases/download/v1.1.0/pdlib-1.1.0.tgz sudo pecl install ./pdlib-1.1.0.tgz

samssausages commented 1 year ago

@johnhelt hey thanks for this, it's the first build I found that actually works with 8.2php and nextcloud 27. I combined these instructions with the readme and was able to turn this into a dockerfile and added some other things like ffmpeg. Hopefully it helps someone.

https://github.com/samssausages/nextcloud-dlib-pdlib-ffmpeg/tree/main

P0Pss commented 1 year ago

Hey, I've tried all of the suggestions in the thread and haven't managed to get any of them working. The tests seem to go fine but whenever I try to select model 1 I always get the response that the PDlib PHP extension is not loaded. Any ideas?

samssausages commented 1 year ago

I always get the response that the PDlib PHP extension is not loaded. Any ideas?

Make sure that pdlib is referenced in your php.ini file.

check if it's loading pblib with: php -m | grep pdlib if that comes back blank, then it didn't find it as loaded.

Are you using a docker image?

The reason the instructions are conflicting online is because a lot of the instructions reference the php.ini file, but nextcloud docker doesn't have a php.ini file, it builds the file using a series of docker-php-ext-xxxx.ini files located in /usr/local/etc/php/conf.d/docker-php-xxxx.ini

If you have a php.ini file, you need to make sure it's added to your php.ini file like this:

[pdlib]
extension=\"pdlib.so\

If you don't have a php.ini file and have conf.d/docker-php-ext.ini files instead, then you need to create this file: /usr/local/etc/php/conf.d/docker-php-ext-pblib.ini

and add this code to it:

[pdlib]
extension=\"pdlib.so\

my docker file build here already includes it and so far is working for me: https://github.com/samssausages/nextcloud-dlib-pdlib-ffmpeg/tree/main

P0Pss commented 1 year ago

It is coming back blank. I am actually using your dockerfile! Maybe a stupid question, but do I need to actively make the /usr/local/etc/php/conf.d folder and create the .ini file? I tried without making it which didn't work, I then tried manually creating the folder and file, as well as adding the code to it manually. But it also didn't work. I'm wondering if I missed a step. Should it work by just adding your Dockerfile to the docker-compose.yml?

samssausages commented 1 year ago

/@P0Pss You shouldn't have to create that file/folder, it's created during the image build process. You can see if it's there by going to the command line in the docker container with this command: cat /usr/local/etc/php/conf.d/docker-php-ext-pblib.ini if its there then you should see: [pdlib] extension=\"pdlib.so\

If that's not there, check your docker build logs to make sure it's creating the .ini file. This is the section in the dockerfile that creates it:

RUN echo "[pdlib]" >> /usr/local/etc/php/conf.d/docker-php-ext-pblib.ini \ && echo "extension=\"pdlib.so\"" >> /usr/local/etc/php/conf.d/docker-php-ext-pblib.ini

So you should see something in the build log that references that.

And you also need to make sure your docker-compose file is using the correct image that you built (whatever you named it)

I uploaded the most recent image build to my dockerhub. But not sure if I'll maintain future versions on dockerhub yet. But you can try that image to see if you get a different result. It's on dockerhub with: kaisarasch/nextcloud:pdlib

P0Pss commented 1 year ago

@samssausages Thank you so much for your help!! Thanks to you I've realized I'm just stupid... I did not realize that the dockerfile should be run instead of pulling nextcloud, so I ended up running both at the same time, so I could of course find the file when running from the other container. I've fixed the problem now and it works... I've only just started using docker so really sorry about that hehe

samssausages commented 1 year ago

@P0Pss Glad you figured it out, that was actually one of the things that popped in my mind, from personal experience, haha. If you have any problems with my dockerfile or image, open an issue on my github. https://github.com/samssausages/nextcloud-dlib-pdlib-ffmpeg/tree/main

P0Pss commented 1 year ago

@samssausages Thanks, really appreciate it!

kurzer90 commented 1 year ago

Hi all, having the issue that pdlib is not running under 8.2. I'm not using docker. Tried a lot of thinks but it doesn't work. It always ends up with the following:

PHP Warning:  PHP Startup: pdlib: Unable to initialize module
Module compiled with module API=20210902
PHP    compiled with module API=20220829
These options need to match
 in Unknown on line 0

You do not meet the dependencies to install the model 1 (Default)
Summary: The PDlib PHP extension is not loaded
Please read the documentation for this model to continue: https://github.com/matiasdelellis/facerecognition/wiki/Models#model-1

Can somebody point me in the right direction?

Cebrain commented 1 year ago

@johnhelt thank you very much, configured your settings in my dockerfile and finally it is working again.

matiasdelellis commented 8 months ago

Thank you all. The application and pdlib work correctly in php 8.2 and up to nc28. šŸ˜¬ šŸ˜ƒ ā¤ļø

p.s.: Update the wiki. šŸ˜‰