Migrations in production Laravel - laravel

I'm working on a personal website, and i try to find a solution to a problem and any help would be welcome.
I work with Github because I'm working from several places (work, home...), and I'm wondering about migrations when I transfer my application in production. Locally, I don't have any problem, I do my migrations, and run artisan migrate, but then when i put this online, I HAVE to log in to my server, run the migration from the command-line, and then edit the migrations file online again.
I know this is not the good solution to do this, it's really not good for long term usage and bigger applications than mine.
And little other question, what would you advise me to use to push automatically my master branch from git to my server, I have heard about Heroku, is it easy to get working with it ?
Thank you

If you are using Laravel 5 you can take advantage of Envoy. It is exactly what you want. You can set tasks for many servers (basically you can write any commands you want like updating from git or running migrations). Taylor wrote the documentation very good, so you can get started very easy.
A quick example for SSH in a server, update form git and run migrations:
#servers(['web' => '192.168.1.1'])
#task('deploy', ['on' => 'web'])
cd site
git pull origin {{ $branch }}
php artisan migrate
#endtask
For Laravel 4, you also have Envoy task runner.

Related

Production Server and Local Server get different result

I build API project using Laravel 8, and I put my project on Git. My production server using Ubuntu Apache. I use only 1 database, and it's use on my local and production server.
I have weird problem since yesterday and make me confused. So, I push the latest commit to my Server from Local Server. Everything went well. But when I try to run my API via Postman, the results from my Local and Production server are different.
I checked manually in the files I pushed from local, everything is exactly same.
I try git status, everything OK. git pull are up to date. Here i attach the screenshoot.
Since i use laravel, i try to clear cache with php artisan cache:clear and it doesn't work.
Here i attach my Postman result:
As you can see, the result are different. I believe, there is no error with my code, It's work well on my Local server.
I try to contact my server provider, but didn't get any solution.
Anyway, this is Header from Prod Server
I'll appreciate all the answer from this thread. Thank you
Are you working on same branch in local and server? check your git branches in both.
Thank you for the answer and comment.
I already solve this problem. The problem pure from my production file and server.
first i try to restart my docker, and then run php artisan config:clear.

Laravel setup on HostGator VPS

I want to deploy my Laravel App in a VPS hosting plan.
I have a WHM, but I've no experience deploying my app and configure the server.
I don't have a domain, so I want to test my app using an IP address (like DigitalOcean)
any help?
Edit:
I've completed these steps into my WHM.
Have SSH access to the VPS
Have a sudo user and set up some kind of firewall (for example ufw)
Install required software (nginx, MySQL, PHP, Composer, npm) and additional PHP modules if necessary.
I've created an account ( CPanel ) and I've completed steps
Create a database
Checkout your application using VCS like Git
Configure your .env file.
Install your composer packages, run npm, or anything you would like to do
The account ( CPanel provides an IP address that looks like http://xxx.xxx.x.xx/~cpanel-account-name/).
I can access the website correctly ( however all images are broken and even laravel-routes are not found 404). I know the issue is because ( ~cpanel-account-name/ ) found at the end of the URL.
But how can I fix It?
Since this is quite a broad topic that consists of multiple questions, perhaps you could elaborate on steps you have already taken or the step you are stuck at / need help with?
In short, you need to do the following:
Have SSH access to the VPS
Have a sudo user and set-up some kind of firewall (for example ufw)
Install required software (nginx, MySQL, PHP, Composer, npm) and additional PHP modules if necessary.
Create a database
Checkout your application using VCS like Git
Configure your .env file.
Install your composer packages, run npm or anything you would like to do
Set-up nginx
If this seems daunting, I would advice to tackle it one by one and trying to research every step along the way. This might be challenging and time-consuming, but will be very rewarding!
Alternatively, a paid solution like Laravel Forge can help you take care of server management.

Why don't my Laravel 5.2 events work on production when they work locally?

Locally, my Laravel 5.2 project works well, including events that are queued using Redis.
IMPORTANT UPDATE: I later discovered that this premise was incorrect (and my events don't use Redis), and so I'd accidentally posted this question in a misleading way. I hope my ridiculously long struggle and my answer below will be helpful to someone else who is an events newbie too.
But I've deployed my project to a production server (where I'm using a Laradock Docker setup).
There, on production, Redis works for caching and for delayed dispatching of jobs.
So I know that my Redis setup is good.
But events don't work (even though they worked when my project was on my local computer).
My question is not a duplicate of Laravel 5.2 event not firing in production because I'm not using broadcasting and because I am using Laradock.
I've also already tried these commands (inside the container at docker exec -it laradock_workspace_1 bash):
php artisan config:cache
php artisan clear-compiled
php artisan optimize
composer install --no-dev
composer dumpautoload
php artisan queue:restart
My events are working on production now. Here is what I learned:
I'd read https://laravel.com/docs/5.2/events many times, but I don't know where/why I got the idea that "events" (which were a new concept to me) relied on Redis or cron jobs. So the entire premise of my question above was wrong! I was not using Illuminate\Contracts\Queue\ShouldQueue, so everything was synchronous and should have been more straightforward than I was thinking.
I think this tip about composer dumpautoload and php artisan clear-compiled was helpful (for after each edit of files on production).
The main issue seemed to be that a certain database table of mine seemed to have records with weird values, and those records were being checked by the event, and that's where it was all breaking.
And I think these records probably got into that corrupted state because on production I don't think I'd started the cronjobs and workers immediately upon deployment.
My local environment was working because its table didn't have these corrupted records.
Hopefully my naive and misleading question (which led to this ridiculously long struggle and this answer) will be helpful to someone else who is an events newbie too.

How to setup Bitbucket Pipelines for Laravel test and SSH Agent to deploy on a remote server

I am developing a project in laravel 5.4. I have repository on Bitbucket. Now I want to setup Bitbucket Pipelines so I can test when anybody commit. I think I need a suitable Docker Image for laravel, I tried some images but they generate errors. Also I want to setup SSH key agent so Whenever I commit in production branch it deploys on server.
I searched a lot on internet to do these things but I could not find anything, If you share any detailed tutorial or something like this it will be helpful.
Thanks in advance.

Artisan command affecting wrong database

I have two laravel apps, the first is used as a Server Management System (SMS) that creates a host on the server. When this host is created it does a git clone to bring in the second laravel app that is used as a CMS for that host.
What I am trying to do is create a plugin within the SMS so that you can just select a check box and it will install the CMS for you when you create a new host. I have most of the code in place and I am testing locally and everything works grand until at the end when I try to install the migrations, when I try to run;
'php artisan cms:update'.
I also tried;
'php artisan migrate'.
What ends up happening is that rather the command being run against the CMS database, it is affecting the SMS's database adding a couple of tables and breaking the SMS database. I have done a 'pwd' and checked to make sure I am in the correct directory;
'/Directory/Directory/host/cms'
As it makes more sense for someone to read all of the code rather than snippets here is a link to the plugin:
CODE LINK
So to clarify what I need is to be able to test the plugin locally so I need the migrations to install into the correct database, and make sure the CMS works before I push to production. If anyone could shed some light on why the migrations is affecting the SMS rather than the CMS it would be greatly appreciated.

Resources