Artisan command affecting wrong database - laravel

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.

Related

How to migrate Laravel database on Docker onto Google Cloud

My Laravel app is running on docker using Linux commands on a Windows Machine. This means instead of using 'php artisan' commands, I use 'sail artisan' commands. I am able to migrate locally onto the SQL server on docker (sail artisan migrate) and am able to deploy the app onto Google Cloud (gcloud app deploy). The final bit of my puzzle piece is migrating the database onto the Google Cloud SQL server.
When I was first setting the app up, I had problems with this so I exported the SQL server, uploaded it to Google Cloud and then deployed it manually which was fine for a one-off but I now have things I would like to change about the database structure without losing all the data. I also figured it was about time I learnt to do it properly anyway.
I have attempted to use the instructions on Google's community tutorial, however, this guide presupposes the project does not yet exist whereas I am working with a pre-existing application and a pre-existing database. I tried to jump into the tutorial halfway through but I couldn't get the Cloud SQL proxy to work.
After a bit more research, I found this article which I got partway through, however, once I got to the part needing TCP or Unix sockets, neither set of commands will run without error on my Ubuntu terminal.
If anyone knows of any useful articles or has had this problem themself, I would greatly appreciate your help.
Additional Info:
Laravel Framework 8.69.0
Vue version 3.0.5
Docker Engine Community 20.10.8
SQL server 'europe-west2'
I'm not aware of anyway to run sail/artisan command line commands on GCP.
However in ./vendor/facade/ignition/src/Solutions/RunMigrationsSolution.php there is the following function
public function run(array $parameters = [])
{
Artisan::call('migrate');
}
which can be used to programmatically run migrations.
So in ./routes/web.php make a route like
Route::get('/run_migrate',
[DataController::class, 'runMigrate']
)->middleware(['auth', 'verified'])->name('run_migrate');
and in ./app/Http/Controllers/DataController.php add the function
public function runMigrate() {
Artisan::call('migrate');
}
Now after signing in as an authorised user (or if you remove the auth middleware you won't need to sign in) you can go to https://your-app-url.com/run_migrate and it will run any outstanding migrations.
To be able to do this the schema table has to exist so you will have to import your local database to start.

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.

How to modify laravel view file names

after using artisan make:auth, laravel creates views in storage/framework/views using scrambled file names. I suspect the filenames are created using the app key. Now the problem is that when I port this to the integration server, artisan uses different file names for those views, and seems to create new files with those new names.
How can I tell laravel to use the views that artisan created on my dev machine, even on the staging environment.
For troubleshooting I changed the app key on integration to be the same as my dev machine, but a) it didn't take care of the problem, and b) I'm sure that's not the intent.
Any help is very greatly appreciate
Files stored in storage/framework/views are cached views and basically there's no need to touch them directly.

Migrations in production 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.

Laravel 3: Run migrations on production server / in .php file

I have been working with Laravel 3 on my local server. I have been using terminal and Artisan to perform my migrations.
I want to install my site on my production server, but I want to create a sort of 'install/migration' script that will perform all the migrations and guide a user through configuration.
I have found where all migration methods are (used by artisan) but I'm struggling to use them. Anyone know how?
I think you are confusing some things (I'm not sure, so I'll tell just in case).
Migrations are meant for developers. Your end users don't run migrations directly. So migrations are for you and your fellow developers. If you want your users to run migrations, than you just create a normal page and have some link or a button that the user presses and this will run an action (a function) on your controller (if you have routes set up this way). In this function, you should run the migration.
Running migrations from PHP: you can use the Command class to run tasks.
Command::run(array('migrate'));
This will run the migrate task, obviously.
Is this what you're after?

Resources