I have a website in Symfony linked to a a MySQL database. The website is having some troubles, so I have to update the information in the database. The thing is, when I update on the database, it stays updated there but on the website it doesn't show any changes.
For example, a user is registered. I go to the database to change the email so I can register another account with the same email. The database is updated with the new email, but on the website it says that the old email is still in use.
I know that I am updating the right database, because when I register a new client on the website, it appears on the database. Any ideas on to why this might be happening?
Like Angel Iliikov mentions in the comments, it's very likely a caching issue. The following suggestions assumes you have access to the command line - which a typical Symfony user should. If you don't already have it, most hosting providers allow you to get SSH access.
Clear the following caches:
1. Symfony's cache
Symfony will store a lot of data in the cache files to prevent it from having to process requests from scratch. When Symfony apps go wonky, a very common fix is to clear this cache and retry. The standard way to clear this cache is with a console command run at your project's root directory:
$ app/console cache:clear
If you run into issues, David Soussan answer provides more information on this one.
2. Doctrine's cache
According to commenters on another question (formatted by me):
The doctrine cache is often stored in apc rather than in the file
system so removing the cache files would not help. The general app/console cache:clear is only for the symfony (app) cache. I don't think it clears the doctrine cache(s).
-caponica
Alternative PHP Cache (APC) is an optional component enabled in php.ini. It's possible Doctrine is caching information there as well if it happens to be enabled.
The accepted answer on the previously mentioned question provides an answer for clearing Doctrine's cache:
$ app/console doctrine:cache:clear-metadata
$ app/console doctrine:cache:clear-query
$ app/console doctrine:cache:clear-result
-amitchhajer
3. Your browser's cache
This is very unlikely to be causing any issues. But if you are doing something to send caching headers over HTTP - it's possible that the application would have properly updated the data, but your browser is displaying an old page.
Each browser has a different way of clearing cache. Google provides support for how to do it Chrome. and Mozilla provides support for how do it in Firefox.
If clearing the cache doesn't solve your problem, it's likely a problem with your application or workflow and will need debugging. A few things you can try:
Make sure you really updated the correct database. Confirm this
on two separate DB clients.
Create your own Symfony
command
where the only thing you do is query the database. If it returns the correct result, you should check that other components are using the same query. If not, check your config/parameters to ensure you're using the right database.
If your Symfony application is not showing the updated database record that is because it is using the cache which still contains the old data. This is often a problem with Symfony, refreshing the page just reloads from the cache. Try clearing the cache first. Now, very often cache:clear does not work from the command line, I've had it happen all the time and never really understood why. The answer is to just delete all the cache files, as per Fabien Potencier's tip: http://fabien.potencier.org/a-symfony-tip-clear-the-cache-without-the-command-line.html. That works and is my go-to solution for when eg; composer update did not clear the cache afterwards. In fact I got into the habit of just deleting the cache files on my dev machine before doing composer install or update.
Adam,
Use these commands to clear your cache:
# dev environment
$ app/console cache:clear
# production environment
$ app/console cache:clear --env=prod
I had problems using the mysql database supplied by my host server at first but then I installed the latest mysql database version available in softaculus inside my host server and then I was able to access mysql inside softaculus or directly by the url (www.mypage.com/mysql). Finally it works perfectly. You can try to do something similar.
Related
I'm using a Mac. Can not execute the command
php artisan cache:clear
I get in return:
Failed to clear cache. Make sure you have the proper permissions.
This is for Laravel. Any ideas how to fix this?
create storage/framework/cache/data directory manually.
This could be one of several things(need more information to narrow it down):
No cache files/records exist.(Updated to reflect your latest comments)
If you are running a webserver (apache or ngix) as a different user, then you won't have permissions to the files as yourself.
If you are using a cache driver other than file, like redis or database, make sure the credentials provided are correct.
There could be a bug in the version of Laravel you are using; this would be unlikely.
Expansion on points 1 and 2:
This is normal behavior. If you have opened pages expecting them to be cached and they are not, split the page and utilize #include directives splitting out the dynamic and static elements of the page into separate blade files.
I like to add my user to the same group as the web server's group(www). Then change the group for all of the files to www, with group read permissions, and write permissions only on the bootstrap/cache and storage directories.
I think it might possibly be a bug with the latest version of Laravel, however unlikely it may seem. I started a new project today and installed a fresh copy of Laravel 5.7 and it seems to cause the error above. However, if I use 5.6 then the error does not appear.
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 tried some solutions (ex: Transfer Symfony2 site onto localhost from web server), but never works, the result is always a blank page.
The project is on Symfony 2.3 and my php version is 5.5
Thanks
When accessing a Symfony2 site locally you need reference one of the routing files in the web folder directly. So try http://localhost/app_dev.php/ and it might give you an error message telling you what is going wrong. Also you can check the log files in the /app/logs folder to see what the problem might be.
Edit:
There are also several command line tools that might be needed to set up the project.
app/console doctrine:schema:update --force
This will check the database is in sync with your code and update the database if necessary.
app/console assetic:dump
app/console assets:install
app/console cache:clear
These are used to install css, javascript and other static assets as well as clearing the cache.
Context : I have been asked today to add a new feature on a quite old project (something like Symfony 2.0). It consisted in adding a new attribute to an entity and add the corresponding field to the edition form. Child play : I have edited the code and it works well in dev environment (set directly in app.php)
Problem : When the environment set in app.php is prod, the entity is not persisted when the form is submitted, nor retrieved when the form is loaded.
Investigations : What I have checked so far in prod env :
The submitted form is correct
The controller manages to map the form and to hydrate the entity correctly
I have deleted the cache multiple times both manually and from command line
I have checked the SQL query after the form has been submitted, the query does not update my new field as expected
Supposition : The problem seems to apppear when the entity is flushed, it is like the new field was completely ignored.
Assumption : After having exposed my problem to more experienced symfony developers, the only suggestion was that there may be a PHP cache (not the symfony one) somewhere parasitizing my prodenv. This assumption is being tested (I could not restart apache myself) and I will be able to test it maybe tomorrow in the best scenario.
Still, I feel like the PHP cache assumption has 10% chance to be the good one. I can not share with you the whole project code, but I am asking you if you could post every idea you might have regarding this issue.
UPDATE : I have restarted Apache2. Problem is still persisting. It seems like Doctrine builds its cache on a former version of the project (It does not see any changes in the annotations for example) even though app/cache/ is empty. Any idea ?
I have deleted the cache multiple times both manually and from command
line
Can you clarify? Symfony's cache is not the same as doctrine's. Depending on your configuration doctrine could be using something like apc, reddis or something else to cache its own queries and result data. If you haven't yet, try to perform these commands:
app/console doctrine:cache:clear-metadata
app/console doctrine:cache:clear-query
app/console doctrine:cache:clear-result
If you're still out of luck, I'm more than 10% sure that an apache restart will do the trick.
If this worked, you should check your prods config yml and see if you find something like:
metadata_cache_driver : something
result_cache_driver : something
query_cache_driver : something
Full answer was to execute :
app/console doctrine:cache:clear-metadata --env=prod
The caching was caused by a memcache configuration only present in production environment.
I need to install and configure an existing Laravel 4 project.
I tried to do, but when I ran composer update or composer install a lot of issues appear.
I have the database too (with data) so I ran the migration but doesn't work because the console show me an issue about the "table doesn't exist".
Can anyone tell me the complete process to configure the App?.
I mean, what its first, second and so and so because maybe in some step I made a mistake
To install and configure an existing project, you'd typically
Check out its source code
Run composer install
Run php artisan migrate
Check the README for specific instructions on installing 3rd party assets, or any additional steps you'd need to take
If the above creates errors, its either because of something in your environment (installing over an old project?) or some problem with the way the Laravel developer created their project.
To install and configure an existing project, you'd typically check those things first :
You should goto app/config/database.php check file and verify username and password.
After check in Project Folder vendor folder and composer.json file exist then remove it (that remove old configuration now we going to fresh configuration).
Then after back to command prompt and fire command composer update and that download some dependent file download.
Now Run php artisan serve
that tricks work for me last time when I migrate another host.
Carlos, when using an existing DB you'll need to check the migrations table to see which migrations have run successfully. Typically when taking over a laravel project setting up a new db and running the migrations against it is a good idea because you never know what hacks were made to the database outside the migration system. One small change can throw the entire system into a useless state because it's looking for a table or column that doesn't exist or has been modified. If you run the migrations against a bare db you can also figure out which tables were manually created (which could very well be your issue) outside the system and add them in as necessary. Cobbling things together after a previous developer is tedious, hopefully there is decent documentation.
Note that if you are using Git with .gitignore, don't forget to copy .env variables in new location too.