Doctrine error: "Failed opening required '/tmp/__CG__Source.php' " - php

I am trying to migrate my PHP application to an Ubuntu server, but without succes. Any help would be appreciated.
First I installed Doctrine successfully into /jorrit/myapp, following the first part of Doctrine's Getting Started manual (till "Generating the Database Schema"). Secondly I placed my PHP scripts (which use Doctrine) in folder /jorrit/myapp.
When I try to run my PHP script in the CLI, I get this error messages:
PHP Warning: require(/tmp/__CG__Source.php): failed to open stream: No such file or directory in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200
PHP Fatal error: require(): Failed opening required '/tmp/__CG__Source.php' (include_path='.:/usr/share/php:/usr/share/pear') in /jorrit/myapp/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php on line 200
Bootstrap.php looks like this:
<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = false;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'xx',
'user' => 'xx',
'password' => 'xx',
'dbname' => 'xx',
'profiler' => 'false'
);
// obtaining the entity manager
$entityManager = EntityManager::create($dbParams, $config);
?>
The first lines of my PHP script:
<?php
require_once "bootstrap.php";
require_once 'classes.php';
$connection = $entityManager->getConnection();
The application works fine in my development environment (Windows). The /tmp folder exists and is accessible. The database is migrated succesfully and exists. I did not change anything in the vendor folder.
Any ideas? Thanks in advance for your help.

TL;DR You'll just need to generate your proxy classes manually
vendor/bin/doctrine orm:generate-proxies
Doctrine uses Proxies to connect the to database. Proxies are generated from the the Entity classes.
In development mode, it generates a Proxies on every request because you could make changes to Entity classes.
In production mode, it does not generate Proxies every time. For performance reason, it assumes the Proxies exist and include them directly.
There are a few mode for Proxies generation:
ALWAYS - It alwayes generates Proxies, this is the default setting for development mode
NEVER - It never generates Proxies, this is the default setting for production mode
ON_DEMAND - It only generates the Proxies if the Proxy files do not exist. The drawback of this option is that it has to call file_exists() every time which could potentially cause a performance issue.
Now the command
vendor/bin/doctrine orm:generate-proxies
generates Proxy classes to /tmp. I would say this might still cause trouble because other applications
on your server might delete these files unexpectedlly. One option is you can change your /tmp directory access permission to 1777
sudo chmod 1777 /tmp
The stricky bit '1' in front of 777 means that, although everyone can read/write to the /tmp directory, but you can only operate on your own files. i.e. You can't remove files created by other users.
For further reading, please have a look at
http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#auto-generating-proxy-classes-optional
You can also set the Proxies directory to somewhere else so no other applications can modify them. http://docs.doctrine-project.org/en/latest/reference/advanced-configuration.html#autoloading-proxies

In code after $config line you could try
$config->setAutoGenerateProxyClasses(true);
But the CLI version is much better, because it avoids on refresh regen as in code might not avoid.
To change cache dir you could try:
$cacheDir = dirname(__FILE__).'/cache';
if (!is_dir($cacheDir)) {
mkdir($cacheDir);
}
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, $cacheDir);

