Pulling updates from Git on running project - laravel

I have a laravel app deployed on an apache2 server in an ubuntu VM.
It took an awful lot of time to set up, but I would like to make some more changes to the website, e.g. now I added a footer.
Is it safe / possible to just pull in the repository so the updates get installed on the project and then restart apache?
I did google but haven't found anything specific, hence why I am asking here.
Since it took so long to setup I am scared that I break something.

Make sure that the file permissions and ownership is correct. If the files are owned by www-data, and you git pull with your own user, and a new file is created, the new file will be owned by your own user instead of www-data. It's possible to create a git hook that will chown file files for you, but you might as well just do it in your own script after pulling the changes (e.g. chown -R www-data). You can also use sudo to run the git operations as the www-data user, e.g. sudo -u www-data git pull --ff-only.
Additionally, make sure you use git pull --ff-only. --ff-only will refuse to merge if for some reason the repository on the server and in the upstream differ due to conflicts (e.g. a force push). This will prevent git pull from creating merge conflict markers in files, which will probably break your code with syntax errors.
It may be safer to move your git repository into a different folder, do the git operations there, then fix the file permissions etc. and then rsync or otherwise overwrite the files in the directory which Apache is using.
As for Laravel, you'll want to follow the deployment steps outlined in the documentation.
composer install --no-interaction --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache
The :cache commands clear existing caches and re-cache the configuration files, route lists, and compiled Blade templates. If you're previously used the cache commands, you'll need to run these or your new code changes related to configs, routes and views won't take effect. If you haven't previously used these, you probably won't need to use them.
You may also need to run php artisan migrate if you have new database migrations. You may also need to run npm install and npm run prod or other npm related build commands, if you're using Laravel Mix, for example.
After this, you'll want to finally reload your Apache2 instance (sudo service apache2 reload) to clear the Apache2 opcache (if you are using opcache).
Finally, if you're using queues, you'll need to restart your queue workers. The procedure here differs depending on what you're using to keep the workers alive. For example, if you use supervisor as documented here, you might do sudo supervisorctl restart laravel-worker:*. Do this after all of the previous operations, so that the workers are running on the latest code.

Yes, you can pull your code and run these commands to remove your old version caches.
php artisan view:clear
php artisan route:clear
php artisan cache:clear
php artisan view:cache
php artisan route:cache
you didn't need to restart your apache service.

Related

Laravel throws Facade root error on key:generate in pipeline

I just tried to push a commit on a project. When this happens, my GitLab CI picks it up and tries to install the projects dependencies via Composer in it's Docker container. After installing the dependencies, it'll copy the .env.example file to .env and run php artisan key:generate
However, when it does this, my pipeline crashes on the following:
$ php artisan key:generate
In Facade.php line 258:
A facade root has not been set.
I've tried to set the key locally in various ways, removed composer depenencies and reinstalled them, but in none of those scenarios, I encounter this error in my local environment.
Is this a known bug in Laravel? (6.18.0)
Thanks.

Run Laravel phpMyAdmin via php artisan serve

I have a Laravel project running with php artisan serve (no Apache or Nginx) on:
http://localhost:8000/
I have then ran this successfully
composer require phpmyadmin/phpmyadmin
My question is, what additions to Laravel's routing etc. must I do to run the following?
http://localhost:8000/phpmyadmin
Though I haven't found a specific way to have
http://localhost:8000/phpmyadmin
working through Laravel as part of php artisan serve, there is a simple solution that works just fine using PHP's native server instead, assuming you have mysql installed as localhost:
composer create-project phpmyadmin/phpmyadmin
cd phpmyadmin
ls -la #files look like classic phpMyAdmin, note however `vendor` folder in place along with package.json
php -S http://localhost:7000 #and you should be able to see and log in!
This does everything I need it to do. If you want to install phpMyAdmin through an actual webserver like Apache that runs always, you're better off doing something like apt-get [or yum] install phpmyadmin and then you'll have a directory override from Apache running:
http://www.mylaravelapp.com/phpmyadmin

Downloaded laravel project hangs on preloader when deployed on localhost

