deploy multiple laravel projects in apache virtual hosts - laravel

I have two laravel projects, I deploy on VPS, then I configure the apache virtual host for each project in my /etc/apache2/sites-available.
example:
project1.conf:
Listen 8999
NameVirtualHost *:8999
<VirtualHost *:8999>
ServerName project1.test
ServerAlias www.project1.test
DocumentRoot "C:/laragon/www/data/project1/public"
DirectoryIndex index.php
<Directory "C:/laragon/www/data/project1/public/">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
project2.conf
Listen 8998
NameVirtualHost *:8998
<VirtualHost *:8998>
ServerName project2.test
ServerAlias www.project2.test
DocumentRoot "C:/laragon/www/data/project2/public"
DirectoryIndex index.php
<Directory "C:/laragon/www/data/project2/public/">
#Options Indexes FollowSymLinks MultiViews
AllowOverride All
#Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
in my /windows/system32/drivers/etc/host, I have already made a host for each project.
but I have a problem, which is when I open the first project in the browser and log in, then at the same time I open the second project and login too, when the first project is refreshed, it returns to the login page. Why did it happen ?

Instead of doing it the hard way, you can try to use Laravel Valet, which allows you to link your site to a domain like localhost.test and localhost2.test. It takes care of all virtual host configuration.

Related

URL not found on server when uploading Laravel project

I have a Laravel project that is on a live server and I have made a copy to place in a development server. When I try to login, it says The requested URL /xxxx/login was not found on this server..
I am not quite sure what to do, as I changed my httpd.conf to
<Directory "/var/www">
AllowOverride All
Require all granted
</Directory>
and
<Directory "/var/www/html">
AllowOverride All
Require all granted
</Directory>
but I am still getting the same error after restarting apache. Is there any way to solve this?
I think you didn't config for the virtual host or you config it wrong.
You can find that config file under folder /etc/httpd/conf.d/vhosts/ Below are a sample file config:
$ cat /etc/httpd/conf.d/vhosts/yoursife.conf
<VirtualHost *:80>
ServerName yourdomain.com
ServerAdmin youradmin_server_mail
DocumentRoot /your_src_path/public/
<Directory "/your_src_path/public/" >
Options FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /your_src_path/public/logs/error_log
CustomLog /your_src_path/public/logs/access_log combined
</VirtualHost>
You can create a new file if you want.

set virtualhost in apache is not direct to my goal directory of laravel project

OS: Microsoft Windows 10
backend framework: Laravel
my goal: when I access to "http://example.domain", it can direct to laravel index.php.
httpd-vhosts.conf:
<VirtualHost *:80>
DocumentRoot "C:\Apache24\htdocs\NKUST_foodpanda\public"
DirectoryIndex index.php
ServerName example.domain
ErrorLog "C:\Apache24\logs\error.log"
CustomLog "C:\Apache24\logs\access.log" combined
<Directory "C:\Apache24\htdocs\NKUST_foodpanda\public">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I save httpd-vhosts.conf and restart my apache, and now, when I access to "http://example.domain", it will direct to "C:\Apache24\htdocs", not "C:\Apache24\htdocs\NKUST_foodpanda\public".
I have tried with same possible scenario as yours with following entry httpd-vhost.conf. Checked it with both '' and '/' and it is working for me. Make sure to provide proper permission to your directories. If this could not work you need to provide more info.
<VirtualHost example.domain:80>
DocumentRoot "C:\Apache24\htdocs\NKUST_foodpanda\public"
DirectoryIndex index.html
ServerName example.domain
ErrorLog "C:\Apache24\logs\error.log"
CustomLog "C:\Apache24\logs\access.log" combined
<Directory "C:\Apache24\htdocs\NKUST_foodpanda\public">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
If you want to set a newer setup in "httpd-vhosts.conf", you have to delete comment out "Include conf/extra/httpd-vhosts.conf" in "httpd.conf".
I have not notice this problem, I comment out "Include conf/extra/httpd-vhosts.conf" and set something in "httpd-vhosts.conf" at the same time, so "httpd-vhosts.conf" doesn't work.

How to point multiple laravel projects on same domain?

I want to create two Laravel applications like below:
app1.domain.com -> points to app1 laravel. Here I am allowing multiple subdomains like wildcard subdomains.
app1.domain.com/blog -> should point to blog laravel.
Database is the same for both applications, and session will be the same.
How can point these two like above?
I have pointed like below
<VirtualHost *:80>
DocumentRoot "C:\wamp64\www\app1\public"
ServerName app1.domain.local
ServerAlias *.domain.local
<Directory "C:\wamp64\www\app1\public">
Options Indexes FollowSymLinks
allow from all
order allow,deny
AllowOverride All
</Directory>
## Path to laravel sub-folder
Alias /blog/ "C:\wamp64\www\blog\public"
<Directory "C:\wamp64\www\blog\public">
AllowOverride All
</Directory>
</VirtualHost>
Using above config, app1 is working fine but blog application does not work. It shows forbidden error You don't have permission to access /blog/ on this server.
Solution:
<VirtualHost *:80>
DocumentRoot "C:\wamp64\www\app1\public"
ServerName app1.domain.local
ServerAlias *.domain.local
## Path to laravel sub-folder
Alias /blog/ "C:\wamp64\www\blog\public"
<Directory "C:\wamp64\www\blog\public">
AllowOverride All
</Directory>
<Directory "C:\wamp64\www\app1\public">
Options Indexes FollowSymLinks
allow from all
order allow,deny
AllowOverride All
</Directory>
</VirtualHost>
Now working fine but with in the blog application assets path not working correctly. assets pointing from main domain instead of subfolder.
it should be like
http://app1.domain.local/blog/assets/js/login.min.js?id=c818c905d151b67566ee
but loading from http://app1.domain.local/assets/js/login.min.js?id=c818c905d151b67566ee