Looks like a permission problem, first should chek on permissions for the entire application folder.
Also try to hard-cleanup cache by deleting app/cache/* files, and try again.
Good luck!

Related

CodeIgniter 4 - Multiple Databases Problem with .env file

I am using CodeIgniter 4.0.3. I've installed it using composer via:
composer create-project codeigniter4/framework
Got one error after the composer project creation was finished (Script bash admin/setup.sh handling the post-update-cmd event returned with error code 127 --- running on Windows 10), but quickly resolved it by editing the composer.json and removing the bash admin/setup.sh directive
I've successfully followed up the tutorial and after that, I decided to make some changes to make it more similar to my web-app requirements, such as adding multiple databases.
Starting with the documentation (here and here), I read that I have to modify my .env file. So, here was the original
# ORIGINAL .env
database.default.hostname = localhost
database.default.database = ci4
database.default.username = root
database.default.password =
database.default.DBDriver = MySQLi
And I wanted to do something like:
# MODIFIED .env
database.primary.hostname = localhost
database.primary.database = ci4primary
database.primary.username = root
database.primary.password =
database.primary.DBDriver = MySQLi
database.secondary.hostname = localhost
database.secondary.database = ci4secondary
database.secondary.username = root
database.secondary.password =
database.secondary.DBDriver = MySQLi
Next, in my Model I have called Database to connect via:
use Config\Database;
...
$dbPrimary = Database::connect('primary');
$dbSecondary = Database::connect('secondary');
When I run the app, I get the following error:
InvalidArgumentException primary is not a valid database connection group
I don't know what else to do, I tried various edits of the .env file, tried debugging the Config class (which I think it does not load the primary nor the secondary subkeys --- nor do I have any idea on how to change the class to read them from my environment file).
Quick checklist:
env file has been moved to .env
both ci4primary and ci4secondary databases exist and have the proper tables with data
database credentials are ok
CI environment is set to development
The database connection groups in the .env file must also exist in the app/Config/Database.php file. By default only the default and tests connection groups are defined.

How can I use Laravel's Storage to download files from a remote SFTP server?

I'm writing an artisan command in Laravel 5.5. There are files in an AWS EC2 instance and all within the same folder, my command needs to download all those files into a local storage/folder.
I went through the Laravel's documentation but couldn't find helpful info. I have added a disk into my filesystem config file for my local storage/folder access, as well as a disk for my AWS SFTP server.
Previously I've been doing this using the phpseclib but would like to move on using Laravel in Laravel way.
I've tried the following:
Storage::disk('aws')->get('path/filename.ext');
which throws the following exceptions:
In FilesystemAdapter.php line 109:
path/filename.ext
and
In Filesystem.php line 388:
File not found at path: path/filename.ext
but I can see the file is there and my program can download it, and actually all of them using phpseclib.
and also tried the following which returns an empty array:
Storage::disk('aws')->files('folder-name');
and aws is the disk I've defined in the filesystem config file as follows:
'aws' => [
'driver' = 'ftp',
'host' = '12.123.123.12',
'username' = 'myusername',
'password' = 'mypassword'
]
Thank you!

ZF3 Development Mode VS Production Mode

I use ZF3 and code in the development mode. I configured it like the tutorial suggests:
composer development-enable
So everything works fine if this mode is enabled. If I disable it I get a database connection error, like this one:
Connect Error: SQLSTATE[HY000] [1044] Access denied for user
''#'localhost' to database 'xyz'
I still work on the same computer.
So what error it might be?
The main topic would be, how is the right way to change between development and production, does the composer statement also make clear to use the production configfiles?
If I have changed the mode via composer, what do I have to do additional? I really blueeyed thought, it would be enough to just disable:
composer development-disable
Do I have to rename the development config files also? Of which files do we talk about? Is it just application-config.php and development-config.php?
Where and how should I place the different database connections? I now use the files you see above.
And last, how to change the mode on the production server? I now just disabled the mode on my developmentsystem and then uploaded the hole project. Afterwards I only upload the changed files.
EDIT1: Here additional a screensot, which configuration files I use in which folders:
In my application.config.php the configuration links to:
'config_glob_paths' => [
realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php',
],
and in my development.config.php the configuration links to
'module_listener_options' => [
'config_glob_paths' => [realpath(__DIR__) . '/autoload/{,*.}{global,local}-development.php'],
'config_cache_enabled' => false,
'module_map_cache_enabled' => false,
],
for me it looks correct. My database connection is in local.php (for the production) and in local-development.php (for the development mode).
Enabling/Disabling the mode is just the same as having/not having the config/development.config.php file.
If you look closely, you'll see that the development mode disables the cache.
Your problem is that the cache files have been created (non dev mode) while the configuration wasn't fine for the environment. Remove data/cache/application.config.cache and application.module.cache as configured in config/application.config.php.
If you use development-mode enable (Development) it mean config_cache_enabled set to false. So your new configuration like module, services, controllers, etc will load by ZF3, because ZF3 will not read the configuration from cache (in data/cache/*).
If development-mode disable (Production) configuration will be cached, so when you deploy your code with new configuration like I mention above, will not read by ZF3. Because ZF3 still read the configuration in cache.
I usually remove the cache when deploying to Production. Here the sample shell script I used for deploying
#/bin/bash
rsync --exclude data --exclude .git -av temp_example.com/. /var/www/example.com/.
echo -e "Removing cache..."
rm -f /var/www/example.com/data/cache/*.php
So, the main key, if you used development-mode disable, just remove the cache after deploying the code.

Using local google Datastore with dev_appserver.pyp

At the moment I am able to write to the datastore once I deploy my code, but I can't write to the datastore emulator with code running locally since it throws a ca-bundle error. The local datastore is visible at localhost:8000
use google\appengine\api\users\User;
use google\appengine\api\users\UserService;
use google\appengine\api\app_identity\AppIdentityService;
echo AppIdentityService::getApplicationId()."<br>";
echo AppIdentityService::getDefaultVersionHostname()."<br>";
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\ServiceBuilder;
$cloud = new ServiceBuilder([
'projectId' => AppIdentityService::getApplicationId(),
'keyFilePath'=>'review-9504000716d8.json'
]);
$datastore = $cloud->datastore();
# The kind for the new entity
$kind = 'Task';
# The name/ID for the new entity
$name = 'sampletask1';
# The Cloud Datastore key for the new entity
$taskKey = $datastore->key($kind, $name);
# Prepares the new entity
$task = $datastore->entity($taskKey, ['description' => 'Buy milk']);
# Saves the entity
$datastore->upsert($task);
This code runs without any issues when deployed. But locally throws:
Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message 'No system CA bundle could be found in any of the the common system locations. PHP versions earlier than 5.6 are not properly configured to use the system's CA bundle by default. In order to verify peer certificates, you will need to supply the path on disk to a certificate bundle to the 'verify' request option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not need a specific certificate bundle, then Mozilla provides a commonly used CA bundle which can be downloaded here (provided by the maintainer of cURL): https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to the file, allowing you to omit the 'verify' request option. See http://curl.haxx.se/docs/sslcerts.html for more information.' in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-hellowo in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-helloworld\vendor\google\cloud\src\RequestWrapper.php on line 219
I didn't manage to make the local server even consider the php.ini file nor did I manage to upgrade the bundled php55 to at least php56.
Thus I actually have 2 questions:
how to properly connect from the local instance (dev_appserver.py) on windows to Google's remote datastore?
how to properly connect from the local instant to the local emulated datastore so I can view the data on localhost:8000?
The APIs are using CA certificate files for authentication more specifically they are using curl.cainfo.
Now you server might already have this file configured in php.ini. You can check in server file. Remember there could be different ini files for different environments like apache, cli.
Now you can either copy that file or Create your own authority file
Option 1:
Set absolute path in php.ini
Option 2:
Use ini_set to set this config.
Option 3:
Try with some other mode of authentication, i am sure google will have that.
Option 4:
As given in your question itself.
If you do not need a specific certificate bundle, then Mozilla provides a commonly used CA bundle which can be downloaded here
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to the file, allowing you to omit the 'verify' request option

You have requested a non-existent service "phpexcel"

I know there are some questions almost identical but none of them seems to be my case.
I have a symfony 2.8.3 project that reads and imports data from an excel file into mysql database. Its all working nice on localhost but in the last 48 hours I've been trying to get it working on my server. Its a shared hosting, with no SSH access to the linux.
When I am trying to load it from the server I get this error: "You have requested a non-existent service "phpexcel"."
Looks like you want to use service from ExcelBundle. But that bundle is not loaded. Check if you have it added for production env.
$bundles = array(
// ...
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
);
Don't forget to clear cache on production environment after any config (AppKernel.php also) change.
To clear cache run php app/console cache:clear. You can also add env parameter: --env=dev or --env=prod - depending on your env. If it don't help then just remove all content of app/cache/ directory (or var/cache/ in case of Symfony3 app)
Pawel answered correctly, but something is missing: after you add this line: new Liuggio\ExcelBundle\LiuggioExcelBundle(), to the AppKernel.php file, inside the $bundles array, don't forget to clear the cache: delete the file from app/cache/dev in case you're in developer mode or app/cache/prod in case on production mode.

Categories