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.
Related
I have a Vuejs App deployed at apache2 server in digitalocean , when you hit the url it forwards you to login page which is working fine and then automatic navigate me to dashboard page that have cards when I click on one of cards I get 404 page even after I edit my .htaccess file in dist
NOTE the card route is domain.com/build
I tried .htaccess configuration from docs
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
and here is my virtual host configuration
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin email
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html/app/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /api/ http://localhost:8000/
ProxyPassReverse /api/ http://localhost:8000/
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
#RewriteCond %{SERVER_NAME} =domain.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Nothing wrong with virtual host file, the problem was in apache2.conf file in /etc/apache2. what I need is to change this part from
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
to :
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
you need to change the AllowOverride attribute.
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
I created a virtual host with this code :
<VirtualHost *:80>
ServerAdmin admin#127.0.0.1
ServerName site.ws
ServerAlias www.site.ws
DocumentRoot /home/me/Projects/website/build
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/me/Projects/website/build>
Allow from all
Satisfy any
</Directory>
</VirtualHost>
and I created a .htaccess file in my /build directory with this code :
RewriteEngine On
RewriteRule ^(.*)$ $1.html [R,NC]
Consider my mod_rewrite is active in apache2, but I can't open pages with /filename
e.g site.ws/about
It shows error :
The requested URL /about was not found on this server.
I try this with Apache2 2.4.27 in win:
First enable vhost in httpd.conf file.
vhost:
<VirtualHost *:80>
ServerName site.ws
DocumentRoot /home/me/Projects/website/build
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/me/Projects/website/build>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
.htaccess:
###START MOD_REWRITE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#REMOVE .html EXTENSION
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
###END MOD_REWRITE
i solved this problem with :
RewriteEngine On
RewriteRule ^([a-zA-Z-]+)$ $1.html [L,NC]
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
I added to C:/windows/system32/drivers/etc/hosts:
127.0.0.1 mywebiste
and in httpd-vhosts.conf added:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/xampp/htdocs/mywebiste"
ServerName mywebsite
ErrorLog "logs/error.log"
CustomLog "logs/access.log" common
<Directory "C:/xampp/htdocs/mywebiste">
Options Indexes FollowSymLinks Multiviews
Options -Indexes
AllowOverride None
Order allow,deny
allow from all
#RedirectMatch ^/$ / index.php
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</Directory>
</VirtualHost>
And now when I want to add new website to hosts file and httpd-vhosts.conf it renders 'mywebsite' and I cant access that website, even if I delete my virtualhost in httpd-vhosts.conf and remove my entry from hosts file it still renders 'mywebsite'. What should I do to fix this, I have no clue?
I believe you need
NameVirtualHost *:80
Prior to any <VirtualHost...> lines
See here
Nevermind, you have to restart the apache to apply new settings :) sorry. Btw it doesnt work at all wit NamevirtualHost.