On my local environment everything works fine, but on my production server files from my/src
folder are not autoloaded by composer. I get the following error:
Warning: require(/home/customer/www/example.com/public_html/wp-content/plugins/example-plugin/vendor/composer/../../src/Commands/Example_Commands.php): Failed to open stream: No such file or directory in /home/customer/www/example.com/public_html/wp-content/plugins/example-plugin/vendor/composer/autoload_real.php on line 55
The file really exists (I checked it multiple times), but it looks like production cannot require a path like:
/home/customer/www/example.com/public_html/wp-content/plugins/example-plugin/vendor/composer/../../src/Commands/Example_Commands.php
But only:
/home/customer/www/example.com/public_html/wp-content/plugins/example-plugin/src/Commands/Example_Commands.php
On my local environment I removed already my/vendor
folder andcomposer.lock
file and ran the following commands:
> composer dump-autoload
and
> composer install --no-dev
My project folder looks like this:
resources
src
- Commands
- Example_Commands.php
- Other_Class.php
- Another_Class.php
vendor
- composer
- ..other composer files
- autoload_real.php
- ..other packages
composer.json
composer.lock
plugin-index.php
My composer.json looks like this:
{
"require": {
"illuminate/encryption": "^9.33",
"wp-cli/wp-config-transformer": "^1.3",
"azurre/php-simple-logger": "^1.1"
},
"autoload": {
"files": [
"src/User.php",
"src/Utils.php",
"src/Config_Checker.php",
"src/Admin_Notices.php",
"src/ACF.php",
"src/Commands/Example_Commands.php",
"src/Service_Logic.php",
"src/Cron.php",
"src/Email.php"
]
}
}
In my plugin-index.php (the first file loaded) I start autoloading like this:
require_once(plugin_dir_path(__FILE__) . 'vendor/autoload.php');
To be clear; I ran the composer commands on my local machine and uploaded the project to the production server.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.