S
S
Sergei Erm2019-10-01 13:22:50
Apache HTTP Server
Sergei Erm, 2019-10-01 13:22:50

How to install Laravel on a server in a subfolder?

The task is a bit non-trivial, the search did not give intelligible answers.
We have: a web server on ubuntu, on board Apache and PHP 7.
The server itself does not have a domain name, only an ip address like 192.168.100.8
Many projects were installed on it at one time, and in the end the structure looks like this:
192.168.100.8
var/www/html:

  • project1
  • Project2
  • Project3
  • My Laravel

As well as a project on Laravel, it lies in the MyLaravel folder.
So the question itself:
When accessing the project 192.168.100.8/MyLaravel, the response comes from the project that the URL was not found.
But when accessing 192.168.100.8/MyLaravel/Public, everything more or less works.
How to make the project work normally with minimal cost?
Perhaps I missed something in .htaccess, or do I still need to make the server "wisely"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergei Erm, 2019-10-01
@Larvis

I came across some more thoughts, maybe it will help someone in the future a lot.
In the root folder, you need to change the name of the server.php file to index.php
and paste the code below into the .htaccess file in the same place.
But after this, the layout is still going, most likely you need to transfer something from the public folder.

.htaccess file code

Options -MultiViews -Indexes

 

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_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^ index.php [L]

 

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !^/public/

RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [L,NC]


But still, it's better not to do this, but to kick the admin to set up a server with domains.
UPD 2020: I strongly advise against doing this in production, locally it is still acceptable. But it's better not to do this and work normally without crutches)

G
Good Samaritan, 2019-10-01
@djamali

yes, in htaccess you need to redirect requests index.php to public/ index.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question