For those that want to horizontally scale their website and share the same database across multiple servers, or save compute resources by moving the database off your server, here's how you do it.
This assumes a few things:
Step 1:
First, lets change users so we have proper permissions:
Step 2:
Change directories:
Step 3:
Create a backup of the local mysql database:
Step 4:
Connect to your RDS database. This can be done via command line like we're about to do, or via a GUI like Navicat or whatever you prefer.
You can name the database anything you want, same with username. Remember to replace [rds_username] with your RDS username and remove the brackets. Same for [rds_database] and [endpoint.for.rds.instance].
Step 5:
Migrate the backup to RDS. Again, replace the stuff in brackets and make sure the database_backup.sql is the same as the one you made in step 3.
Step 6:
Change your env to your new database.
Replace the values with your RDS information. It's a good idea to save the default info somewhere just in case you need it. You can leave the encryption key, port, and table prefix as-is. Just change the host, name, pass, and user.
Ctrl + X to exit.
Press Y to save modified buffer.
File name to write, just press Enter.
Step 7:
Restart Apache
Step 8:
Lets load the website and see if it's working. Upload a file to test.
Step 9:
Delete the database backup.
That's it! We're done.
If you have issues, drop a comment. Or check your RDS security groups and make sure your VPS instance can access the RDS instance. This is streamlined if you use EC2.
This assumes a few things:
- You are migrating to Amazon RDS and you already know how to create an RDS instance (but should work for any database host).
- You are familiar with command line.
- You are using a VPS or Ubuntu server.
- You have a default chevereto installation.
Step 1:
First, lets change users so we have proper permissions:
Code:
sudo su
Step 2:
Change directories:
Code:
cd /var/www/html
Step 3:
Create a backup of the local mysql database:
Code:
mysqldump -u chevereto -p chevereto > database_backup.sql
Step 4:
Connect to your RDS database. This can be done via command line like we're about to do, or via a GUI like Navicat or whatever you prefer.
Code:
mysql -h [endpoint.for.rds.instance] -P 3306 -u [rds_username] -p
(Enter your password you set during RDS setup)
create database [rds_database];
You can name the database anything you want, same with username. Remember to replace [rds_username] with your RDS username and remove the brackets. Same for [rds_database] and [endpoint.for.rds.instance].
Step 5:
Migrate the backup to RDS. Again, replace the stuff in brackets and make sure the database_backup.sql is the same as the one you made in step 3.
Code:
mysql -h [endpoint.for.rds.instance] -u [rds_username] -p [rds_database] < database_backup.sql
Step 6:
Change your env to your new database.
Code:
nano app/env.php
Replace the values with your RDS information. It's a good idea to save the default info somewhere just in case you need it. You can leave the encryption key, port, and table prefix as-is. Just change the host, name, pass, and user.
Ctrl + X to exit.
Press Y to save modified buffer.
File name to write, just press Enter.
Step 7:
Restart Apache
Code:
sudo systemctl restart apache2
Step 8:
Lets load the website and see if it's working. Upload a file to test.
Step 9:
Delete the database backup.
Code:
sudo rm -rf database_backup.sql
That's it! We're done.
If you have issues, drop a comment. Or check your RDS security groups and make sure your VPS instance can access the RDS instance. This is streamlined if you use EC2.