How many times have you gone to do an upgrade of Mautic and it failed only to leave you hanging without a system and running around looking for a solution.
At Surge we believe in fail safe methodologies to ensure 100% uptime for our customers.
With the release of Mautic 4.x we have noticed many upgrade issues both with current instances and monitoring the forum, as such we have put together a small tutorial on how to best upgrade your instance with ability to test and confirm in a temp staging environment before going to live.
This tutorial will assume the following:
1. You have ssh access to your instance server
2. The web server you are running is nginx
3. You have basic knowledge of working inside terminal.
With that lets jump in:
Start off by accessing your server via ssh.
Here are the steps to take and commands that go with it.
1. Make a backup of the ams base files. For this you need to know where you version of mautic (AMS) is installed.
cd /var/www/ams/
tar -czvf ams-files-5feb22.tar.gz *. (This will create a tar file of your entire directory)
mv ams-files-5feb22.tar.gz /root/. (if you are on AWS mv /home/ubuntu/)
2. Make a backup for the active database
mysqldump -u root ams > ams-db-5feb22.sql (where we have ams you can replace with the name of your Mautic database – over here we are not going to zip the sql as we will be using it in the next few steps)
3. Go ahead and create a staging directory
mkdir /var/www/stage
4. Copy the tar file we created to the stage directory and extract it
cd /var/www/stage
cp /root/ams-files-5feb22.tar.gz .
tar -xzvf ams-files-5feb22.tar.gz
5. Lets give this directory the correct permissions and ownership
chown -R www-data:www-data /var/www/stage
6. Now we can go and create a staging DB inside mysql
mysql -u root
This will take you into the mysql command line, here we will create the staging database.
CREATE DATABASE staging DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
GRANT ALL ON staging.* TO ‘dbuser’@’localhost’ IDENTIFIED BY ‘password’;
FLUSH PRIVILEGES;
quit
7. Now lets import the original database into the new one we created:
cd /root
mysql -u root staging < ams-db-5feb22.sql.
8. Now we need to update our configuration files cd /var/www/mautic/app/config (All the configurations are held in the local.php file) There are a number of parameters to look out for an change here.
Find these lines and change the values according to your changes in the steps above: vim local.php
‘db_name’ => ‘mautic’, —->. here you would change mautic to staging (the name of the database we created in step 6.
‘cache_path’ => ‘/var/www/mautic/app/../var/cache’, —> change name of directory to stage
‘log_path’ => ‘/var/www/mautic/app/../var/logs’, —> change name of directory to stage
‘tmp_path’ => ‘/var/www/mautic/app/../var/tmp’, —> change name of directory to stage
‘upload_dir’ => ‘/var/www/mautic/app/../media/files’, —> change name of directory to stage
‘form_upload_dir’ => ‘/var/www/mautic/app/../media/files/form’, —> change name of directory to stage
‘report_temp_dir’ => ‘/var/www/mautic/app/../media/files/temp’, —> change name of directory to stage
Save and exit the file.
9. Next lets go delete the old cache:
rm -rf /var/ww/stage/var/cache/*
At this stage we are ready to go ahead and upgrade. If you want, you can first change the web server configuration to test that everything is working on the staging environment.
Remember we are working on nginx server, but the same would apply for apache2
10. Change the directory the webserver is looking for as the root directory.
vim /etc/nginx/conf.d/mautic.conf
Change your root directory to point to your stage directory /var/www/stage
Test your changes
nginx -t
Then go ahead and restart your nginx server
systemctl restart nginx
Now if you go to your AMS instance via a webbrowser everything should seem exactly the same.
Lets go ahead and update to the latest version of Mautic
cd /var/www/stage/bin
php console mautic:update:apply
php console mautic:update:apply –finish
Hopefully everything should go fine and if not all you need to do is change your server config file to point back to your original directory.
If you do run into any troubles, feel free to contact us for some quick answers and professional support