first thanks for your brilliant work on Restler, I am using it for some labs at the University and so far it works like a charm, really simple and elegant framework!
I've been using Restler 3.0 RC4 successfully until I updated to RC5 today. Now I'm having problems with the HtmlFormat. Whenever I try to access any of my web services that return HtmlFormat or try to enter the API Explorer, I'm getting a HTTP 500, "Unable to create cache directory /home/xxxxxxx/public_html/concrete/api/cache/php" . Also, I see a "Warning: mkdir() [function.mkdir]: No such file or directory in /home/xxxxxxx/public_html/concrete/Restler/vendor/Luracast/Restler/Format/HtmlFormat.php on line 367" .
Do you have any idea of what could be happening? In the upgrade, I just replaced my Restler framework folder with the RC5 one, without any changes in my API itself.
I would appreciate any help. Thank you!
Most of the template formats need a cache folder to keep their compiled files so that they run efficiently
Since RC5 we create a subfolder for the template type used. Even though php templates does not need compilation Restler attempts creating php folder under the default cache location, which is cache folder located in the same folder as the index.php
In your case it is
/home/xxxxxxx/public_html/concrete/api/cache
You should update the cache folder to keep it outside the web root by adding
Defaults::$cacheDirectory = '/home/xxxxxxx/cache';
And then make sure the cache folder is writable
Then HtmlFormat will create the php/twig/blade folder depending on your template preference and add the compiled files inside
Related
I've been working on this for several days now and I'm at the point of pulling my hair out.
Goal: to deploy Slim4 on my LAMP server within a specific subdirectory and accessible via a simple URL.
Structure:
There are several instances of my web app on the server and the setup should be replicated for all of them; the structure is straight forward:
/var/www/company1.com/app
this "app" folder contains the main index.php of the website, as well as other various folders. Eg. /var/www/company1.com/app/index.php => https://company.com/index.php
there is a folder called "api" within which I want to load Slim4. I don't really mind how this folder is structured and how deep it goes. I'm working on basis that this is where the composer file goes.
the end result should be that the customer can access the api by calling https://company1.com/api
I'm using the openapi-generator and the Pet Store yaml file.
Running:
openapi-generator-cli generate -i petstore.yaml -g php-slim4 -o /var/www/company1/api/
I've then run composer install and setup the config.inc.php file as described in the instructions.
However when I navigate to http://company1.com/api I am greeted with the same issue every time:
404 Not Found Type: Slim\Exception\HttpNotFoundException Code: 404 Message: Not found. File: /var/www/company1.com/app/api/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php Line: 91 Trace: #0 /var/www/company1.com/app/api/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(58): Slim\Middleware\RoutingMiddleware->performRouting() #1 /var/www/company1.com/app/api/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process()
it goes on...!
I can't figure this problem out.
This issue seems to be quite common as there are a lot of posts about it, so I'm convinced I've missed something very simple.
I have tried the following:
Setting the base path
$app->setBasePath("/api");
Creating a /public/ folder and moving the index.php file there, then creating two different .htaccess files, based on these instructions:
https://akrabat.com/running-slim-4-in-a-subdirectory/
using basepath as per its instructions
https://github.com/selective-php/basepath
None of it seems to work! What am I doing wrong?
I have been able to successful load the Slim4 Skeleton application, however I want to use the openapi-generator so that I can have it automatically prepare all the php files based on my openapi yaml spec.
Any thoughts on tips would be greatly appreciated!
I have multiple restful apis build using yii2 framework, What i wouldlike is to use a single vendor directory stored in a different address
That is
I have an application hosted at www.example1.com and another one hosted at www.example2.com and the one i would like to contain the vendor files to be at www.example3.com so that in both example1 and example2 i only have to upload the resful folder without vendor directories
After some looking into yii2 advanced folder i have found these lines in index.php
require(__DIR__ . '/_protected/vendor/autoload.php');
require(__DIR__ . '/_protected/vendor/yiisoft/yii2/Yii.php');
Ive tried as a work around by doing
require(__DIR__ . 'http:://example1.com/pathto/_protected/vendor/autoload.php');
But the above fails, How best can i achieve this
You can't do it via HTTP.
The only solution is to create shared, NFS volume, which will be mounted on both servers as your vendor/ directory. After you will be able to use the same vendor dir for two servers.
If those two sites are deployed to the same server, it might be easier.
It is very simple .
you can just copy the vendor file into your next project and change the two lines of required file path (autoload.php & yii.php) to the correct vendor location.
the /config/web.php. add vendorPath to the config with your vendor directory.
As the vendor is moved from /var/www/html/myapp/vendor to /var/www/html/frameworks/yii2, you will find problem installing a new extension or updating the existing through composer command. To fix it, modify your composer.json (right under your project directory) by adding the vendor-dir attribute under the config section, eg:
// other settings ...
"config": {
"vendor-dir":"your path",
"process-timeout": 1800
},
// other settings ...
Also, you may find "a man-in-the-middle attack" message when either update or install the new extension (i don't know if there is a relation to the modification of composer.json but i get it several times during experiments). To fix it run composer update --dry-run. then it would ok.
This can be done: Include through http.
You need to set some php variables (allow_url_include, allow_url_fopen). And you need to get rid of __DIR__ constant in front of your php file path:
require('http://example1.com/pathto/_protected/vendor/autoload.php');
BUT
Don't do this. Really. You don't want to go through all these unsafe php setups. And you don't want to expose your vendor files to all the people in the world. If your script can access php source code via http, everyone can. Also, includes over http will be extremely slow.
The (probably) only solution
If you really want to share core php files between multiple websites, you can purchase virtual server, set up both websites on it and create one folder accessible from all websites on this server.
You don't even need virtual server, you can go with some kind of multihost service with custom folder for each website and shared folder for core (vendor) files.
The Yii2 preview was recently released and is available on github. I want to take it for a test drive, but the "documentation" so far gets outdated almost instantly since it is still under heavy development. I have tried to follow this guide on creating a simple CRUD app with Yii2, but it fails at the step:
php yiic.php app/create /var/www/yii2
With the error:
Could not open input file: yiic.php
Indicating that there is no file called yiic.php. The only folder within the framework folder is yii (framework/yii), and within that folder there is no file yiic.php, only Yii.php which when called in the command line gives the command list:
The following commands are available:
- asset
- cache
- help
- message
- migrate
Anyone managed to successfully setup a Yii2 app? Care to share how you got it done?
Seems like yiic has been removed for now, there are alternatives though, so read on.
It's all in the early stages, so the following method could break in the coming days/weeks/months. Therefore use with caution.
There are 2 ways to do this now:
Use composer. (I recommend this option.)
Directly copy the contents of yii2/apps/ directory to your apps directory, depending on the type of app you want to try.
There are currently 2 options for type of app - advanced, and basic. Both are in their respective directories within the yii2/apps/ directory, i.e yii2/apps/advanced and yii2/apps/basic.
For basic go through the basic readme.md, and for advanced go through the advanced readme.md.
The directions for using composer are given in the respective readme.md files. Including them here for completeness:
Basic app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-basic my_yii2_trial
Access app from http://localhost/my_yii2_trial/www
Advanced app:
Install composer, if you don't have it.
Use composer to install the app alongwith dependencies(Yii):
php path/to/composer.phar create-project --stability=dev yiisoft/yii2-app-advanced my_yii2_trial
According to readme, after step 2 app should be accessible, but composer was failing(see issue 439). With schmunk's tip, ran the install or install.bat command that gets copied by composer: ./install . Selected development environment (by entering choice 0 in the instructions that show up when running install command). Update: The command has been renamed to init, composer doesn't fail anymore, with fix from Qiang (check the issue 439 for more details).
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Here's how to copy the directory and get it working:
Basic app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/basic/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/www/index.php file to point to the correct path for Yii.php.
For me it was within yii2/framework/yii/
comment the line that tries to include ../vendor/autoload.php file, I couldn't find that file anywhere, so its probably for some future use. it is the autoloader provided by composer.
Access from browser : http://localhost/my_yii2_trial/www
Advanced app:
create your web-accessible directory for the app : my_yii2_trial
copy all files and folders from yii2/apps/advanced/ directory to my_yii2_trial/ directory.
modify the my_yii2_trial/frontend/www/index.php file to point to the correct path for Yii.php. Similarly modify backstage/www/index.php.
comment the line that tries to include ../vendor/autoload.php file in both the index.php of backstage and frontend.
Access app at: http://localhost/my_yii2_trial/frontend/www or http://localhost/my_yii2_trial/backstage/www
Some important links to read more about this: issue 77, issue 108, issue 131, and wiki comment.
I am not sure how composer's autoloader is being used, so can't comment on that. Also in future versions, backstage might be renamed to backend.
I have inherited an application written with Zend Framework 1.11.2. It has been ported to a server managed by my company, but some of the functionality of the site seem broken on the new server, due to a little fine tuning of the environment.
Specifically, one of the cron jobs on the system is throwing an exception related to the cache directory not being writable.
I am not sure where the cache directory is to make it writable. I have done a little reading and it seems to suggest there is a tmp directory. Can anyone point me in the right direction to either the directory, or how to find out where it is, if it is application specific?
Any help appreciated.
The code for which determines the cache_dir to use when one is not specified is in Zend_Cache_Backend::getTmpDir(). The results are OS-specific and even environment-specific.
This little snippet:
require_once 'Zend/Cache/Backend.php';
$cache = new Zend_Cache_Backend();
echo $cache->getTmpDir() . PHP_EOL;
produced /tmp on my Ubuntu. YMMV.
The cache directory is specified in application.ini:
resources.cachemanager.database.backend.options.cache_dir
resources.cachemanager.locale.backend.options.cache_dir
resources.cachemanager.translations.backend.options.cache_dir
There is a feature request for this (ZF-12214). You can use the included patch to monkey-patch your ZF for debugging.
On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.
What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/
So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.
Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}
As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?
Any ideas what the problem is? Thanks
EDIT:
Even doing this doesn't work???
Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}
You are right on the money with:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3
It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:
Make sure the host is pointing to
the correct directory
(/Users/cameron/Sites/sample-site/)
Verify mod_rewrite is in fact on.
Verify you have copied the .htaccess
file in both the
/Users/cameron/Sites/sample-site/
and the
/Users/cameron/Sites/sample-site/webroot
directories.
Confirm that the
/Users/cameron/Sites/cake-1.3/
directory has a directory called
cake in it that contains the core.
Once all of this is confirmed, you will be good as gold!
Happy Coding!
UPDATE:
When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:
/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.
CakePHP 3.0+
In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php
If you have access to your php.ini, you can add the path to Cake core there. Doing it this way means you don't have to change webroot/index.php at all. Example in php.ini:
include_path = ".:/usr/local/lib/php:/home/something/phpinc/cakephp2/lib"
According to the CakePHP 2.x docs, this is the recommended way to share the Cake core (assuming you have access to your php.ini).
You can have only one cake core but you must have one app folder (containing MVC) by site.
Is this a misunderstanding of the folder structure of CakePHP?
From the docs (CakePHP folder structure):
The app folder will be where you work your magic: it’s where your application’s files will be placed.
The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.
So the cake folder shouldn't change between all of your uses, therefore you have 1 copy. You can always change some of the functionality of the core by making your own changes in the app folder i.e. extending.
There is no need to edit index.php.
Just put an alias (or link in UNIX) to your cake folder in each of your sites folder. Works perfectly. Same goes for plugins and vendors folder.