I'm trying to deploy a laravel project I have received onto my localhost but it hangs on the loading page and doesn't load the site.
I received the source code of a laravel project that was coded for me.
The deployed website on the shared hosting works properly, and I can also manipulate the files through my ftp access.
However, I'm trying to deploy the project on my localhost (as well as to migrate to a different shared hosting service).
I tried loading the server on wamp, homestead and with artisan serve, but all methods end up the same - the index.php seems to be loading, but is stuck eternally on the preloading .gif file and doesn't present the site.
the browser debugger is throwing a lot of javascript errors (see attached image)
I assume a have a config problem, but I can't locate it and I am unsure how to even locate & debug the issue.
I tried following these configuration steps:
1. changed .htaccess to generic laravel .htaccess (deleted cpanel related lines)
2. changed the .env to fit my wamp db / homestead db
3. composer install
4. composer update
5. php artisan key:generate
6. php artisan cache:clear
7. php artisan migrate
I also installed laravel-debugbar but it hasn't helped me out of the box, and I'm unsure where I need to try to catch the problem.
If anyone can give me pointers on how to understand my problem better, I would be very thankful.
Thanks in advance!
laravel bug
Double check your .env if all details are correct
Set APP_DEBUG=true in your .env file
Double check if your database exist and have data if you are using a database
Check if your host is added to /etc/hosts
Check if your host is added to apache/nginx config correctly
Try running these commands:
$ rm composer.lock package-lock.json
$ composer install
$ npm install
$ npm run dev
$ php artisan clear-compiled
$ php artisan optimize:clear
$ php artisan package:discover
$ php artisan storage:link
$ php artisan migrate:fresh && php artisan db:seed // optional!
Then clear browser cache to be safe.
Open web inspector to see if you can see any errors.
Open latest laravel log in storage/logs/ folder to debug.
If all fails, install laravel-debugbar and see if you can debug there.

Laravel with php 7: No supported encrypter found

This question has been asked for many times, so let me list the steps I did on it:
Setting 'cipher' => 'AES-128-CBC', (original AES-256-CBC);
php artisan key:generate
pasting the new key to the .env file
but the error remains the same.
In phpinfo, mcrypt shows enabled, although there's no extension in httpd.conf. Some answers says that the extension is integrated with php 7.
The project is downloaded from git and installed with composer and npm, the .env file was sent from another developer.
Might be there is a problem with your mcrypt. You need to check whether mcrypt php extention is installed or not and it should be enabled.
on command prompt run php -m | grep mcrypt
if you couldn't find in your apache just install it.
https://www.myoddweb.com/2010/11/18/install-mcrypt-for-php-on-windows/ here is the link.
After performed last two steps from you listed into your problem, have you clear config cache?.
If not then you must run php artisan config:clear because Laravel caches all config data.
Also why you change cipher? if no reason, revert it with original and performed the steps again.
Might this work for you.

Laravel 4 Class not found in bootstrap/compiled.php

I have created a new branch using Git, applied some updates to my code, checked out that branch on my staging server and I now can't run anything composer related.
I've added some new packages to composer.json which work on my development environment, but as soon as I try composer update on the staging environment I get class not found errors relating to the classes it's not yet downloaded.
I've tried
composer update
composer dump-autoload
php artisan clear-compiled
php artisan dump-autoload
php artisan optimize
But all result in the following error
PHP Fatal error: Class 'Artdarek\OAuth\OAuthServiceProvider' not found in
/var/www/sites/x/bootstrap/compiled.php on line 4321
Script php artisan clear-compiled handling the
pre-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Fatal error: Class 'Artdarek\OAuth\OAuthServiceProvider'
not found in /var/www/sites/x/bootstrap/compiled.php
on line 4321
What else can I try in order to get composer to download new files?
php artisan optimize --force
That command will re-generate /bootstrap/compiled.php
The --force arg is needed to re-generate the file when your environment is in debug mode.
I'm sure there is a more elegant way of dealing with this (and please accept any answer that provides that over this one) but this can probably be solved by deleting the entire vendor directory and running composer install again.
I know its not pretty but sometimes it's easier and quicker.
I had the exact same issue, which I solved by uploading the project again through filezilla to my server.
That doesn't solve the issues you are having with composer, however. Which begs the question: Assuming that you are working on a dedicated server, do you have composer installed globally in your server? If not you should still be able to do a php composer.phar update or just create an alias.
I might have misunderstood your question, and I realize that your question was asked a while back, but hopefully it will be helpful for someone else.

Resources