I want to deploy a Laravel 5 project to shared hosting from my localhost but I am facing so many problems. I have uploaded all files in a subfolder of my shared hosting (PHP 5.5) and when I try http://domain.com/subfolder/public its showing me 500 error. I check the laravel.log but found nothing, set the storage/ to 777 but still no changed (showing last error from localhost).
I also check .htaccess and it seems good. I search a lot and try so many thing but still facing same problem.
Now, my shared hosting give access of SSH so I have installed a new Laravel project. Then copy my edited and added file except vendor from my localhost to Hosting. Then I update the composer and dump-autoload, Now my application is working file.
But I am not sure about the process I did. Is it the right way (I don't think so)? Please let me know what was the problem of directly uploaded file and is there any problem if I use second system for my production app.
There are chances that your route cache is messed up. It is safe to artisan route:clear, artisan cache:clear, and artisan view:clear before uploading your files to ensure that no compiled script left - which usually tied to specific path.
But it is unclear, could you share your stacktrace for your error (and if possible share where your .htaccess file and it's content)?
sorry i can't comment, need higher point. However, by looking at your statement that it works by moving your files (controller, views, public, etc) but not the entire project, i believe clearing caches is the best to try.
As for the deployment of laravel project, there are methods suggested in laravel.io. It is not a good idea to expose your entire laravel files in public folder. Nevertheless, there are many ways to deploy it.
I know it's a little late but you need to either:
1. Make laravel's public folder the root folder of your domain or
2. Make a sub-domain and point the root folder to your projects public folder. The disadvantage with this is that your sessions cannot be connected directly to your main domain's sessions.
Related
I'm using Laravel Homestead (Vagrant) to set up my development environment. Everything works fine, until I try setting up NFS on my Windows following https://laravel.com/docs/8.x/homestead#configuring-shared-folders
As soon as I set up NFS, the vagrant up process goes fine, but trying to access the project website makes it unresponsive, i.e. no reply from the server. Opening vagrant ssh, only the place where the shared folder is present is unresponsive (bash gets unresponsive), otherwise other parts of the shell keep working.
More than a day of debugging later I find that simple files are actually working fine. So if index.php contains phpinfo();, that loads fine. I then copied the Laravel public folder, all good with an error that vendor is missing. Added the vendor folder, still good, says Kernal missing. And finally when I add the app\Http\Kernal.php file, again it gets unresponsive.
Edit: Adding the following mount_options finally gets it working, but instead of being a lot faster, it is actually taking double the time it takes without NFS. My aim here is to improve the app loading speed, which everyone says gets a lot lot faster with NFS.
mount_options: ['vers=3', 'tcp', 'actimeo=1', 'nolock']
Edit 2: After a lot more debugging I noticed realpath() in PHP was coming out empty, after which I realized I'm unable to change file permissions of the shared folder! So the index.php has 644 permissions, and I'm totally unable to change those permissions or owner:group. I tried changing mount_options dmode and fmode, they don't have any effect
Future update: I eventually moved to Docker and later Laravel Sail and its magically fast
Try setting the max rsize and wsize for tcp in your mount options, you would also probably want to set asynchronous mode and force nfs to use fs-cache.
e.g.
mount_options: ['async','fsc','nolock','vers=3','tcp','rsize=65536','wsize=65536','noatime','actimeo=1']
You could also try the mount over udp to see if that resolves the issue, I would also try simplifying the mount options at this point to see if it is something there causing the issue you are having.
mount_options: ['vers=3','udp','rsize=8192','wsize=8192']
I've got a real head-scratcher for you! I've been working on a Laravel 5.4 application for quite some time now and up until yesterday I had been able to:
develop on my local machine [still works flawlessly],
push my changes to my BitBucket repo [still okay here],
and would subsequently pull those changes to my shared hosting server (RedHat) [still running smoothly],
I then run my dependency managers (npm and composer) to get the project in place and functional
there is some matter with clearing various caches:
php artisan view:clear
php artisan route:clear
php artisan cache:clear
composer dump-autoload
and finally move my '/public' folder to the web root and update index.php to point back to the 'bootstrap/autoload.php' in main project structure,
I am aware there is likely another or several steps I am missing, but I am unsure what they are...
All that being said, I've attempted to deploy a number of applications using Laravel lately and I always seem to run into the same issue come time to deploy an application to production. I've read 30+ tutorials on the matter and nothing seems to explain the issue why my site isn't working any more.
I've checked the error log file maintained by Apache, it's empty.
Was wondering if it's a permissions issue, doesn't seem to be the case (all folders set to 775 and files set to 664 as specified by various sources and owned by serverName:userName)
Browser console simply shows a 500 server error.
All I see if "Whoops, looks like something went wrong." twice.
There must be some way to show better error details (config debug setting already set to true)
Any suggestions at this point would be beneficial to send me looking in the right direction!
======= UPDATES =======
For the sake of thoroughness, and that this save others from severe headaches, I'll be posting actions taken here.
Following tutorial mentioned by #user123456 (permissions applies)
Generate new key for application
Run php artisan config:clear
Off to the races, answer to come!
You need to ensure you have a working .env file.
Once done, run php artisan key:generate to create a key for your application after which you should clear your application's cache as follows php artisan config:clear
I would never recommend using shared hosting for Laravel application. You will face lots of issues for permissions, composer and external dependencies. Instead, you can use cloud servers like DigitalOcean, Linode, vultr and deploy laravel application on them. If you don't know about linux and creating Stacks you can use Cloudways to deploy laravel.
https://dev.to/rizwan_saquib/deploy-laravel-application-on-cloud-easily-with-cloudways
I'm a bit fresh to Laravel. I installed it via composer in the xampp/htdocs file. I installed the latest version 5.6.
The install works with no errors, and the file structure is as it should be.
When I run the php artisan serve command from inside the folder, it deletes the server.php file and therefore outputs the error:
This site can’t be reached.
localhost refused to connect.
So I thought why not just add a new file inside and it will work... Well, trying to add new file shows that I do not have permissions to add files to this folder.
I tried a new install a few times, but the situation is always the same.
Has anybody else encountered this problem?
So I realised it was some kind of server problem... well, removed the antivirus, chanhed my firewall settings and everithing works as it should.
My advice to avoid this in the future is to start creating Laravel applications in a folder inside of your My Documents folder in Windows or using /home/{your-username}/projects directory in Unix environments.
What likely happened is xampp has certain permissions that don't play nice with what you need in Laravel.
I'm trying to copy an existing Symfony project to another directory, so I can test changes before applying them to the live version.
I get a 404 error whenever I try to access the project on the copy via app.php or app_dev.php, and I can't pin down why. The live project is in a folder called representation/mvcrep and the copy is in a folder called representation_dev/mvcrep, and they are both on the same hierarchy in the directory tree.
I've already successfully cleared the cache for both the dev and prod environments in the copy, with no decipherable result. There are no errors in the Symfony logs, and the 404 is one for the site not for Symfony, so I'm assuming it's a problem with the server. Both projects have the exact same permissions as well.
Anyone have any clue to what the problem could be?
Edit: To clarify, the web directory has not been renamed or modified.
As you reported that you use two subfolders in the same virtual host, the web server configuration is probably not the issue here.
Since I suspect permissions issues, I suggest you to debug by creating a base text file in the /representation_dev/mvcrep/web folder, e.g. hello.txt, and see if you can get that via browser.
If not, check the permissions on the newly created folder.
There is not enough info for a precise answer, but this sounds definitely more like a server configuration issue than a Symfony issue,
If you make a copy of your Symfony folder, you also need to create a new web site that points to the new installation.
I.e. previously you browsed the site
http://representation.local/
which has its web root in
.../representation/mvcrep/web
Now you need to create a new site
http://representation_dev.local/
which has its web root in
.../representation_dev/mvcrep/web
A year ago, I decided to go with codeigniter instead of laravel, because codeigniter prooved to be easier to setup. I am now preparing for my next project and it seems as if codeigniter is now obsolete (at least most of the people seem to recommend laravel over codeigniter).
Now to my problem: I use a virtual ubuntu machine for developing web apps so I have a dev environment similar to the production environment (this helps me to avoid some problems (especially case-sensitivity...;)))
I installed composer and laravel and created a new laravel project named "quickstart" in /var/www/quickstart. I then followed their "getting started guide" (here: Guide). So far everything worked.
But here come the problems:
I have two other web applications in /var/www, so when I enter the ip of the machine I see the 3 directories.
Issue 1:
Normaly I'd expect that as soon as if I click on the "quickstart"-Directory in my browser, the webapp would get displayed, but I have to click a second time on "public", and then the webapp is displayed.
Issue 2: Of course, the links on the page are wrong too, because they reeer to (for example) "/task", which can't be found on the server.
The problem is that I'm not really experienced with apache configuration. I suspect it has something to do with VirtualHosts, but AFAIK you need to have root access to configure virtual hosts, and I do not have root rights on the dev environment.
Could you point out a way to me how I can make laravel work in a subdirectory in a way that I can just move the files and folders to my hoster as soon as I have finished the project? I'd like to then change only one file, and not all paths and URLs in all files ;)
Regards,
Christian
Thanks to Bogdan, I was able to figure it out. My hoster allows symlinks, so I did it like so:
I put the laravel installation in
/srv/web/quickstart
(quickstart is the name of the project). I then created the following symlink:
ln -s /srv/web/quickstart/public /srv/web/www/public
The document root of the apache is configured to
/srv/web/www/public
After that I just got a blank page. That was because I forgot to set the correct permissions on the storage-folder. So I set the following permissions
chmod -R 777 /srv/web/quickstart/storage
This is fine for a development environment. For production I'd recommend to only allow the webserver-user to write into that directory.
And voilà: Everything works!
Thank you for your help bogdan.
Christian