Apache http-vhosts not the same as httacces? - apache

I have a new project created in symfony and I configured httpd-vhosts to bypass all htaccess files that exist in the project's path.
<VirtualHost *:80>
ServerAdmin admin#lab.localhost
DocumentRoot "C:\wamp64\www\lab.localhost"
<Directory "C:\wamp64\www\lab.localhost">
AllowOverride None
AllowOverrideList None
Order Allow,Deny
Allow From All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ /web [L]
</IfModule>
</Directory>
<Directory "C:\wamp64\www\lab.localhost\web">
AllowOverride None
AllowOverrideList None
Order Allow,Deny
Allow From All
DirectoryIndex app.php
Options FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
</Directory>
ServerName lab.localhost
ServerAlias www.lab.localhost.com
ErrorLog "logs/lab.localhost-error.log"
CustomLog "logs/lab.localhost-access.log" common
</VirtualHost>
With this config it gives me Internal Server Error. If I set the AllowOverride and AllowOverrideList to All, it works as expected. The rewrite directves listed here are the same in my htaccess file.
Is there any difference between htaccess and httpd-vhosts?
And if not, why doesn't my config work?
Thank you

Related

Apache2 + Symfony4 + subfolder = issue

i would like to know how can i have access to my symfony apps like that
ipofmyserver/symfony1 and ipofmyserver/symfony2 with apache2
I've tried that but it doesn't work
<VirtualHost *:80>
ServerName symfony1
Alias "/symfony1" "/var/www/html/symfony1/public"
DocumentRoot /var/www/html/symfony1/public
<Directory /var/www/html/symfony1/public>
AllowOverride None
Require all granted
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ symfony1/index.php [QSA,L]
</IfModule>
</Directory>
<Directory /var/www/html/symfony1/public/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/symfony1_error.log
CustomLog /var/log/apache2/symfony1_access.log combined
# optionally set the value of the environment variables used in the application
SetEnv APP_ENV prod
#SetEnv APP_SECRET <app-secret-id>
SetEnv DATABASE_URL "mysql://root:#localhost/symfony
</VirtualHost>
that config works but when i go on / i have the same thing and when i try to go on symfony2 it doesn't work (same config as symfony1)
if someone can help me
Thanks in advance

Several symfony project on one server with the same port

I have a trouble installing two projects on the same server. Some necessary information:
One VPS server
Two symfony projects (each in separate directory)
Subdomains pointing to projects (first.domain.com / second.domain.com)
All projects must be on the same port (80)
My server looks like this:
Root directory: /var/www/html
- index.php (welcome page)
- projecta (first project)
- projectb (second project)
I would like to achieve:
domain.com -> index.php
first.domain.com (domain.com/first) -> first project
second.domain.com (domain.com/second) -> second project
My apache config:
Alias "/first" "/var/www/html/projecta/web"
<VirtualHost *:80>
ServerName vps.net
ServerAlias http://vps.net/first
DocumentRoot /var/www/html/projecta/web
<Directory /var/www/html/projecta/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ first/app.php [QSA]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/first_error.log
CustomLog /var/log/apache2/first_access.log combined
</VirtualHost>
Alias "/second" "/var/www/html/projectb/web"
<VirtualHost *:80>
ServerName vps.net
ServerAlias http://vps.net/second
DocumentRoot /var/www/html/projectb/web
<Directory /var/www/html/projectb/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ projectb/app.php [QSA]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/second_error.log
CustomLog /var/log/apache2/second_access.log combined
</VirtualHost>
My problem is that first project override path to second project (if I change first project server, then second works).
Now looks like:
domain.com -> first project
domain.com/first -> first project
domain.com/second -> second project in web directory (when I click on the app.php then project run).
Solved
I solved the problem in this way (only in apache config file, I don't need any .htaccess file)
Alias "/first" "/var/www/html/projecta/web"
<VirtualHost *:80>
ServerName first.domain.com
ServerAlias *.first.domain.com
DocumentRoot /var/www/html/projecta/web
<Directory /var/www/html/projecta/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ first/app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/first_error.log
CustomLog /var/log/apache2/first_access.log combined
</VirtualHost>
Alias "/second" "/var/www/html/projectb/web"
<VirtualHost *:80>
ServerName second.domain.com
ServerAlias *.second.domain.com
DocumentRoot /var/www/html/projectb/web
<Directory /var/www/html/projectb/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ second/app.php [QSA]
</IfModule>
</Directory>
ErrorLog /var/log/apache2/second_error.log
CustomLog /var/log/apache2/second_access.log combined
</VirtualHost>
Currently alias didn't work, but for the moment it is enough.

Apache2 mod_rewrite rules

How do i rewrite static files request like
http://example.com/assets/img/logo.png
to
http://assets.example.com/img/logo.png
main site rewrite rules
ServerName example.com
ServerAlias example.com
DocumentRoot /var/www/html/example.com/public/
<Directory /var/www/html/example.com/public/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} !assets\.site\.com
RewriteCond %{REQUEST_URI} \.(png|gif|ico|css|js|tiff|woff|woff2|ogg|mp3)$ [NC]
RewriteRule ^(.*) http://assets.example.com$1 [NC,L]
sub-domain for assets is working properly
virtual host config for assets.example.com
ServerName assets.example.com
ServerAlias assets.example.com
DocumentRoot /var/www/html/example.com/public/assets/
<Directory /var/www/html/example.com/public/assets/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
http://assets.example.com/img/logo.png gives a 404
but if i create a /var/www/html/example.com/public/assets/assets/ then http://assets.example.com/img/logo.png reutns 200
Per your comment, you just need to change the what you're capturing in the regex used by the RewriteRule. Right now $1 is the value of what's in (.*). You can remove "assets" from that by adding it to the path prior to your capture group.
Change:
RewriteRule ^(.*) http://assets.example.com$1 [NC,L]
To:
RewriteRule ^assets/(.*) http://assets.example.com/$1 [NC,L]

How to setup Apache to run Laravel rooted from a subpath?

The DocumentRoot of example.com is in /var/www/html.
Laravel is installed in /var/www/example/public and I can access it using http://example.com/dashboard but problem arises when I try to access other routes like as http://example.com/dashboard/login and is throwing 404 Not Found error. And saying The requested URL /var/www/example/public/index.php was not found on this server. Can anyone please guide me?
The .htaccess file in the public directory is untouched.
Here is the 000-default.conf:
ServerName example.com
UseCanonicalName Off
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /dashboard /var/www/example/public
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
#dynamic subdomain provisioning
<VirtualHost *:80>
DocumentRoot /var/www/example/public
ServerName user.example.com
ServerAlias *.example.com
<Directory /var/www/example/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I could solve using the following in the 000-default.conf file:
<Directory /var/www/example/public>
DirectoryIndex index.php
AcceptPathInfo on
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
And had to change the laravel .htaccess in the following way:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /dashboard
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ dashboard/$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

Ubuntu Apache virtualhost with symfony

have a problem here with Symfony . I want to have virtual host on ubuntu so I can access my Symfony application like this app.local. What I have tried:
<VirtualHost *:80>
ServerName app.local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
DocumentRoot /var/www/app/web
<Directory /var/www/app/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
I added these lines to hosts file
127.0.0.1 app.local
but when I write app.local in my browser, it brings the index of my www directory(default apache page). What am I doing wrong?
Try this :
/etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName app.local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
DocumentRoot /var/www/app/web
<Directory /var/www/app/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Then apply configuration changes :
$>sudo a2ensite mysite // If not already enabled
$>sudo service apache2 restart
If the problem is not solved, check the error logs in /var/log/apache2/