Deploying Laravel 5.4 to Shared Hosting - php

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

Related

Quick Admin Panel | Unable to locate a class or view for component (only when live)

I am trying to get a Laravel 8 project up and running on Hostinger's shared hosting. I realize I'm already complicating things but have successfully set things up besides the components. I am using Povilas' Quick Admin Panel (Livewire ver), and it's this that requires components that are only 'missing' when on production server. Everything runs smoothly on localhost.
I've read that this may be caused by namespace issues - the environment may have case sensitivity (if so, how can I work around?). Other posts explained how each component should be visible in Http\View\Components as well as in resources\views\components. I've also read something on the existence of default/packaged components but can not find documentation on these individual ones.
I am looking for components 'x-application-logo', 'x-dropdown', 'x-dropdown-link', 'x-responsive-nav-link', and more. I do not see ANY of these in my local files, yet it all works fine in a local environment.
Yes, I've seen very many similar questions asked. However, in all of those cases, the askers were able to visually locate their component files, or were using self-declared components...
Has anyone working with Quick Admin Panel had similar issues?
I've attempted:
php artisan cache:clear, config:clear, view:clear,
php artisan optimize,
composer dump-autoload,
recompiling with npm then reuploading files,
composer install (and composer2 install)
I ended up installing a fresh instance of Jetstream to copy over its source files. After a few tweaks I got something to work without errors... As I've come to find out, the entire admin panel that I was working with had wiped itself, and for some reason started requiring an instance of Jetstream?? I have no recollection of touching any sort of configuration regarding this, so either there's a carbon monoxide leak in my home, or Hostinger is deciding to automatically mess with my Laravel files for one reason or another. Thankfully I have a proper local version of my project, which I will use to reattempt.

What is the best way to deploy changes in Laravel

We already have a Laravel web app hosted in the cloud (AWS EC2 instance). Let's say that changes will be required to be made, such as revising the (blade view) layout or adding new reports.
After I make the changes to the local controller, view and route files, do I simply copy them to the cloud host? Laravel keeps a cache of the blade view files. Will they be updated when the blade view files are updated? What other items do I need to do?
The views caches will be automatically regenerated, but you can force delete the cache if you want. php artisan cache:clear.
For routes, it's parsed from the file, so no worry there.
If you change config at some point, make sure to run php artisan config:clear.
If you touch the services and something is still not working, try php artisan clear-compiled. it will force the regen of the bootstrap.
The best way would be to use a source version control software like git and implement a pipeline on a service like GitLab.
I recently implemented one with this tutorial.
It exploits GitLab pipelines and Larvel's Envoy to automatically run tests and deploy your code that passed each stage you defined. It also allows you to rollback to previous versions at any given time.
For deploying PHP applications in any framework, you can use various tools. The most simple is PHP Deployer, and i recommend you to use it if you're not familiar with automatic deployment. You can set a sequence of commands which will be launched during deployment e.g.
git pull origin master
php artisan cache:clear
php artisan migrate

How can I organize my laravel project's github repository so that users can easily install and run it?

Five months ago I created a pretty extensive Laravel Blog Management system. I am now at a point where I am looking for a job and would like for potential employers to be able to easily install and run my project to check it out. I want to include instructions in the readme.md on how to get it started but I've just realized that I can't figure out how to run it myself!
Here is the repository: https://github.com/colesam/Laravel-Blog
Here is what I've tried:
git clone git#github.com:colesam/Laravel-Blog.git
composer install
php artisan serve
This copied the repo into my xampp/htdocs directory and ran it. XAMPP is currently running with MySQL and Apache running.
The console responds by telling me it's being served on localhost:8000. Unfortunately I receive an error message on the actual html doc:
What is going wrong with my project and how can I make this as easy as possible for my potential employers / anyone who would like to download and check out my project?
It's really easy actually. Takes about ~5 minutes. Here are the steps:
Clone the project
Create a database
Copy .env.example to .env and set the correct database credentials
Run php artisan key:generate to generate the app key
Run php artisan migrate to create the tables
Run php artisan serve
And you're done.

php artisan optimize times out only on composer install

I'm running a laravel app on Azure. Things are moving in the right direction, composer install didn't use to work at all. Now however, the "php artisan optimize" command times out:
However, running "php artisan optimize" separately is no problem at all:
What could be the cause of this?
Edit:
Deleting the symfony-folder does not help, it is not present when I run the "Composer install"-command:
Increasing the timeout-limit does not help either, I increased it in both azure and in the composer.json file:
This still gives me a timeout, after installing the symfony-components again:
...
As I deployed a new clean Laravel 5 application to Azure Web apps and tried to reproduce your issue, however, it worked fine on my side either I run the command php artisan optimize or composer install or composer update.
I installed the composer at the Site extensions at the KUDU console site of the application on Azure Web apps, the url should be like: https://<your_site_name>.scm.azurewebsites.net/SiteExtensions/#gallery
There are several solutions of other developers who occur the same issue with you, you can try these solutions:
try to increase the max_execution_time or set the value to 0, refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/#how-to-change-the-built-in-php-configurations to change the PHP build-in configurations on Azure Web Apps. And you can change the process-timeout in Composer.json file :
"config" : {
"process-timeout": 0
}
deleted the entire Symfony folder and try again. As the comments at PHP Artisan Optimize - Timed out? #1050, it seems the symfony dependencies raise the issue.
#Rkey,
According to my experience, I think the issue is more related to the symphony version/configuration. I suggest you can remove/edit the symphony configuration from the composer.lock file (NOTE: please backup this file if you cannot success, you also can recovery your environment). And then you can run this "composer install".
After installed component, You can see an alert window which shows that
your session is timeout, please refresh your browser.
You can see this information because the server is in initialization process.
Any concerns, please feel free to let me know.
I'm also having this problem. Will upgrading the plan help?
According to this upgrading to S3 helps... I haven't tried it though... Let me know if it really works.
#Rkey & #cabs, per my understanding on this question, I wanna point out that Composer is not fully supported on Azure. The issue is that it’s using Taskkill command which is blocked on Azure. We are aware of this and please feel free to submit an idea or suggestion based on the experience with Azure at https://feedback.azure.com/forums/34192--general-feedback.
I have been stuck in this problem as well for a week.
Have tried all solutions on forum but no success.
This morning finally solved after reinstall XAMPP. It was problem on my previous PHP version 5.6.19. While using new XAMPP with PHP version 5.6.28, it worked fine.

Uploading Laravel 5 Project to Shared Hosting

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.

Categories