To
backup website web source and database
1. Back up website database
·
- To verify what
database name is used in the website, check website’s wp-config.php
- Once website
database name is verified in wp-config.php; Verify it in mysql ; Once verified.
- Run command to
back up database, don’t worry it won’t affect current database, this will only
create a copy.
# mysqldump
–u root –p database_name > backUpDatabaseNameDate.sql
e.g: # mysqldump –u root –p
database_name > mysqldump_db_backup_WebsiteDatabase_name20190314.sql
2. Back up website web source
- Locate folder
that contains WordPress files.
- Verify if you’re
in the folder where you can see the folder that holds WordPress files.
# tar -zcvf
newWebNameBackUpDate.tar.gz folderName
e.g: # tar -zcvf web_castleoaklp_20140418.tar.gz web_castleoaklp
- Verify that backup tar websource and
backup mysqdump is stored at website folder websource (e.g public_html)
- Create "wgetdown" folder to store your downloads using wget command. Inside wgetdown folder, run command.
wgetdown] # wget http://test.example.com/fileBackUp2019611.tar.gz
Restore
wordpress back up to localhost via virtualhost
·
Always check if you are at source folder /var/www/FolderName/
·
FolderName] #
·
If you’re not inside your FolderName specify the correct
path written in terminal /var/www/…/…
User: root
Password: admin1234
Mysql Password: 123456
1. Add new folder to var/www directory (add your
desired website name; sample ‘folderName’ : path /var/www/folderName)
Add
2 folders: log and public_html
# mkdir log create
‘log’ folder
Or # mv
web_castleoaklp public_html rename
extracted ‘web_castleoaklp’ folder to public_html
# unzip folder.zip extract
zip file
# tar -zxvf
web_castleoaklp.tar.gz extract
tar file
# tar -zcvf newfile.tar.gz
folderName compress
folder in tar
# tar -tvf file.tar.gz show
list inside tar file
2. Rename database sql file (with your
desired database name; sample 'db_name.sql')
FolderName] # mv
OldName.sql NewName.sql
3. On sql file -> Replace website url
with test.example.com
· Ctrl H, Replace all www.castleoaklp.com to
test.example.com
· cat (search)
FolderName]
# cat filename.sql | grep “TextToSearch”
· sed -i (replace)
FolderName]
# sed –i ‘s/OldText/NewTextToReplace/g’ filename.sql
4. Create
new database at phpMyAdmin (with your desired database name; sample 'db_name.sql')
# mysql
–u root –p –e “CREATE database db_name”
FolderName]
# mysql –u root –p - -database=db_name < db_sourceFileName.sql
· In phpMyAdmin, select your database (sample db_name)
# mysql
–u root –p
# show
databases;
# use
db_name;
db_name] #
show tables;
# exit;
5. Update wp_config.php at www/folderName/public_html:
# vi /var/www/FolderName/public_html/wp-config.php
if you’re not in
sourceFolder
Or # vi wp-config.php if
you’re in sourceFolder
Press
letter “i" on
the keyboard to allow input to vi editor
After
changes to file is done;
Press
‘esc’ key
Type
in
:wq! To save changes to file and exit
:q! To exit without saving
changes to file
·
db_name
->db_name (this can be
changed, it depends on your desired name made at step 2)
· db-user -> root
· db_password -> '123456'
· db_host -> localhost
6. Add
vhost info
# sudo vi
/etc/httpd/conf.d/httpd-vhost.conf
<VirtualHost
*:80>
DocumentRoot
"/var/www/folderName/public_html"
(the location of your WordPress files)
ServerName
test.example.com (your desired domain)
Errorlog /var/www/folderName/log/error.log
CustomLog
/var/www/folderName/log/request.log combined
</VirtualHost>
7. Add info below at hosts file
# sudo vi /etc/hosts
127.0.0.1 test.example.com (your desired domain)
8. Restart apache services
# sudo systemctl restart
httpd.service
9. Visit your site (sample
test.example.com)
10. If Apache does
not restart because of an error; to view the error run this command:
# sudo systemctl status
httpd.service –l
Try to visit your site first if
it’s working without doing step 11, coz I made changes on htpd.conf file.
11. If WordPress permalinks not
working
·
Change the file’s permission so that it is writeable by Apache.
# chown
apache /var/www/foldername/public_html/.htaccess
·
Edit your httpd.conf file in /etc/httpd/conf/, add the following
info below:
# sudo vi
/etc/httpd/conf/httpd.conf
<Directory
“/var/www/foldername”>
AllowOverride All
</Directory>
·
Restart your Apache.
# sudo systemctl restart
httpd.service