I'm trying to host my laravel app on an ubuntu machine
I added the laravel app to the /var/www/html folder which is root directory for my domain on apache conf file. But when I access my domain, I only get the list of files in /var/www/html folder. When I insert a index.html file for test, it works perfectly when I access the domain. What can be happening?
Your apache needs to be configured to recognize index.php as well as index.html. This is done by setting the directoryindex in the httpd.conf file.
Laravel is served out of index.php inside the public folder.
You are getting your list of files because your domain is pointing to var/www/html which contains the root of your Laravel application and not the public directory which contains index.php.
If you go to www.yourdomain.com/public you will find your application served correctly if your apache is set up to recognize index.php which it should be.
To fix this up so you don't need to use public inside the URL you can just edit /etc/apache2/sites-available to point your directory to /var/www/html/public and then you will be able to access it through www.yourdomain.com.
Related
I have a Laravel 5.3 project on shared hosting located at the following address.
How to remove the public from URL?
Now the same question was asked at Remove public from URL Laravel 5.3 on shared hosting but many answers were asking to move all public content to root domain, but my root domain is already hosting something with index.php in it.
Can you please tell me how to do it? All other information is same as the question shared, i.e default .htaccess file in public as well as home (laravel installation) folder. Second I am in shared hosting, I cant change Vhost or something.
Here is my folder structure inside https://yourdomain.tld/home folder
I think there are 3 possible solutions:
Since you use vhost instead of localhost, the problem might be the DocumentRoot declaration. I use Xampp, so the path and code will be based on that. In my case, the file that creates vhost is located:
C:\Xampp\apache\conf\extra\httpd-vhosts.conf
The vhost code is this:
<VirtualHost *:80>
DocumentRoot "C:/Xampp/htdocs/mydomain/home/public"
ServerName mydomain.tld/home
ErrorLog "logs/mydomain-e1rror.log"
CustomLog "logs/mydomain-access.log" common
</VirtualHost>
BTW, make sure you 127.0.0.1 mydomain.tld in "etc" file if you use a Windows machine.
When you enter www.mydomain.tld it should hit the index.php file that is located in public folder.
Since you use very old version of Laravel, I suppose you download it from liveserver. When we deploy our app, we make some changes in public/index.php file to tell our app where Laravel is. Look for
require __DIR__.'/../vendor/autoload.php'; //
I think this is different in your index.php file. BTW, I don't know if this path is different in version 5.3.
Your folder structure is incorrect. You might try to compare it with freshly installed Laravel.
Currently, my Slim project is stored in localhost/projects/applications/file hosting/src/. My project works when I setup a virtual host via MAMP with the root set to the public folder. I'm trying to make it so I can access the "raw" URL for the project and have my public folder as the root. I've tried adding an .htaccess file inside the src directory with various rewrites and conditions but all seem to error out the program.
How would I go about setting up an .htaccess file to set my public directory as the root when I visit http://localhost/Projects/Applications/File%20Hosting/src/?
My laravel project work good in localhost by artisan serve commend.
Now i'm trying to host it on web host.
I upload my project under public_html and copy all files from public folder i also edit app.php 'debug' => env('APP_DEBUG', true), for showing the error.
i edit index.php
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
but it still give a 500 Internal server error back.
I also try an another way,
Upload my project into root directory except public folder and upload public folder into public_html directory .
and i edit index.php as
require __DIR__.'/laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/laravel/bootstrap/app.php';
i can't find what wrong with my code.
how can i deploy my laravel 5.2 project into a web hosting.?
No No no.. You need to achieve the second option with some improvements. Let me explain it to you. A laravel application looks like:
app/
config/
public/
public/index.php
.env
composer.json
artisan
Right? good, now a web host's structure looks like:
/home/user/
/home/user/public_html/
But the structure above does not fit our needs because is public/ folder that should be accessed instead of public_html/. So.. the first step is to upload your project, lets say, like these:
/home/user/home/project/app/
/home/user/project/config/
/home/user/project/.env
/home/user/project/composer.json
/home/user/project/public/index.php
The next step is decide if you want your project as a main domain, or as subdomain.
If your laravel's project will serve as a main domain just edit apache's config file httpd.conf and set the following rules:
DocumentRoot "/home/user/project/public"
...
If you want you project as a subdomain, just edit the apache's config file httpd.conf and add a virtual server like this:
Listen 80
<VirtualHost *:80>
DocumentRoot "/home/user//project/public"
ServerName my-project.example.com
# Other directives here
</VirtualHost>
With this directive you are telling to apache Hey! when people visits my-project.example.com show them the content of my site under /home/user/site/public.
IF you are using cpanel, just create a subdomain and point it to /home/user/site/public
That is all, you do not need to hack any project's files like index.php, that is a bad practice.
I've gone through phalcon's documentation and followed the tutorial provided on the official site: https://docs.phalconphp.com/en/latest/reference/tutorial.html
The problem is when I browse the project (localhost/tutorial) it shows me the directory list as
app/
public/
What am I doing wrong?
The .htaccess file for the phalcon directory structure assumes you're working at the web root, not a subdirectory. You'd need to adjust your .htaccess file accordingly if you're not going to follow their proposed directory structure. The .htaccess file they give you is designed to redirect all traffic to the web root to your /public directory thus essentially hiding the /app directory from the web. Try placing their suggested web root .htaccess file in your tutorial directory and add a line RewriteBase /tutorial/. Then place their 2nd .htaccess file in your /tutorial/public directory adjusting its RewriteBase to RewriteBase /tutorial/public/.
Alternatively, you can avoid their public directory altogether and use a safer and faster directory structure, due to avoiding extra RewriteRules, albeit less convenient, by placing your app directory below the web root and adjust your PHP to use either dirname(__DIR__) or .. to refer to the parent directory when attempting to locate your app directory.
A final approach would be to create a subdomain on your localhost, http://tutorial.localhost/, yes localhost subdomains are a great solution for allowing web root access for multiple projects without stepping on each other's toes, then you'd edit your hosts file to add a record for the fake domain mapping it to 127.0.0.1, the same as localhost. Then edit your apache config file adding a virtual host for the subdomain mapping it to a specific directory to use as your web root for that subdomain, reload apache, and presto.
Thanks for the answers...but i figured out the problem myself.
The problem was the configuration setting in apache. I changed the setting in the http.conf in apache folder by removing the # from LoadModule rewrite_module. And that worked for me. cheers!
Steps:
Go to wamp/bin/apache/apacheVersion/conf
open httpd.conf
Uncomment or remove "#" from LoadModule rewrite_module
modules/mod_rewrite.so
It seems to me that the idea behind laravel is that the public/ directory is where your DocumentRoot points to and that the app/, vendor/, bootstrap/ and build/ directories all live outside the web root. But what happens if you want the laravel project to live in a subdirectory.
ie. http://www.domain.tld/ might be static HTML, http://www.domain.tld/phpbb/ is phpBB and you wanted your laravel app to live at http://www.domain.tld/app/.
Should you just put the entire laravel folder in http://www.domain.tld/app/ and redirect, via .htaccess, all requests to http://www.domain.tld/app/public/? That seems inelegant.
Maybe you could put laravel in http://www.domain.tld/ and rename the /public/ directory to /app/ but that seems even more inelegant.
Any ideas?
The question is why you need it in subdirectory. So far I never need to put custom project into subdirectory. I use domain or subdomain if needed.
You could try with:
renaming your public directory to the directory name you want to use
put other directories into your root domain directory
add .htaccess for those directories with deny from all (to block access from your root domain)
edit paths in bootstrap/paths.php
I haven't tested it and I wouldn't probably even try to do that. Many frameworks are rather created to use them on separate domains or subdomains and not in directories so I would recommend you to rethink it.
Use virtual hosts in your web engine (eg. apache, nginx, IIS, etc.) and point the document root for your alias to your laravel app.