Composer autoload: class not found in production, locally works

admin

Administrator
Staff member
I read a lot of threads about my problem but I can't find the correct solution.

I wrote my own wordpress plugin and used composer for it. Locally it works fine but when I upload my project onto my webserver I got an error message about class not found.

MyOwnHooks not found in /wp-content/plugins/my-own-hooks/myownhooks.php.

Directory of my repository:

<ul>
<li>wp-content/

<ul>
<li>plugins/

<ul>
<li>my-own-hooks/

<ul>
<li>vendor/</li>
<li>inc/

<ul>
<li>php/

<ul>
<li>MyOwnHooks.php</li>
<li>GoogleContactsHelper.php</li>
<li>MyContact.php</li>
<li>MyPhoneNumber.php</li>
</ul></li>
</ul></li>
</ul></li>
<li>myownhooks.php</li>
</ul></li>
</ul></li>
</ul>

Code:
/wp-content/plugins/my-own-hooks/myownhooks.php
:



Code:
/**
 * Plugin Name: MyOwnHooks
 */
require_once ("vendor/autoload.php");

futur22\MyOwnHooksPlugin\MyOwnHooks::runner ();

Code:
/wp-content/-plugin/my-own-hooks/inc/php/MyOwnHooks.php
:

Code:
&lt;?php

namespace futur22\MyOwnHooksPlugin;

class MyOwnHooks {

    public function init() {
        \add_action ( 'wp_head', array (
                $this,
                'moh_incomplete_profile_script_code'
        ) );
    }

    public static function runner() {
        $pluginx = new MyOwnHooks ();
        $pluginx-&gt;init ();
    }

    public function moh_incomplete_profile_script_code() {
        // print something
    }
}

Code:
/wp-content/plugins/my-own-hooks/composer.json
:

Code:
{
    "require" : {
        "rapidwebltd/php-google-people-api" : "^1.0"
    },
    "autoload" : {
        "psr-4" : {
            "futur22\\MyOwnHooksPlugin\\" : "inc/php"
        }
    }
}

It is confusing that it works locally with XAMPP, but not on the Linux system. Everytime I change code and pull it from repository I delete composer.lock and vendor directory to run
Code:
composer install
.

XAMPP and production server have PHP 7.3.x.

What's wrong here?

Thanks for help.