I developed my laravel application on wamp. I am finally done and rent a cloud hosting server with CPanel interface. I uploaded all my files on public html and tried going to the site. It's supposed to go to login page but not working.
I used to deploy classic html file, this is the first time I'm deploying a PHP laravel site. I've successfully imported my MySQL database so it's ready. I'm just clueless of the configuration etc.
I'll walk you through the steps. Since you mentioned about public_html folder, I assume that this solution will work for you. Please follow the steps and change myapp to whatever your app name is.
Copy your project's public folder into public_html folder and rename it (Say myapp_public)
You will see a .htaccess file in public_html folder. Edit the contents of that file as follows:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^myapp_public
RewriteRule ^(.*)$ myapp_public/$1 [L]
Copy other folders in the root directory inside another directory say myapp
Now the final thing that you need to do is, to edit index.php file at the path public_html/myapp_public/index.php (if you followed the steps I wrote above). Change require statement as follows
Change require statement as follows:
require __DIR__.'/../../myapp/bootstrap/autoload.php';
Change $app variable as follows:
$app = require_once __DIR__.'/../../myapp/bootstrap/app.php';
And this should do it. Drawing out the simple directory structure for easiness.
~
|__ myapp
| |____ .env
| |____ app
| |____ artisan
| |____ .........so on
|
|__ public_html
|_____ .htaccess (this is the file to edit)
|_____ myapp_public
|________ .htaccess
|________ index.php (this is the file to edit)
|________ robots.txt ...... so on
I will explain in detail if you do not understand what is happening here.
EDIT
Make sure that you have installed composer via cURL as apt-get wont work on shared hosts. Once done, run composer install from your project's root directory i.e. myapp if you followed above steps.
Finally I got it, Vishal's answer really helped, but I needed to change my PHP version setting to 5.5 or higher, after looking at the error log and googling the error. Thanks again Vishal. I still have problems with database connection but I think I can handle it from here.
Related
I've built a Laravel site locally, and everything works wonderfully—but when I've tried deploying it to my shared host (Hostinger), I cannot get everything replicated or set up correctly. The obvious problem is that Hostinger puts the public-facing code in a public_html folder, which my Laravel setup does not have (it has public instead).
Also, I'm using GitHub for version control and (hopefully) deployment. I'm able to connect my GitHub repo directly in Hostinger, but the problem is, it pulls my code into public_html instead of the root.
I'm really sorry if this question/problem is dumb; I'm more of a web designer than developer these days, and I just need a damn portfolio site up and running. :)
Local directory structure:
root
--app
--bootstrap
--config
--database
--node_modules
--public
--resources
--routes
--storage
--tests
--vendor
I've read various articles and posts about either copying contents of public into public_html after uploading the code, and then changing __DIR__ suffixes in index.php; or ways to change public to public_html locally up front...but the former didn't work and the latter scares me since so much of my Laravel workflow using npm run and whatnot utilizes the public dir.
I also don't really want to have my remote and local out of sync. My desired workflow:
code locally <---
| |
npm run dev/watch --
|
npm run prod
|
push to GitHub
|
deploy to host
|
enjoy fresh website without any changes to remote files on host :)
You don't want to move the contents of public to the root and serve your app from the root because you will expose important config files such as .env.
Create another .htaccess in your root with the following contents:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Which will rewrite all of your urls to the public directory. This should work in the local and production environment.
Have you tried to change public path in Laravel :
See answer here maybe this is a solution.
Following an audit, I've been tasked to remove extraneous files from the Twig 1.x vendor directory in one of our sites. Planning on removing /twig/twig/doc, /twig/twig/test and see if anything breaks.
What about /twig/twig/ext/twig/run-tests.php, or the entire "ext" directory?
Does anyone have prior experience weeding a default Twig 1.x installation for production environments? Any assistance or advice gratefully welcomed.
The correct action would be to update your site's layout so that these files are outside your web server's document root -- then you don't have to worry about what to delete and what to leave. You probably have something like this, where your web server's document root is pointing directly at /path/to/project:
/path/to/project
/lib
foo.php
bar.php
/twig
/twig
/doc
/test
index.php
This means anybody can directly request http://yourdomain.com/twig/twig/test/some_file.php
What you want is more like this:
/path/to/project
/public
index.php
/lib
foo.php
bar.php
/twig
/twig
/doc
/test
Then configure your web server so that its document root is /path/to/project/public. Then your application code can still include() things in /twig and /lib, but your web server won't directly serve them.
If your removing files from the vendor directory they'll come back the next time you do a composer install so this seems kind of pointless.
The files you mention (docs and test) are causing no harm other than taking up space as they are not directly called, but that's just a downside to any package management system. Like #Alex said as long as they are not publicly accessible there is no need to worry.
If you really want Twig without the extra files you could fork the project, move it into your own Git repo then reference that in your composer.json instead of the official one - but you will miss out on any updates from Twig.
We're running on Apache, so the easiest solution was to simply add a .htaccess file to the top vendor directory:
# Prevent non-local access to the vendor directory.
Order deny,allow
Deny from all
Directory structure:
/root
/vendor
.htaccess
/twig
...
/includes
...
Now the PHP scripts continue to have access, but external attempts to view anything inside the vendor directory return a 403 error.
Currently my local code and production code follow the same directory structure. After, pushing my changes from local, i pull it on the server and it works fine.
Website path is something like http://abcde.com/code/laravel/public
code directory is under version-control
Now, i'm trying to change path to http://abcde.com
i followed this guide and thinking about moving source code out of server directory. So, the structure:
/var/www will contain content of laravel's public folder
/var/source will contain laravel
But then how'll i manage it with Git because the structure will be different?
Edit: I'm aware of two solutions:
Changing apache root
use .htaccess to remove public
For 1, there is a possibility that we'll add another directory admin in www, which will have its own source code. So, existing content of www will be moved to a sub-directory.
For 2, It's not recommended to keep source code inside web server root.
Please correct me if i'm wrong.
My thought is, you can make symlinks to preserve your directory structure, with this you help apache to keep it original configuration, and at the same time will no have any issues with version control.
Symlink is by using this command: ln -s /path/to/origin path/to/destination.
Bests ;)
There is a simpler procedure. Pull you complete project in var/www and add a .htaccess in var/www which contains -
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Now you will be able to use http://abcde.com
I'm trying to remove the public/index from laravel url, since this is one of the common question so there are lot of tutorials and answer. I also searched about this and followed the #rimon.ekjon answer which is working fine for me it's pretty simple.
Rename the server.php in the your Laravel root folder to index.php and copy the .htaccess file from /public directory to your Laravel root folder. -- Thats it !! :)
I'm confuse why i should rename or move something from one place to another because there will be a reason why files exist in public folder. I want to show another good answer which is also following the almost same pattern.
I'm thinking that by following above answers' step may be create some issues in future if there will be a new requirement or new feature request in the project.
So can anyone guide me is there any best to rewrite or remove the public/index from laravel 5. I would like to appreciate if someone guide me.
You should configure your web server's document / web root to be the public directory. That way you don't have to copy/move/delete anything.
For apache you can look here.
For nginx you can read here.
I've visited your link and saw really terrible advices.
You do no need to move any Laravel files or modify them. What you need is to setup web server. You need to point it to a public directory which is inside Laravel project root folder.
Please look here for an example config directives for Apache and nginx.
One other option is to symlink the public folder to your server's root folder (e.g. /var/www/). This article is a great guide on how to do this.
On your dev environment however you can use php artisan serve.
In case, if you don't have access to you server config, this is a perfect solution https://stackoverflow.com/a/32580688/5015089 .
Remove public from url without htaccess. It will work on laravel latest versions also.
step 1. Copy all files from public and paste on root directory
step 2. Open index.php file remove ../ from path as given below
Laravel5:
require __DIR__.'/../bootstrap/autoload.php';
to
require __DIR__.'/bootstrap/autoload.php';
and
require_once __DIR__.'/../bootstrap/app.php';
to
$app = require_once __DIR__.'/bootstrap/app.php';
Laravel 7:
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
I'm new in Laravel 5.
I found this Laravel 5 - Remove public from URL on Stack Overflow to remove public folder from my Laravel 5 App. Only I have a question about the security.
When I am removing public from URL, then I have to change the basic folder structure of Laravel 5. Yes, it's working fine without the public from the URL.
But what's about the security of Laravel, because I am changing the default folder structure? Is it secure to use?
You should be pointing your Apache host root to the $LARAVEL_PATH/public directory instead of $LARAVEL_PATH.
The point of having sub directory for www host root instead of project root is that you're not leaking any of your project files through your web server.
Even though all the PHP files have the file suffix .php, malicious user can access your $LARAVEL_PATH/storagedirectory and its subdirectory contents, read your composer.json or package.json to find vulnerable dependencies or read .env file etc.
If you're running on shared hosting and you have mandatory public_html, try installing Laravel outside of that public_html directory and either removing public_html (if empty) and replace it with symlink to $LARAVEL_PATH/public OR if you want the Laravel instance to be subdirectory ofpublic_html, do the same but create symlink from$LARAVEL_PATH/publictopublic_html/$PROJECT_SUBDIR`.
That public directory is there for reason to make project a bit more secure. Solve the actual problem and don't try to break this simple but nice security addition. :)
you this link you provided is not about changing the actual file structure of the framework, this example uses mod_rewrite to rewrite the url of your application. In other words you are telling your server that you would like to point to that directory without the full path is visible to the end user.
Also take a look on the below answers of the link you've provided.
Rename the server.php in the your Laravel root folder to index.php and
copy the .htaccess file from /public directory to your Laravel root
folder. -- Thats it !! :)