I have been getting this error in Zend framework when i want to run the static content , The error is like
///Not Found
The requested URL /public/content/services was not found on this server.
Apache/2.2.20 (Ubuntu) Server at localhost Port 8090///
This is occuring when I try to access localhost:8090/content/services
Please give me a solution , thanks in advance :)
I Replaced "AllowOverride None " with "AllowOverride FileInfo " in httpd.conf file and it worked !!!
make sure you create the route in your application.ini as specified on page 39 "Defining Custom Routes"
//this needs to be exact
resources.router.routes.static-content.route = /content/:page
resources.router.routes.static-content.defaults.module = default
resources.router.routes.static-content.defaults.controller = static-content
resources.router.routes.static-content.defaults.action = display
without the route being defined correctly the static content will not work as suggested by this book.
i/f you are going to use this book "Zend Framework: A Beginner’s Guide" follow the code as close as you can until you understand it. ZF1 is not trivial to understand.
Don't change your .htaccess arbitrarily, keep it as close to stock as possible. It's ok to use it to set the environment and that's about it. Zf1 won't work correctly if the .htaccess is even a little incorrect.
//stock .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I noticed you are using Ubuntu... Make sure you have the correct permissions and ownership of the files in your document root. Ubuntu has some different default settings for file permissions.
The book also instructs you to establish a vhost for your site ( page 13 "Define Virtual Host Settings" ). Please execute this recommendation it will make your life easier as you learn this framework.
Related
We are using a popular PHP framework to host a website.
We made some additions that allow us to do custom modules that encapsulate controllers, service objects, PHP templates, Javascript, CSS, and images into a single sub-directory.
We created it outside the vendor directory to distinguish these modules from third-party libraries.
What I want to do is have Apache 2.2. serve up the images, js, and css in these modules instead of going through PHP.
I have tried to edit the .htaccess file to return the files directly. It isn't working and I can't seem to find documentation on how to do this.
The URLs are in the format:
https://example.com/Modules/cart/images/shopping_cart.png
https://example.com/Modules/cart/js/shopping_cart.js
https://example.com/Modules/cart/css/shopping_cart.css
Here is what I have so far:
RewriteCond %{REQUEST_URI} ^/Modules/(.*)/images/(.*)$
RewriteCond /var/www/app/%{REQUEST_URI} -f
RewriteRule ^/Modules/(.*)/images/(.*)$ /var/www/app/Modules/$1/images/$2 [L]
What am I missing?
Edited to add:
The Modules directory is outside the document root /var/www/public of the virtual host, so they are currently being served through PHP. I am actually trying to optimize a currently running site.
[UPDATE]
As per the info given by #Dave I have created a symbolic link from a sub-directory the document root to the images directory of the module.
So the symbolic link is in the form [document root]/images/[module name]/ pointing to /var/www/app/Modules/[module name]/images/.
However I'm still getting the following headers indicating it is going through PHP:
Request URL: https://example.com/Modules/cart/images/shopping_cart.png
Server: Apache/2.4.35 (FreeBSD)
X-Powered-By: PHP/7.2.10
My new rewrite rule is:
RewriteCond %{REQUEST_URI} ^/Modules/(.*)/images/(.*)$
RewriteCond %{DOCUMENT_ROOT}/images/$1/$2 -f
RewriteRule ^/Modules/(.*)/images/(.*)$ %{DOCUMENT_ROOT}/images/$1/$2 [L]
I got it working. For those who may be wondering what the final answer is I'll detail it here.
I created symbolic links into our modules so that Apache can see them relative to the document root in the following format:
[document root]/images/[module name]/ pointing to /var/www/app/Modules/[module name]/images/
[document root]/css/[module name]/ pointing to /var/www/app/Modules/[module name]/css/
[document root]/js/[module name]/ pointing to /var/www/app/Modules/[module name]/js/
Then the rewrite rule is as follows:
RewriteCond %{REQUEST_URI} ^/Modules/(.*)/(js|css|images)/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%2/%1/%3 -f
RewriteRule ^(.*)Modules/(.*)/(js|css|images)/(.*)$ %{DOCUMENT_ROOT}/$3/$2/$4 [L]
Now we can transition on a case by case basis to the new locations while still speeding up the old code.
I have a code (who works on remote server), but he don't want work on my VM linux (ubuntu 16).
Issues are varied :
CSS isn't read
#import and #expand don't work
Laravel routes don't work
Apache 2 rewrite_module is ok (classical solve for Laravel routes issue)
PHP 7 is ok (phpinfo is good), Laravel is ok (access to database via Eloquent is good).
I precise that my html code is generate via php artisan with blade.
I suppose that I forgot a step in my configuration but I don't see what...
Edit :
Change on Apache's config DocumentRoot from root of application to /public solve the CSS issue.
a valid .htaccess is now ok, without change.
So, now, my major issue is to find why
https://www.xxxxx.vvv/api/v3/docs works and https://localhost/api/v3/docs doesn't.
Given that https//www.xxxxx.vvv/ and http://localhost/ work in the same way.
versions : php 7.0.3
Laravel 5.0.4
(and I don't want update)
As you said, .htaccess file missed. So put it in public directory with the following code:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I've been searching lot of related tutorials and so on from Google to solve this on my own, but with zero luck. Therefore I am here to ask. I am trying to 'prettify' my project URL by rewriting. I am not sure are these all achievable anyhow, because I am just starting to get my head around the subject.
I am working 'example' on localhost project folder localhost/example. File '.htaccess' is located in that folder. Where I have set the following:
RewriteEngine On
RewriteBase /example
So basically my application now generates a URL consisting at least 1 parameter all the time and another pointing current location.
Current URL: localhost/example/admin.php?e=2&p=frontpage
Fantasy: localhost/example/admin/2/frontpage
About the parameters:
p stands for selected page
e stands for event
Okay lets think this all is achievable easily, do I have to change all the attributes to match current shown url?
Now they are:
href="?e=2&p=settings"
Should they be:
href="2/settings" ?
I am checking what value GET parameter P has, then including that page into content area.
That is pretty much it, pretty too complex for me, but for education purposes I really want to understand this thru and thru. Thank you.
EDIT:
With the added
RewriteRule ^admin.php/(.*)$ /admin.php?e=$1 [L,QSA]
I am getting lot of pathing errors, whole site is without styling and js files.
EDIT 2:
RewriteEngine On
RewriteBase /example
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /admin.php/e=?(.*)$/p=?(.*)$ /admin.php?e=$1?p=$2 [L,QSA]
Now urls are following:
http://localhost/example/admin.php/2/inc/vex/vex.css
http://localhost/example/admin.php/2/css/modestgrid.css
It is not showing the page in url and the paths are not correct.
They should be http://localhost/example/admin.php/css/modestgrid.css
Your question is a bit vague, contradictory and it is unclear how you actually want to handle (reference) your asset files. But in general I'd say this should be a starting point to get you going:
RewriteEngine On
RewriteBase /example
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/(.*)$ $1.php?e=$2&p=$3 [END]
For this to work you obviously need the apache rewriting module to be installed and loaded, you need to take care that the interpretation of dynamic configuration files is enabled at all (AllowOverride directive) and you have to place such file in the correct location with reading permission for the http server process.
In case you get an internal server error (http status 500) for that chances are that you operate a very old version of the apache http server. In that case you probably need to replace the [END] flag with the [L] flag which probably will work here too. You will find a hint on that in your http servers error log file in that case.
And a general hint: you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only supported as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).
I am using Yii2 framework for my PHP development. In my view files, If I want to call any of the functions, I just use Class/Function name
Eg : www.example.com/SiteController[class name]/index[function name]
And it is calling the function.
I like to know, How to do the same in a pure php script ?.
I searched in many places and I could get the suggestions for special_autoload_register();. But I could not understand the exact practical application.
Guidance is expected and Thanks is advance.
Its easy :).
It's all based on apache module mod_rewrite. This module allows you to modify path behavior in .htaccess file.
Using this .htaccess file
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
you will get following behavior:
If requested file exists (/styles/style.css - styles, javascripts, images, etc) serve it (dont change anything on current behavior)
If requested file doesn't exist, go to index.php.
If you are redirected to index.php, you can find full requested url in $_SERVER['REDIRECT_URL'] or $_SERVER['REQUEST_URI']. There you can take it, parse and based on requested uri, behave.
Please take this as explanation post, not a guide on how to get this going. Mostly it requires some apache configuration because mod_rewrite is mostly disabled by default.
If you want to get things going, I would recommend this post.
To fully answer your question, you can for example explode request uri by "/" sign, save first part into $firstPart and second into $secondPart and then have
$controllerName = $firstPart."Controller";
$controller = new $controllerName;
$actionName = $secondPart."Action"
$response = $controller->$actionName();
So if you call /help/me, helpController->meAction() will be called.
I hope I helped :)
To do this, Yii 2 (and other PHP frameworks) have routers. The router in Yii 2 is the UrlManager class.
I would not advice you write a router from scratch for a solution you want to deploy. There are routing packages in PHP which you could easily use in your solution. I like Klein. It's a pure router in PHP.
However, if for academic purposes, you want to know how routing works in PHP, get to understand the $_SERVER reserved variable. It has all the details of the HTTP request coming to your script. You can then use the details from this to call the specific function you want to call.
I am trying to run laravel4 on a service that cannot use Apache or nginx.
everything is good till I wanted to use Routes on my project.
I've tried using /index.php/... on the URL but could not make this work.
is there any way to force laravel not to use .htaccess file or any ways to use raw PHP routing?
Try setting the "application.url" option in one of configuration files, probably in app/config/application.php or application/config/application.php:
https://github.com/laravel/laravel/blob/4cb904f44d24f856ec9c1040d2198ed8f009723b/application/config/application.php
Set it to http://127.0.0.1:54007/index.php. Now when laravel creates url it will use this as a root and the final urls should be like http://127.0.0.1:54007/index.php/account/signin.
Also you need to modify PHP Desktop settings so that it uses a fixed port. Edit settings.json file and set it like this:
"web_server": {
"listen_on": ["127.0.0.1", 54007],
In laravel's .htaccess I've found this:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
So it should work fine to add "/index.php" to root url, because this is what apache's mod_rewrite does.
If something doesn't work, take a look at some other files named "url.php", "uri.php".
Let us know if that works.
EDIT.
You may also try setting root url to "index.php", without the "http://". This way it wouldn't be required to set a fixed web server port.
UPDATE
There was a bug in Mongoose web server in PHP Desktop, that prevented urls like "index.php/company/5" from working properly. See the __fix_mongoose_env_variables() php function in Issue 137 that fixes it:
https://code.google.com/p/phpdesktop/issues/detail?id=137