Does Laragon ignore .htaccess? - laravel

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>

Related

working .htaccess configs don't work on httpd.conf

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 get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux

I have configured httpd in my fedora and I checked everything is true but i get
access forbidden
I have tested everything about .htaccess but still getting access forbidden. also, my laravel folder permissions are correct.
I tested a sample project while installing httpd it worked perfectly with no 'access forbidden' message.
this is my httpd config
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
this is my htaccess in laravel public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
your probably creating the issue by mixing old Apache syntax with new Apache syntax, modern versions of Apache should be something like this...
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
I found the problem.
it is because of the
SELinux
ubuntu does not uses SELinux by default but RedHat distributions use it by default. SELinux prevents apache to access the home directory for the sake of security so if you disable or put it to Permissive mode, apache can access your home directory to load the web project. if you do not want to disable SELinux so the correct location for web applications is in /var/www/ folder
so if we change httpd config to
<VirtualHost *:80>
ServerName test.com
ServerAlias www.test.com
DocumentRoot /var/www/gitlab/register/public
<Directory /var/www/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
it works fine

Laravel on Google Compute Engine with Apache2 RewriteEngine on Returns 404

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]

Nothing accessible in my Laravel project except the home page

been searching for the past 3 days about configuring laravel 5.4 on my linux mint 18.2 system running apache 2.4 . when apache server starts and i manually type in localhost in the browser,it does show up the default home page of laravel , but when i try to access it through live preview in brackets (live preview base url : http://localhost as my laravel project pro lies in /var/www/html/)but it throws internal server error corresponding to the errors in my apache configuration.So here i put forward my .htaccess file , 000-default.conf file in sites-enabled directory of apache2 and apache2.conf files :
One important thing : i got my project folder pro under /var/www/html/
1. 000-default.conf(sites-enabled)
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/pro/public
<Directory /var/www/html/pro/public>
Options Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2. apache2.conf
Mutex file:${APACHE_LOCK_DIR} default
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
AccessFileName .htaccess
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
Include /etc/phpmyadmin/apache.conf
3 .htaccess (/var/www/html/pro/public/.htaccess)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /var/www/html/pro/public/
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
thank you before hand!
Your all routes would be available after index.php, i mean if your route's url is abc, then it will be open as http://localhost/index.php/abc. Now you don't need to change anything in .htacesss file.
Go to your project root and give the read write execute permissions, so that laravel will able to cache the file inside bootstrap/cache directory and able to create your logs file inside storage/logs directory.
sudo chmod -R 777 bootstrap/cache
sudo chmod -R 777 storage/logs
If your project didn't run after that also, then sometimes you need to give this permission also.
sudo chmod -R 777 vendor/ storage/
Run these three commands after that
sudo a2ensite 000-default.conf
sudo a2enmod rewrite
sudo service apache2 restart
your route should be served after localhost.
Hope this will help :)
Try giving read/write permissions to your storage and bootstrap folder in laravel. Also setup virtual hosts if you can. Refer here.

How to setup base URL in codeigniter running on Ubuntu 14.04?

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.

Resources