Hosting Mutiple laravel project in sub-directory in same server

I am struggling to host the multiple laravel project in same server in sub-directory.
I want to run laravel project in example.com/CoreApp and example.com/DataSync
Project Directory:
- Root directory (example.com): React Js Project
- CoreApp (example.com/CoreApp) : Laravel Project
- DataSync (example.com/DataSync) : Laravel Project
Here is the current issue I am facing now.
example.com/ => It is working fine.
example.com/CoreApp => It is working fine.
example.com/DataSync => It is serving me 404 page whereas its other routes are working fine. Like example.com/DataSync/telescope is working fine.
Note: Also, I have added RewriteBase /DataSync and RewriteBase /CoreApp in respective project in .htaccess
Here's my config:
Server Config:
- Digital Ocean Server
- Apache web server
- Ubuntu 16
Here is what my virtual host look like.
<VirtualHost *:80>
DocumentRoot /var/www/sites/html
Alias /CoreApp /var/www/sites/html/CoreApp
Alias /DataSync /var/www/sites/html/DataSync
<Directory /var/www/sites/html/CoreApp>
AllowOverride All
DirectoryIndex index.php
</Directory>
<Directory /var/www/sites/html/DataSync>
AllowOverride All
DirectoryIndex index.php
</Directory>
ServerName www.example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
<Directory "/var/www/sites/html">
Options Includes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
ServerAlias www.example.com
DocumentRoot /var/www/sites/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateKeyFile /etc/ssl/sites/key/myserver.key
SSLCertificateFile /etc/ssl/sites/certs/example_com.crt
SSLCertificateChainFile /etc/ssl/sites/certs/example_com.ca-bundle
<Directory "/var/www/sites/html">
Options Includes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
Change in you virtual host file for Alias as:
Alias /CoreApp /var/www/sites/html/CoreApp/public
Alias /DataSync /var/www/sites/html/DataSync/public
you have to provide location of public folder
You should provide URL up to your-directory/public. If still issue. then provide URL up to your-directory/public/index.php.

How to serve different web apps using one domain name in Apache?

I'm currently trying to deploy my Django 2.0 App on an Apache Web Server. However I'm experiencing difficulties in configuring it because my Virtual Host configuration overrides other Virtual Hosts which is used by other projects (Ruby and PHP WebApps). We only have one domain name at the moment so I cannot use other domain names to host my app.
Is it possible to serve different kind of apps with one domain name using Apache Virtual Hosts?
Since you can only have 1 VirtualHost (one domain, one port, one IP), you cannot create additionnal VH. You need to "split" the paths to the different applications some other way.
Let assume www.example.com:
ServerRoot "/some/path/apache"
[...] OTHER LoadModule directives [...]
LoadModule alias_module modules/mod_alias.so
Listen *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
# Logs
LogLevel warn
CustomLog "logs/www.example.com_access-log" combined
ErrorLog "logs/www.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This VirtualHost is a basic configuration for the www.example.com domain. Now you want to have Ruby, PHP WebApps and Django 2.0 App under that single domain. You have 3 choices:
Get 1 domain per application, not applicable here, that is your question.
Make a sub-directory in htdocs, and a path in the URI for each application.
Put each application in some directory, not under DocumentRoot and use Alias.
Use sub-domains.
Not applicable.
Sub-directory and path
Create /some/path/apache/htdocs/Ruby, put your Ruby app. here.
Will be accessed via http://www.example.com/Ruby
Create /some/path/apache/htdocs/PHPWebApps, put your PHP app. here.
Will be accessed via http://www.example.com/PHPWebApps
Create /some/path/apache/htdocs/Django, put your Django app. here.
Will be accessed via http://www.example.com/Django
The URI value must match the directory value.
In some directory, use Alias
If you do not need, or want the URI to match the directory name (like in 2.), use Alias.
Create /SOME_DIR_FOR_Ruby, put your Ruby app. here.
Add Alias "/Ruby" "/SOME-DIR-FOR-Ruby"
Will be accessed via http://www.example.com/Ruby
Create /SOME_DIR_FOR_PHPWebApps, put your PHP app. here.
Add Alias "/PHPWebApps" "/SOME_DIR_FOR_PHPWebApps"
Will be accessed via http://www.example.com/PHPWebApps
Create /SOME_DIR_FOR_Django, put your Django app. here.
Add Alias "/Django" "/SOME_DIR_FOR_Django"
Will be accessed via http://www.example.com/Django
Use sub-domains
This is where you could use multiple VirtualHosts. But you have to be able to create sub-domains. This is done either via a DNS configuration, or through your hosting provider.
You could setup http://ruby.example.com, http://php.example.com, http://django.example.com. Each of these will have 1 VirtualHost, but will all be mapped to the same IP in the DNS.
Then setup 3 VH:
<VirtualHost *:80>
ServerName ruby.example.com
# Logs
LogLevel warn
CustomLog "logs/ruby.example.com_access-log" combined
ErrorLog "logs/ruby.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/Ruby"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/Ruby">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName php.example.com
# Logs
LogLevel warn
CustomLog "logs/php.example.com_access-log" combined
ErrorLog "logs/php.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/php"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/php">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName django.example.com
# Logs
LogLevel warn
CustomLog "logs/django.example.com_access-log" combined
ErrorLog "logs/django.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/django"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/django">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
On Apache 2.2, you have to add NameVirtualHost *:80, in Apache 2.4, nothing, it is always "on".
All these values can be changed as you like, this is just an example to explain the concept.

Resources