Hosting Mutiple laravel project in sub-directory in same server - laravel

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.

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.

deploy multiple laravel projects in apache virtual hosts

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.

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

.htaccess <VirtualHost not allowed Mac

I am trying to setup crud app using http://crud-admin-generator.com/ on my Mac
So I followed the steps on the above link to get all the entities generated.
While running the server I needed to setup the .htaccess file on my mac throws the following error when I run localhost on my mac machine.
/.htaccess: <VirtualHost not allowed here
My configurations are as follows
/etc/apache2/httpd.conf
DocumentRoot "/Users/akshat/Sites"
<Directory "/Users/akshat/Sites">
/etc/apache2/users/akshat.conf
<Directory "/Users/akshat/Sites/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And /Users/akshat/Sites/.htaccess
<VirtualHost *:80>
DocumentRoot /Users/akshat/Sites/admingenerator/web
DirectoryIndex index.php
<Directory "/Users/akshat/Sites/admingenerator/web">
Options Indexes FollowSymLinks
Order Allow,Deny
Allow from all
AllowOverride all
<IfModule mod_php5.c>
php_admin_flag engine on
php_admin_flag safe_mode off
php_admin_value open_basedir none
</ifModule>
</Directory>
</VirtualHost>

Resources