We recently migrated one of our WordPress websites from an old server to a new infrastructure in Stratos Datacenter. We have already set up LAMP, except for the database. We have also restored website code; however, we need to restore the database to make it work on the new infra. Please perform the below given steps on DB host:
a. Install/Configure MariaDB server.
b. Create a database with name kodekloud_db8.
c. There is a DB dump on jump_host under location /home/thor/db.sql. Restore this database in newly created database.
d. Create a user kodekloud_top and set any password you like.
e. Grant full permissions to user kodekloud_top on database kodekloud_db8.
f. Update database-related details in /data/wp-config.php file on storage server, which is our NFS server having a share /data mounted on each app server on location /var/www/html. (for more details about how to update WordPress config file please visit https://wordpress.org/support/article/editing-wp-config-php/)
g. You can access the website on LBR link; to do so click on the + button on top of your terminal, select option Select port to view on Host 1, and after adding port 80 click on Display Port.
Sample Answer:
#Login to db server using ssh
ssh <user>@<DB-server>
#login as root
sudo su
#install mariaDB
yum -y install mariadb*
#enable, start and check status of mariaDB
systemctl enable mariadb && systemctl start mariadb && systemctl status mariadb
#Start mysql secure installation(press 'Enter' to give a new root password)
#run below command and press enter
mysql_secure_installation
*now give new password as your wish
#Now, login with root password that you have given in above step
mysql -u root -p
#create DB,user and grant permissions (check your question, DB name and user name from your question but for password you can give your own password)
CREATE DATABASE <DB_from_your_question>;
CREATE USER '<user_from_your question>'@'localhost' identified by '<your_own>';
GRANT ALL PRIVILEGES on <DB_from_your_question>.* to '<user_from_your_question>' identified by '<your_own>';
GRANT ALL PRIVILEGES on <DB_from_your_question>.* to '<user_from_your_question>'@'%';
FLUSH PRIVILEGES;
exit
#Edit the configuration file and bind the mysql to the database ip address and port
vi /etc/<any_name>.cnf
bind-address=<DB_server_IP_address>
port=3306
#Install Open ssh if the SCP isn't working
yum -y install openssh-clients
#Go to jump server and copy db.sql from jump server to db server
scp /home/thor/db.sql <user>@<DB_server>:/tmp/
#Go to db server and import db.sql to newly created datatbase
mysql -u <user_from_your_question> -p <DB_from_your_question> < /tmp/db.sql
#restart mariaDB
systemctl restart mariadb
#check connection
mysql -u <user_from_your_question> -p -h <db_server>
mysql -u <user_from_your_question> -p -h localhost
#Next go to the storage server and
ssh <user>@<storageserver>
#login as root
sudo su
#Now check the configuration
cat /data/wp-config.php | grep DB_NAME
cat /data/wp-config.php | grep DB_USER
cat /data/wp-config.php | grep DB_PASSWORD
cat /data/wp-config.php | grep DB_HOST
Replace with correct configuration
sudo sed -i 's/dbname/<DB_from_your_question>/g' /data/wp-config.php
sudo sed -i 's/dbuser/<user_from_your_question>/g' /data/wp-config.php
sudo sed -i 's/dbpass/<your_own>/g' /data/wp-config.php
sudo sed -i 's/dbhost/<DB_host_name>/g' /data/wp-config.php
#TESTING
click on the + button on top of your terminal, select option Select port to view on Host 1, and after adding port 80 click on Display Port.
*Please comment on this post if you are facing any issues in the steps, also provide your feedback in the comments :)
Note: **The Question copied it for learning purposes.** Commands are correct but based on your question the server, user name, and other details might differ, so please do check.
What is the need of installing apache and on which server it has to be installed
ReplyDeletegood catch
ReplyDeleteapache installation is no need
Also, entering hostname in the wp-config.php might not work, didnt work for me. I entered the IP address for the same. also no need for installing openssh-clients. You can do sftp instead
ReplyDeleteit should work with hostname
ReplyDeletecheck out below link and details
thanks for your command
https://wordpress.org/support/article/editing-wp-config-php/
To change the wp-config.php file for your installation, you will need this information:
Database Name – Database Name used by WordPress
Database Username – Username used to access Database
Database Password – Password used by Username to access Database
Database Host – The hostname of your Database Server. A port number, Unix socket file path or pipe may be needed as well.