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.
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.
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.
I need some help Please, for I'm beginner with Laravel and MVC.
I want to remove the "public/" of the URL.
The only two "solutions" that I found in Google, are:
Either with .htaccess. But with me (and obviously not with me) it's not working.
Either by putting what is in the "public" folder at the root of the project Laravel. This is not good for security reasons.
There is a real solution to remove the "public/" URL? So that for example this URL:
localhost/Laravel/public/test
Accessible only with this URL:
localhost/Laravel/test
Because if it or has no solution, it is of no use that I continuous to take courses on this Frameworks.
_I had read, that there may be a solution with this in AppServiceProvider:
http://www.creerwebsite.com/medias/upload/larav2.png
Or with this in the Router or a container:
App::bind('path.public', function() {
return base_path().'/public_html';
});
But I am beginner, so I do not find the solution.
Thank you.
The best option is to configure your local installation of WAMP to use Laravel's public folder as the document root. You have two options here:
Option 1. Use wamp just for this project alone
Find your httpd.conf file. This is the server config, and should be located in C:\wamp\bin\apache\Apache2.4.4\conf. (it's a good idea to make a backup of this file before editing)
Open the config file in notepad, find the line DocumentRoot "c:/wamp/www" and change to DocumentRoot "c:/wamp/www/public" (assuming you have your laravel project in the www folder)
save the httpd.conf and restart wamp.
Now when you visit http://localhost you should see the Laravel welcome screen.
Option 2. Set up a virtual host
This option is a bit more complicated, but will allow you to have multiple websites running alongside each other in wamp, each with their own subdomain that you can use to access them in your browser.
1. open the httpd.conf file in notepad and find the line DocumentRoot "c:/wamp/www". Change it to DocumentRoot "c:/wamp/www/default".
2. add the following snippet below this line:
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'c:/wamp/www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName myproject.localhost
DocumentRoot 'c:/wamp/www/myproject/public'
</VirtualHost>
This will create two new virtual hosts running on your local ip. One will work on the domain localhost and serve files from the www/default folder, the other will work on the domain myproject.localhost and serve files from the www/myproject/public folder.
locate your hosts file at C:\Windows\System32\drivers\etc and open it in notepad. add the following lines:
127.0.0.1 localhost
127.0.0.1 myproject.localhost
This will add two domain mappings that point traffic to your local ip for wamp to handle.
Now navigate to the www folder and create C:\wamp\www\default and C:\wamp\www\myproject. Move your laravel project into the \myproject folder ensuring that the public folder is here as well.
finally restart wamp and now you should be able to go to http://myproject.localhost and see your laravel website.
The solution :
_In His Laravel project: Rename the "public" folder like this: "www."
_In An accommodation (example OVH): remove all that is at the root, including the "www" (except: .ovhconfig).
_Send His project on accommodation.
I hope it will not cause conflict. After I think we should also rename in his Laravel the "public/" in "www/".
thank You
My server has the following directory structure
/srv
/www
/site.com
/symfonysite
/Other Drupal hosted site files
when I go to site.com my drupal site opens up and I want to be able to access my symfony site on site.com/symfonysite instead of site.com/symfonysite/web/app.php
I created an .htaccess file inside /symfonysite shown below
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /billing/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
But this only gets rid of the app.php part, i.e. site.com/symfonysite/web opens my symfony site and site.com/symfonysite gives No route found for "GET /symfonysite/" error.
What am I doing wrong?
Its the beauty of symfony that it is highly configurable.
You can achieve what you are looking for by following the simple 4 steps:
Create a directory(say project) and put all the content of symfonysite there. You can put this directory any where you like. For simplicity we are going to create the directory in your symfonysite dir.
Move all content of your symfonysite/web to symfonysite
Edit the app.php and or app_dev.php to modify two line as follow:
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
to
$loader = require_once __DIR__.'/project/app/bootstrap.php.cache';
require_once __DIR__.'/project/app/AppKernel.php';
Edit composer.json file to update the value of "symfony-web-dir": "web" and change it to
"symfony-web-dir": "../",
Your modified directory structure may look like:
/srv
/www
/site.com
/symfonysite
/project
/Other Drupal hosted site files
NB: For security reason symfony suggest to expose only the web directory to a web accessible path. You can put the project directory any where you like. Just need to update the path as per your locations.
To give this set-up a little more security you can put a .htaccess file in the project directory
.htaccess
Deny from all
Enjoy!!
You need to make /srv/www/site.com/symfonysite/web the document root of the project.
This can't be done with .htaccess so you need to change apache virtual host config.
This usually lives in /etc/apache2/sites-enabled/yourserver.com.conf
<VirtualHost *:80>
ServerName yourserver.com
DocumentRoot /srv/www/site.com/symfonysite/web
</VirtualHost>
I'm not sure how rackspace sites work, maybe best to open a support ticket with them if you are unable to change these settings. I head they have Fanatical Support :P
The best approach IMHO is to use symlinks. In the site.com/web/content directory you need to run ln -s symfonysite/web sitesymfony. It will create symlink sitesymfony in your web-root that points to /site.com/web/content/symfonysite/web folder. Then your site.com/sitesymfony will call app.php from site.com/symfonysite/web
I deployed an application on Heroku and I used a folder to place all my files inside thus now my application is only accesible from:
http://myapp.heroku.com/app/
Is it possible to create a virtual root to point
http://myapp.heroku.com -> http://myapp.heroku.com/app/ ?
Something similar to Apache VirtualHost?:
<VirtualHost 10.1.2.3>
ServerAdmin webmaster#host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
</VirtualHost>
Thanks in advance.
Yes you can configure the apache as well, however, this needs some changes on your system.
I've compiled a blog post recently that shows this (as the last part), it also shows how you can compile your own PHP extensions for heroku:
PHP on Heroku, again (by hakre; 20 May 2012)
It basically works by extending the standard configuration with your additional settings in another file. Look for the Configure the Webroot section, that's where it starts:
Now comes the next tricky part that is specifying the webroot. Specifying the webroot needs a little bit more work and background information. The CVBacklogs applications webroot in the git-tree is src/app/public. For Heroku, by default, the webroot is the root of the git-tree. That directory is internally mapped to /app/www btw. So what this needs is to create a so called Procfile that starts a sh-script each time the Heroku app web-node starts. That script then modifies the Apache configuration and includes your own config which is setting the webroot to /app/www/src/app/public. So we create the procfile, a config directory, the script and the Apache configuration. Ready?
You can't do anything with Apache / Nginx configuration on Heroku - these are all beyond your control. You could do some kind of php based redirect in the root folder to the /app folder or alternatively rejig the repo so app is the top level.