Shlink - manual setup (woes & workarounds) WIP

Note: No shlink application tag is available on this forum, though it’s packaged and available.

In setting up shlink and performing manual administration steps, here’s a brief guide to errors I’ve encountered, and corrections or improvements.

Parse error / T_OBJECT_OPERATOR / `->` -> invoked with wrong php major version
root@yuno:/var/www/shlink# sudo $(cat .env) -u shlink php7.4 bin/cli api-key:generate --name first-key
PHP Parse error:  syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ')' in /var/www/shlink/config/container.php on line 27

The rest of this command comes from later tricks, the key difference here is php7.4 instead of required php8.[x]

no driver exception -> set the env

Set the env: /var/www/shlink $ sudo $(cat .env) -u shlink php8.2 bin/cli [list|api-key:generate]

api-key:generate ... relation ____ does not exist exception -> ?
root@yuno:/var/www/shlink# sudo $(cat .env) -u shlink php8.2 bin/cli api-key:generate --name first-key

In ExceptionConverter.php line 71:
                                                                                                                                 
  An exception occurred while executing a query: SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "api_keys" does not exist  
  LINE 1: INSERT INTO api_keys ("key", "name", expiration_date, enable...                                                        
                      ^                                                                                                          
                                                                                                                                 

In Exception.php line 28:
                                                                                  
  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "api_keys" does not exist  
  LINE 1: INSERT INTO api_keys ("key", "name", expiration_date, enable...         
                      ^                                                           
                                                                                  

In Statement.php line 130:
                                                                                  
  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "api_keys" does not exist  
  LINE 1: INSERT INTO api_keys ("key", "name", expiration_date, enable...         
                      ^                                                           
                                                                                  

api-key:generate [-m|--name NAME] [-e|--expiration-date EXPIRATION-DATE] [-a|--author-only] [-d|--domain-only DOMAIN-ONLY] [-o|--no-orphan-visits]

Currently working on this. bin/doctrine has orm:generate-entities command, but has not solved my problem yet. Might try a reinstall, manually (beware) or by yunohost.

progression

/var/www/shlink $ bin/cli api-key:generate
/var/www/shlink $ sudo -u shlink bin/cli api-key:generate
/var/www/shlink $ sudo -u shlink php8.2 bin/cli api-key:generate or ... bin/doctrine [list]
/var/www/shlink $ sudo $(cat .env) -u shlink php8.2 bin/cli api-key:generate

Other inquiries

My YunoHost server

Hardware: own server, in lxc container
YunoHost version: 11.2.10.3 (stable) (upgraded during this, no difference in errors)
I have access to my server : through ssh & webadmin
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no
If yes, please explain: N.A.
If your request is related to an app, specify its name and version: shlink 3.7.3~ynh1

1 Like

Ok, to generate the schemas

Commands

bin/doctrine orm:schema-tool:create

root@yuno:/var/www/shlink# sudo $(cat .env) -u shlink php8.2 bin/doctrine orm:schema-tool:create

bin/doctrine orm:validate-schema

Confirm with root@yuno:/var/www/shlink# sudo $(cat .env) -u shlink php8.2 bin/doctrine orm:validate-schema. Note, it still reported [FAIL]s to me, but also ...

Example output, noisy ignorable errors

bin/doctrine orm:validate-schema
root@yuno:/var/www/shlink# sudo $(cat .env) -u shlink php8.2 bin/doctrine orm:validate-schema

Mapping
-------

 [FAIL] The entity-class Shlinkio\Shlink\Core\Tag\Entity\Tag mapping is invalid:
 * The field Shlinkio\Shlink\Core\Tag\Entity\Tag#shortUrls is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl#tags does not contain the required 'inversedBy="shortUrls"' attribute.


 [FAIL] The entity-class Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl mapping is invalid:
 * The field Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl#visits is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Shlinkio\Shlink\Core\Visit\Entity\Visit#shortUrl does not contain the required 'inversedBy="visits"' attribute.
 * The field Shlinkio\Shlink\Core\ShortUrl\Entity\ShortUrl#deviceLongUrls is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Shlinkio\Shlink\Core\ShortUrl\Entity\DeviceLongUrl#shortUrl does not contain the required 'inversedBy="deviceLongUrls"' attribute.


 [FAIL] The entity-class Shlinkio\Shlink\Rest\Entity\ApiKey mapping is invalid:
 * The field Shlinkio\Shlink\Rest\Entity\ApiKey#roles is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity Shlinkio\Shlink\Rest\Entity\ApiKeyRole#apiKey does not contain the required 'inversedBy="roles"' attribute.


Database
--------

                                                                                                                        
 [OK] The database schema is in sync with the mapping files.                                                            
                                                                                                                        

Before a final success:

root@yuno:/var/www/shlink# sudo $(cat .env) -u shlink php8.2 bin/cli api-key:generate --name first-key

                                                                                                                        
 [OK] Generated API key: "[...uuid...]"


Ok, I also tried the INITIAL_API_KEY initialization trick that shlink mentions in their docker documentation. I’m going to remove this, and try again. Neither the uuid literally, nor the random hex string I passed as INITAL_API_KEY in the .env file are working as API keys for the Yuno/Shlink-server, from the Yuno/Shlink-webclient.

It seems more clear to me this is an issue with the shlink server not receiving requests routed – whether yunohost api frontend is not properly configured to route them, or the install process did not full set up the shlink-server portion to with all dependencies and to listen and run.

(Docs, on (not) pre-configuring servers or no pre-populating server configurations with secrets in clients.)
(For upstream developer’s recent release announcement and other thoughts, Alejandro Celaya | Blog — Software development, agile methodologies and open source software)

I generated a second api key, I see it in the database, and neither by shlink.fqdn or shlink.fqdn/api endpoints mentioned by yunohost webadmin work as servers for

To make shlink available to cli invocation on yunohost, install this:

in /var/www/shlink,
create bin/shlink with contents

#!/bin/bash

cd /var/www/shlink
sudo $(cat .env) -u shlink php8.2 bin/cli "$@"

then symlink it into /usr/local/bin
/var/www/shlink# ln -s `pwd`/bin/shlink /usr/local/bin

Then it can be called anywhere as $ shlink [args]

  • list to see commands,
  • api-key:generate,
  • api-key:list, and others.

After all this, my current status is:

  • I cannot add server to webclient. Api keys are not accepted, it seems likely the client is not able to reach the server.

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.