PHP built-in web server is not finding assets - php

I have a php project built with Zend Framework 2. In want to start the built-in server to developing with the following command:
sudo php -S localhost:8080 -t public/ public/index.php
All the functionality of Zend Frameowrk 2 are working fine but I get 404 errors when retrieving the assets.
The assets are in the public/css, public/img and public/js folder.
GET
http://localhost:8080/css/bootstrap.css [HTTP/1.1 404 Not Found 10ms]
GET
http://localhost:8080/css/dlu-tw-bootstrap.css [HTTP/1.1 404 Not Found 21ms]
GET
http://localhost:8080/css/style.css [HTTP/1.1 404 Not Found 35ms]
GET
http://localhost:8080/js/bootstrap.js [HTTP/1.1 404 Not Found 45ms]
Any idea on how to allow the built-in server to access these files?

As I understood from reading this blog post, you either need to start your command from the right folder and not specify any -t option
$ cd public
$ sudo php -S localhost:8080
Or you need to write your own routing rules in the index.php

Related

Symfony 4 assets response error in dev , require which php extension?

In symfony I use bin/console server:run all resources response is invalid ~
example:
css response info by 'bin/console'
This is return a text and has not response header.
But when I use php -S 127.0.0.1:8000 -t public, it is worked!
css response info by 'php -S'
And there are some logs is samed in terminal They are all response 200!.
I think the reason is that I have some php extension not istalled.
So I composer require req-checker,But there is not required symfony required check
So who can tell me I will require which extension can fixed it.
Thanks!

Symfony4 Route not found with path param if contains a dot

If I navigate to this route with this slug (/client/example.com)
/**
* #Route("/client/{url}")
*/
I get this error
The requested resource "/client/example.com" was not found on this
server.
I'm using php built-in server php -S 127.0.0.1:8000 public/index.php
With this aproach it works but assets doesn't load properly
php -S localhost:8000 public/index.php
Edit:
without dot it works.
php bin/console router:match /client/example.com
[OK] Route "client_show" matches
php bin/console router:match /client/example
[OK] Route "client_show" matches
As Lawrence Cherone stated in the comments looks like it doesn't work with the built-in php server but it does work with the composer require server included in Symfony Recipes.
php bin/console server:run

symfony2 assets targets the /www server folder, not the /web symfony folder when deploy in production

I have some problems with Symfony 2 application deployment. I have import all files I need on my OVH shared server, but some errors occured like css and js files not found (internal server error for example) or error like Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://my-server/css/458dafd_bootstrap-theme.min_1.css".
Notice that I have installed the CoresphereBundle in order to have a console in my browser when my application is iploaded on my server, I have access to the console only on dev environment.
This is step by step what I did in order to deploy my application:
1 I updated my application and vendors with composer (because I have no ways to install composer on my server)
composer.phar update
2 I clear the dev cache php app/console cache:clear
3 I clear the prod cache php app/console cache:clear --env=prod --no-debug
4 I install assets php app/console assets:install web
5 I dump the assets php app/console assetic:dump web
6 I uploaded my symfony application on my server.
7 Once the files are uploaded in web/app.php I I authorize
the prod debug
$kernel = new AppKernel('prod', true);
8 Then in web/config.php I remove this block
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
So, on my server, if I would like to go to http://my-server/web/config.php it works well, so I see if my server is compatible with symfony. the only thing that appears is Set short_open_tag to off in php.ini*.
9 I set the access rights for the app/cache and app/log folders to 777 on my server, it allows the applications to write in these folders.
10 In web/app_dev.php I write this code, in order to allow the dev mode for my IP adress and so have access to the console bundle
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
'121.457.719.2' //a random ip adress it's just for you to understand
))) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
11 So I have access to the dev environment on my server, all works well, and no errors occured here. To access to the console bundle, following to the bundle documentation, I have to wrote http://my-server/web/app_dev.php/_console (see the routing code here):
_console:
resource: "#CoreSphereConsoleBundle/Resources/config/routing.yml"
prefix: /_console
But this routes does not exist, If I wrote this url, nothing appear in my browser:
However, by the config.php, I have access to app_dev.php by following the Bypass configuration and go to the Welcome page link:
I click on the link and I arrived on app_dev.php. Like I said before, no errors occured in this environment, except for the console route. But I could have access to the console by clicking on the console logo under the symfony debug toolbar:
This is the url for the console when I click on the logo under symfony debug toolbar: http://my-server/web/app_dev.php//_console/_console, I would like to understand why?
Then when I would like to make some commands another error occured: [error] Internal Server Error in the console:
If I try to use the router debug php app/console debug:router, I have this:
and with the php app/console debug:router | grep _console:
So, there are the problems I have with my symfony application.
UPDATE
I resolved the problem of the console bundle. In fact my server does not use the same php version of my symfony application, I have to set this in the .ovhconfig at the root of my /www folder.
/www/.ovhconfig:
app.engine=php
app.engine.version=5.5
http.firewall=none
environment=production
Now when I would like to access to the production environment I have these errors concerning all my assets files (css/js/images, a 404 not found):
Failed to load resource: the server responded with a status of 404 (Not Found) -> http://my-server.com/bundles/fosjsrouting/js/router.js
Uncaught ReferenceError: fos is not defined -> routing:1
Failed to load resource: the server responded with a status of 404 (Not Found)
->http://my-server.com/css/45898d_dataTables.min_7.css
I don't really understand, the files are indeed at the root of the app, e-g I have no folder css or js or etc in http://my-server.com/. These folders are in http://my-server.com/web/. Where is the problem?
When I access to the console, this is the command I made:
1 cache:clear
2 assets:install web
3 assetic:dump web
EDIT: solution works
I understand that the assets target a /css /js /images etc folder at the root of my server, so I replace the css and js files to the root of the /www server folder, e-g in the /www folder of my server I have this:
//my server
/.ssh
/www /*http://my-server.com/...*/
/app/
/bin/
/css/
/fonts/
/images/
/js/
/src/
/vendor/
/web/
/.htaccess
/.ovhconfig
/composer.json
/composer.lock
/composer.phar
Why my symfony application tagets the assets here?
Have you tried to use the Symfony command line routing debugger?
php app/console debug:router
That will output all the routes the symfony app knows about and you could try piping it into grep to see if you're trying to use the wrong path to hit the _console route.
php app/console debug:router | grep _console

