Symfony2 with PHP 5.4 built-in server - php

I'm trying to work with Symfony2 with the new PHP 5.4 and its built-in server.
I downloaded Symfony2 and unziped it on my server and added this router.php file like mentioned here:
<?php
if (isset($_SERVER['SCRIPT_FILENAME'])) {
return false;
} else {
require 'Symfony/web/app.php';
}
?>
The webserver itself works because if I replace router.php with something simple like phpinfo(); it outputs it correct but with the mentioned router.php script the site remains white/blank. If I open developer tools it returns 500 Server error.
I start the server like that:
/home/php54/php -S 0.0.0.0:88 router.php
On my shell I have no output of a error message.

/home/php54/php -S 0.0.0.0:88 router.php
You are trying to run server on privileged port, so either change port or run this as privileged user (not recommended).
Also you have modified router script and I think you've messed up with file paths. You are not specifying docroot in your command, so your current directory is your docroot (so it should be your project's web/ directory). But then path to the front controller in router.php is wrong (Symfony/web/app.php).
You should really follow carefully instructions from my blog post. So:
change your current directory to your project's web/ directory,
download router script: wget https://raw.github.com/gist/1507820/b9583ab7f7f5e0e4e29806c38c6c361220b6468f/router.php,
run server: php -S 0.0.0.0:8000 router.php.
This should work.
You can also try patch from my pull request which adds simple command that just runs built-in PHP server.

I don't have a php 5.4 environment handy, but load app_dev.php instead of app.php, as debugging will be set to true and errors will be reported.

Related

Calling a PHP (Fat Free Framework) file from a bash script in Linux is giving me "No Routes Specified" error

I am working on a PHP (Fat free framework) project in Linux. The project is running fine when I call it directly from the cli.
> cd /var/www/html/test/proj/source/
> php index.php controller_name/action_name/parameter1
However, I cannot run the project from a bash script. I have created a bash script with following content:
/usr/bin/php /var/www/html/test/proj/source/index.php controller_name/action_name/parameter1
I get the following error
"No routes specified"
[/var/www/html/test/proj/source/index.php:LINE_NUMBER] Base->run()
I couldn't find anything about it on https://www.fatfreeframework.com
Probably it does not work because the app's root path is a different. Change the working dir with cd /var/www/html/test/proj/source/ first before calling index.php, because otherwise relative paths within the app are screwed and things like $f3->config('config.ini'), where you might have defined the routes, isn't finding the file to load.

Accessing laravel on local without IP address

I am new to web development and completed some practise project on xampp on windows.
without using laravel i used to access my website by typing 'localhost/myproject' but in laravel it doesnot work.
i have few quesions -
what does php artisan serve do internally?
After running command php artisan serve why we can only access our project by '127.0.0.1:8000/myproject' instead why we cant use 'localhost:8000/myproject'.
The artisan serve command uses the Built-in web server from PHP itself.
The reason you can't use localhost is probably the fault of your OS. You have to add the localhost alias to your hosts file which can be located in different places depending on your operating system.
You can access your project without IP address like localhost/myproject/public without doing anything but keep in mind every time you have to put public word. If want to remove public word and access like as normal php project from localhost example localhost/myproject then do these simple steps.
Cut files (index.php, .htaccess and robots.txt) from public directory from your laravel project and paste files to root of your project.
Now open the index.php file and change the lines like below and save.
require __DIR__ . '/bootstrap/autoload.php';
$app = require_once __DIR__ . '/bootstrap/app.php';
Now you can easily access your project without IP address :)
For better understanding you can watch this YouTube video. (Bangla Language)
https://www.youtube.com/watch?v=PvuI1UiYIo4

HTTP 500 Error in Symfony 3

