I have two servers (on locally and one production). They have the same settings. The only thing I update when I want my new code to go to production is the src folder. So this folder is exactly the same when I push a release.
On my local server the new column in my entity/table works, and can be created, updated, etc. But on my production environment, this new column isn't noticed or even selected by doctrine.
The new column is in my database (both production and local), is in my entity.php file, in my entity.orm.yml file.
I did the app/console cache:clear option. Both dev and prod and on both servers.
What am I doing wrong?
Finally found the solution.
Because I didn't use metadata cache on the local server, but I did on my production server, it saved my mapping information. That's why doctrine didn't knew I had new columns. The solution was to clear the metadata cache using:
php bin/console doctrine:cache:clear-metadata
After that I run php bin/console doctrine:schema:update --dump-sql and I got the new columns.
Related
In my deployment strategy I want to do the following:
Get code from git
Install dependencies via composer (dev requirements as well)
Run tests (phpunit etc)
Install dependencies for production (will remove dev requirements)
Zip
Copy to server
Unzip
Change symlink to current release (leave 2 old releases in case of revert)
At this point can I run php artisan migrate to update the database?
Considerations:
The application cache files are purged (actually they are empty like a fresh install).
Will the migrate query check the schema to know if updates are required?
All in all:
Can I run php artisan migrate safely in production with no previous application cache?
How does the migrate task kow the history of the table and what needs to be done?
When you first run your migrations, Laravel creates a migrations table which helps it to know at what point you are with your migrations.
I suggest doing always a backup, anyway you can update your tables without any issue if you test them locally before applying them in production and, most important, you don't edit the old migrations but instead add new ones to migrate, event to edit existing tables (add/remove columns).
PS: Why would you need to symlink if you use git? I'd just tag a working release.
If you are able to get ssh access to your hosting server, even a sandboxed version to just be able to access your site folder, you may directly deploy using git. Best way to avoid any problem caused by a failing copy of files.
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.
i'm using github in combination with laraval for the first time.
I have 2 local environments :
a) i use MAMP Pro for local development (Mac)
b) i use XAMPP for local development (Windows)
I made a new repository and pushed to github on environment a) , I cloned this repository on setup b) and added a .env file to setup my database. However i'm a bit confused what to do with the app_key value, do i need to just copy it form my initial environment? or need a new one?.
The second part of my question is that i seem to have problems with xampp vs mamp pro because they rewrite a couple of urls, wich means my project won't run on environment b). Are there other settings i need to adjust? and will it brake again if i commit on environment b) ?
Error message when running the project on environment b)
Warning: require(D:\dev.local\ADifferentDesign\bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in D:\dev.local\ADifferentDesign\bootstrap\autoload.php on line 17
Fatal error: require(): Failed opening required 'D:\dev.local\ADifferentDesign\bootstrap/../vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in D:\dev.local\ADifferentDesign\bootstrap\autoload.p
I'm really confused , i saw other questions like this but none are quite what i was looking for.
A good aproach for future projects would also be very much appreciated
Progress update 1: I updated my .env file with the same key. But the error shown above still persists. I dont want to change te path in autoload every time i switch environments either.
It depends. If you are sharing any resources that hold encrypted data between the two environments, like a database, then you must copy the app_key. This is because Laravel uses the app_key whenever it encrypts something like a user's password or a session ID.
If you don't need to share a database, sessions, etc then you can and should generate a new key for every environment.
You generate a new key by running this command in your site root:
php artisan key:generate
Ideally, you would run this command as the first step in setting up a new environment, before running database seeds or other stuff. This is because if you generate a new key after seeding your database then any password you created in the seeds will be invalid and you'll have to reseed the database.
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.
So I disabled my site with
symfony project:disable --env=prod
And rsynced my new code to the server.
But now when I run
symfony doctrine:migrate --env=prod
I get a warning that the site is currently unavailable.
I clearly don't want to enable the project (yet) as I first want to make it all works. What is the correct way to do this?
You are right. This doesn't work by default. If your production database is available from your development machine you can start the migration on this machine via:
$> php symfony doctrine:migrate --env=prod
Thats what I do in my deployment scripts
I would probably restrict access to your IP address in the index.php, such as when working in the dev environment. Enable the project and then run again.