Apache Server Throwing 500 Internal Server Error

I had a LAMP application running wordpress and I deleted the whole directory and replaced with new files - php based.
Now, when I go to view my server running CentOS - it just shows a 500 Internal Server error.
I've tried:
restarting server
restarting apache service itself
both completed successfully, but this didn't fix anything. Now, I do not know where to go from here.
apache logs # /usr/local/apache/logs/error_log on apache:
[Tue Apr 22 11:12:15 2014] [error] [] SoftException in Application.cpp:357: UID of script "index.php" is smaller than min_uid
I found the fix myself, this wasn't an error with Mysql at all, but rather a permissions issue with the index.php file I had.
The error, which I found in /usr/local/apache/logs/error_log was:
:is smaller than min_uid Premature end of script headers: index.php
To fix, I did this:
ls -l in the directory causing the issue (mine was public_html)
You should see the index file (e.g. index.php) that should be causing the issue. It is due to a root user having the only permission to the file and not your CPanel (or system) username. (note this system/cpanel name)
Run the following within the errorneous directory(Note: this command must be run within all subdirectories of the primary errorneous directory.):
sudo chown yoursystemuserhere:yoursystemgroupuserhere index.php
or to apply to the whole directory (thanks to #Prix):
sudo chown -R user:group /folder
You're all set.
Further literature here: http://www.inmotionhosting.com/support/website/general-server-setup/uid-smaller-than-min-uid
I hope this helps someone else in the future.
I had similar symptoms on my cPanel VPS - I was able to use easyApache to recompile Apache and PHP which fixed the problem for me.
(I realise my problem was slightly different to yours, but it may be helpful for people in the future who have the same problem I had).
chown -R user.usergroup /path_to_the_directory
Will resolve this. It is basically permission issues.
just install wordpress latest version make sure you have atleast php version 5.3 and above also look global register variable if it off or just delete htacess file from server and see what will happens
generally 500 internal server gives when file permission is missing so you should delete htacess file

How to parse index.php in server root by default in HipHop / HHVM (and fix the "404 File Not Found" error)?

Reproduceable problem description:
When installing HipHop / HHVM via the official way [1][2], and then running the built-in server [3] from /var/www via
cd /var/www
sudo hhvm -m server
it will render a custom "404 File Not Found" message to the browser, regardless of /var/www's contents when moving to the server's root:
http://111.111.111.111/
However, HipHop will run perfectly when a filename is given, like
http://111.111.111.111/index.php
Filling the index.php with phpinfo() will also show "hiphop" as feedback, indicating that this PHP file is correctly parsed by HipHop.
Question:
How to let HipHop's server run index.php (etc.) by default when navigating to the server's root, like Nginx and Apache do ?
Update:
Seems to be a common issue: [4], [5]
According to the documentation, the config.hdf file has a DefaultDocument directive. Set that.
For HHVM 3.0 you specify it in a ini config file with this:
hhvm.server.default_document = index.php

Categories