I created an app on my localhost using symfony 3. Stuff works perfectly well on my local host. Now my main problem is moving it to my shared hosting (cPanel). Moved the files to the public_html folder, then I moved the .exe, bin, src, var, etc folders to the parent folder (The folder containing the public_html folder) while leaving the 'web' folder in the public_html. I then moved everything from the 'web' folder (Which is inside the public_html folder) into the public_html folder. Making me have the following directory structure:
cpanel-root-directory<br>
---/app<br>
---/bin<br>
---/src<br>
---/tests<br>
---/var<br>
---/vendor<br>
---/public_html<br>
------/bundles<br>
------/css<br>
------/dist<br>
------/fonts<br>
------/img<br>
------/js<br>
------/plugins<br>
------/uploads<br>
------.htaccess<br>
------app.php<br>
------app_dev.php<br>
------apple-touch-icon.png<br>
------config.php<br>
------robots.txt<br>
<br>
When I go to the domain name, I keep getting this annoying HTTP 500 error. Then on both localhost and on the server (at different times), I created a fresh new symfony project, dumped it in the server and got the "Welcome to Symfony 3" page quite alright. But, when I tried putting my controller files, and going to the routes defined in them (I use annotations in the Sensio bundle to define routes), I get that HTTP 500 error. Then, in the default controller that works, I try defining a new action 'testAction'. When I go to the route for the test action, I still get the HTTP 500 error, but going to the '/' route, I see the symfony welcome page correctly.
My clients have seen that the stuff works perfectly well on my localhost, but now moving it to the server is the issue.
If you can (have access), just keep your web dir, and then make public_html a symlink to your web dir.
If you need to change the name of your "web" dir, you need to follow this instructions:
http://symfony.com/doc/current/configuration/override_dir_structure.html
You should check this paragraph from Symfony documentation
This part seems to describe exactly your problem:
Some shared hosts have a public_html web directory root. Renaming your web directory from web to public_html is one way to make your Symfony project work on your shared host. Another way is to deploy your application to a directory outside of your web root, delete your public_html directory, and then replace it with a symbolic link to the web in your project.
Eh, I think that's because, now, you are online, so you need to clear the cache for the prod environment:
$ php bin/console cache:clear --env=prod
But you say you are on a shared hosting, so unless you have some available tools to access the terminal (and run the above command), then you need to manually delete the var/cache/prod directory if present.
Or if this doesn't work, I usually, don't upload the var/cache + var/logs + var/sessions directories at all, but create them manually as empty ones, and then let Symfony do its job with them by default.
LE
Maybe you have another problem, and the one with the cache you've solve it already.
So, to check if there is something wrong with your app, enable the dev mode ( app_dev.php ), by modifying, locally, your public_html/app_dev.php file, and comment out these lines:
if (isset($_SERVER['HTTP_CLIENT_IP'])
|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
|| !(in_array(#$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
And then, copy this file over the one on the server, and then access a route with app_dev.php in front, and see if there is an error (eg):
http://www.domain.com/app_dev.php/existing_route
After you are done, don't forget to uncomment the code inside app_dev.php,and re-upload the file on the server.

Where is the Front Controller using server:run in Symfony 2

Using plain old apache server, you make your request to Symfony using localhost:80/acme/app.php/routes
So app.php or app_dev.php is you Front Controller. Knowing this, you can forget almost it. But when you use the PHP built in server, you can access directly to localhost:8000/routes.
I have looked inside the console script file, and it looks like app.php but we call it only once, at the start of the server. Where is the glue stuff ?
The console file is the front-controller for the CLI environment of your Symfony application. The server:run is part of this environment and can be found in the FrameworkBundle: ServerRunCommand (EDIT: as of Symfony 3.3, the command can be found in the WebServerBundle)
It starts the built-in webserver of PHP: php -S localhost:8000 and it routes all incomming requests to a so-called routing script. In case of the dev environment, the router_dev.php router inside the FrameworkBundle.
This router file has this line:
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app_dev.php';
Which pretends that the incomming request was made to the app_dev.php file. (So localhost:8000/something becomes localhost:8000/app_dev.php/something after this router script). It then includes the app_dev.php file to handle the rendering of the site.

Laravel base route errors "NotFoundHttpException"

I'm too newbie to Laravel...I have written this route to echo "Hello World", but It errors NotFoundHttpException
This is my routes.php (no other code is in the file but the following):
Route::get('/', function(){
return "HELLO WORLD";
});
I have also enable mode_rewrite, and also set AlloOverride to 'all' in apache module.
This is also the URL is use to access the page:
http://localhost/laravel/public/mostafa
Do:
php artisan serve
Use that URL to visit your website.
You will see that you get some output like:
Laravel development server started on http://localhost:8000
When you have no clue what Artisan is take a look at this;
http://laravel.com/docs/artisan
Navigate into your project directory with your command prompt and run there the serve command from above.
Example:
Sometimes the default .htaccess file located in public folder doesn't work in apache. Try altering the .htacess as mentioned here. Alternatively renaming your laravel project folder would work especially in XAMPP.
Some other frameworks treat route definitions as relative to the project web root so a path defined as /foo/bar will match http://example.com/additional/levels/laravel/public/foo/bar and will work without changes even if you move the project tree somewhere else in your public web hierarchy. Laravel, however, considers routes as absolute paths so /foo/bar will only match http://example.com/foo/bar.
The simplest solution is probably to move your code into a separate virtual host and point its document root to laravel/public/. (In this case it seems that's actually the intended set-up.)
(I suppose there's a way to make the framework assume an implicit prefix but I've only been using Laravel for 10 minutes.)

Categories