Help please, i am using Laravel4 but for some reason i can not get it to work on my mac at home,i have no problems with the mac at work, either i am missing something obvious or my mac is set up different.
the problem i am having is that i can only get the HomeController To Work if i try to use the Test Controller i get Controller method not found. the whooops error gives Controller Method Not Found
REDIRECT_URL /test
GATEWAY_INTERFACE CGI/1.1
SERVER_PROTOCOL HTTP/1.1
REQUEST_METHOD GET
QUERY_STRING
REQUEST_URI /test
SCRIPT_NAME /index.php
PATH_INFO /test
PATH_TRANSLATED redirect
my routes
Route::controller('test', 'TestController');
and my Test Controller
class TestController extends BaseController {
public function getIndex()
{
return View::make('test.index');
}
}
my htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
rewrites are enabled
am i missing the obvious?
thanks for any help
I had a similar situation in my local development environment. The Laravel 4 app that was deployed on my remote server was working perfectly, however I couldn't get it to work on my local machine. The problem was that only the root folder of the app (/public - Home Controller) was accessible and none of my routes were working.
The problem was in the configuration of Apache which was not allowing loading of .htaccess files. My solution was to define a new Directory statement for my sites path as follows:
<Directory "/path/to/your/sites">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
You may insert this in httpd.conf or in any configuration file that is being loaded. If there is already a definition for that path, you should update it accordingly. In my case I added the code above to my httpd-vhosts.conf file along with the virtual host definition:
<VirtualHost *:80>
ServerAdmin your#email.com
DocumentRoot "/path/to/your/sites/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
Finally add this line to your /etc/hosts
127.0.0.1 laravel.dev
In this way, you can reach your local environment via this URI: http://laravel.dev
Related
An early heads up - I'm a beginner student with Back-end programming and for now, even .htaccess URL rewrites was a huge pain to implement.
I have XAMPP Apache installed on my Mac (not XAMPP-VM) with a website folder called "Project" inside "/htdocs". So basically a website that I'm practicing with URL looks like this - "localhost/Project"
There was one .htaccess file in my "root" ("root" is the "/Project" folder) folder and another one inside a "PHP" folder (i.e. root/PHP/.htaccess).
Root's .htaccess had the following configs:
Options -Indexes
ErrorDocument 403 /Project/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)Pages
RewriteRule ^(.*)$ Pages/$1.php [L,NC]
</IfModule>
Whilst root/PHP's .htaccess had this:
Deny from all
Everything worked and after reading a bit more about .htaccess best practices I wanted to move all of the above configs to httpd.conf, specifically the one located inside "/Applications/XAMPP/xamppfiles/apache2/conf". I moved the code to that httpd (properly?), commented out everything inside the previously mentioned .htaccess files, and here's how the httpd now looks like inside:
Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
Options -Indexes
ErrorDocument 403 /Project/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)Pages
RewriteRule ^/(.*)$ /Pages/$1.php [L,NC]
</IfModule>
</Directory>
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project/PHP">
Deny from all
</Directory>
And it doesn't work. I've tried to google a solution for a while and so far completely nothing. Just in case, I'll also mention that the goal for this "CMS" project is to "write once, install anywhere".
[EDIT]
With some clarifications from #MrWhite, this is what the configs look like in xamppfiles. Also, also, Options -Indexes and /Project/PHP > Require all denied don't work as I can browse folders and access "PHP" folder from Browser. And it did not work prior to this EDIT as well.
-xamppfiles/apache2/conf/httpd.conf
Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Include "/Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf"
-xamppfiles/apache2/conf/project.conf
<VirtualHost *:80>
DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
Options -Indexes
ErrorDocument 403 /Project/index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(.*)Pages
RewriteRule ^(.*)$ Pages/$1.php [L,NC]
</IfModule>
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project/PHP">
Require all denied
</Directory>
</VirtualHost>
I'd greatly appreciate any help.
Original:
RewriteRule ^(.*)$ Pages/$1.php [L,NC]
New:
RewriteRule ^/(.*)$ /Pages/$1.php [L,NC]
You shouldn't have changed anything here. You are moving the directives from .htaccess to a <Directory> section (in the server config). These are both directory contexts and work the same way. (You are incorrectly thinking this is a server or virtualhost context, although the target URL-path would still be wrong.)
By introducing a slash at the start of the URL-path in the RewriteRule pattern (first argument) the rule will never match. If it did... the additional slash you've introduced at the start of the substitution string (second argument) would incorrectly rewrite the request to /Pages in the document root, not /Project/Pages as would seem to be the intention.
Note that if you are moving the .htaccess config to <Directory> containers in the server config then you should probably disable .htaccess overrides altogether, since a .htaccess file that contains mod_rewrite directives will completely override the <Directory> container in the server config. For example:
AllowOverride None
Note also that Order, Allow and Deny are Apache 2.2 directives and formerly deprecated on Apache 2.4. On 2.4 you should be using the equivalent Require directive instead. For example:
Require all granted
Require all denied
Extra:
Look into creating additional <VirtualHost> containers for each project, store these in separate files and include them in the main server config, rather than modifying the main server config directly. This will allow you to host multiple (separate) websites on the same webserver.
I have found the issue, which was my blind mistake.
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
Options -Indexes
//...
I was pointing to the wrong htdocs folder that contains my Project and the correct way was:
<Directory "/Applications/XAMPP/xamppfiles/htdocs/Project">
Hope this saves some time for anyone else that would come across this.
I created Common Helper for Image Upload & Common Trait Function for get Images Full URL from Storage & I tested it in Laravel's default inbuilt server it's 1005 perfectly works.
but after Deployment I can't Display Images. it's show 404 error to me
I shared my Common function of Get Full URL path of Image from storage.
app/Traits>HasProfilePhoto.php file
public function getProfilePhotoUrlAttribute()
{
return $this->profile_photo_path
? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path)
: \URL::to('/').'/adminLTE/dist/img/user-img.png';
}
above function will returns Image's Full URL Path Like."test.com/storage/users/user.png"
using Laravel's Default Inbuilt server it returns Full URL like this. http://localhost:8000/storage/users/user.png & using that path image display perfectly
but after the deployment in local Windows using XAMPP Server, it returns Full URL like this. http://localhost/ProjectFolderName/storage/users/user.png & it's show 404 Not Found
NOTE:- If I use FULL Url like this:- http://localhost/ProjectFolderName/public/storage/users/user.png then image displayed
Please Help me what's my mistake there?
*
**How I deployed my Laravel Project see below:- **
*
root/server.php file renamed with index.php
& root/public/.htaccess file copied at root directory
Rename the server.php file to index.php is not good practice for security reasons as well. So if you need to hide the public path from the URL then create a .htaccess at root level:
<ifmodule mod_rewrite.c>
<ifmodule mod_negotiation.c>
Options -MultiViews
</ifmodule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</ifmodule>
Updated by Harsh Patel:- 8th September 2021
Actually Problem is about defining Virtual Host in Server... I was defined DocumentRoot path & Directory path as like "C:/xampp/htdocs/projectFolderName/ this.
I was identified my mistake in deployment from here medium's Blog
but as per Laravel Documentation , we need to direct all requests to public/index.php in other words Laravel's Public Folder is an Our Server's Root (public_html) folder that's why I need to define DocumentRoot & Directory up to public folder like this C:/xampp/htdocs/projectFolderName/public
We need to define our Laravel Web in Apache Server's Virtual Host Config.
for XAMPP Server
step 1: open C:\xampp\apache\conf\extra path location in XAMPP Server
step 2: Open httpd-vhosts.conf File
step 3: define virtual host rule as like below
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot "C:/xampp/htdocs/projectFolderName/public"
<Directory "C:/xampp/htdocs/projectFolderName/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
IF you faced any problem to define Virtual Host in XAMPP then you can see Full detailed answer about How to define Virtual Host in XAMPP
& If you Use WAMPP Server then you can see Full detailed answers about How to define Virtual Host in WAMPP
Maybe you just need to set your projects URL inside .env to start with http://
APP_URL=http://your-project-url
Without this, images will not have proper URL but when you copy image path and open it inside new tab, image will be available anyway.
I'm trying to host this website on google cloud using the compute engine and apache2. Since this is a previously established instance, there are a couple websites in there already and a pre configured .conf file as shown below. Uploading files and other stuffs are fine, and the website run smoothly, however i ran into the /public issue in where if the user didn't enter domain/public they'd be taken to the project directory index page instead.
i have tried creating the .htaccess file inside the laravel root directory, it got rid of the directory index page but it returns 404 instead. I have checked the routes are indeed listed and can be accessed with the /public even after the RewriteEngine on in .htaccess
lamp-server.conf :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess :
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(.*)$ /public/$1 [L]
404 :
expected result : return the landing page
issue : server return 404 on existing routes without /public after .htaccess RewriteEngine on
question : How do i fix this so it doesnt return 404 without the /public?
attempt :
change RewriteRule to RewriteRule ^(.*)$ /public/$1 [L]
I'm trying to move a working project from XAMPP to Laragon.
Everything is fine, but some directives I've put in my .htaccess don't work anymore: all modules seems to be enabled correctly.
What I'm trying to have working again is the versioning for my assets:
<IfModule mod_rewrite.c|rewrite_module>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(css|js)$ $1.$3 [L]
</IfModule>
This is placed in the root of the project with Laravel, but moving it into the public folder does not change anything
In the Apache config I have the following correctly uncommented:
LoadModule rewrite_module modules/mod_rewrite.so
And this is the host configuration (untouched)
<VirtualHost *:80>
DocumentRoot "C:/laragon/www/projectski/public/"
ServerName projectski.localhost
ServerAlias *.projectski.localhost
<Directory "C:/laragon/www/projectski/public/">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
As you can see it points to /public, but moving to the root (which I would like to, considering server configuration) will disable everything and turn the local site into a directory.
Please help me move to Laragon.
For those still looking for an answer, Laragon does not ignore .htaccess
The error was a simple syntax error in the IfModule
<IfModule mod_rewrite.c | rewrite_module>
# Logic
</IfModule>
Installed LAMP stack. Right now I've extracted codeigniter files to /var/www/ci
but while running on browser http://localhost/ci/ the welcome page doesn't display.
Finally found the answer. Have to enable the site.
In /etc/apache2/sites-available/000-default.conf file shud modified as follows:
<VirtualHost *:80>
DocumentRoot /var/www/
ServerAdmin webmaster#localhost
<Directory /var/www/ci/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And this worked for me! Thanks all.
If you are using ubuntu 14.04 the web server inside var/www/html, so move your folder into var/www/html/ci.
And open .htaccess file inside ci folder.paste the following code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /ci/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You can set the base url in /application/config/config.php on line 26.
$config['base_url'] = 'http://localhost/ci/';
If that doesn't solve the problem you have to post more informations.
Fresh codeigniter install?
No third party plugins?
No changes to routes? (in /application/config/routes.php)
No changes to the controller?
No changes to the view?
Do you get errors?
If not check if error reporting is on in the index.php (set it hard to development for testing)
Do you use Rewrite rules in an .htaccess in the /var/www/ci/ folder?
Do you autoload anything? libraries, models, languages, helpers ?
If you can't find anything, set this to 4:
$config['log_threshold'] = 4;
in /application/config/config.php on line 216.
The log file is written to /application/logs/.
Post that log, probably it helps.