To change password in MySQL log in to mysql as root user:
$ mysql -h localhost -u root -p
mysql> UPDATE mysql.user SET Password=PASSWORD(‘new_db_password’) WHERE User=’db_user_name’ AND Host=’db_host’;
mysql> FLUSH PRIVILEGES;
mysql> quit;
web development and system administration of Linux
To change password in MySQL log in to mysql as root user:
$ mysql -h localhost -u root -p
mysql> UPDATE mysql.user SET Password=PASSWORD(‘new_db_password’) WHERE User=’db_user_name’ AND Host=’db_host’;
mysql> FLUSH PRIVILEGES;
mysql> quit;
To log out ssh user automatically add the TMOUT variable to your /etc/bashrc configuration file using your favorite editor. Mine is vim:
# vim /etc/bashrc
# Set TMOUT to 600 seconds (10 minuets):
TMOUT=300
To backup your WordPress website on Linux you can follow these steps:
1. Log in via ssh to your server.
2. Change directory where your website files are located. For example:
$ cd /home/shkodenko/public_html
3. Find out MySQL connection settings using command:
$ grep -ni "DB" ./wp-config.php
You will need these lines below.
19:define(‘DB_NAME’, ‘db_name’);
22:define(‘DB_USER’, ‘db_user’);
25:define(‘DB_PASSWORD’, ‘db_password’);
28:define(‘DB_HOST’, ‘localhost’);
4. Create backup of MySQL database using mysqldump utility. For example:
$ mysqldump -h localhost -u db_user -p db_name > ./wp-content/uploads/db_name.sql
5. I am checking MySQL dump using tail and head utilities:
$ tail -n 15 -f ./wp-content/uploads/db_name.sql
$ head -n 15 -f ./wp-content/uploads/db_name.sql
I am using sha1sum command to get SQL dump file checksum:
$ sha1sum -b ./wp-content/uploads/db_name.sql
I am checking SQL dump file information usinng ls command:
$ ls -Alh ./wp-content/uploads/db_name.sql
All these steps above in 5 can be skipped. I making these checks for history and possible future verification purposes if something will go wrong.
6. Making archive:
tar cpjf /home/shkodenko/shkodenko.com-backup.tar.bz2 ./
7. Some additional commands for verification with backup file:
$ sha1sum -b /home/shkodenko/shkodenko.com-backup.tar.bz2
$ ls -Alh /home/shkodenko/shkodenko.com-backup.tar.bz2
8. Cleaning garbage:
$ rm -fv ./wp-content/uploads/db_name.sql
To take screenshot on Android 4 or later press and hold the Volume Down and Power buttons at the same time.
I have been working with some Linux servers with Plesk control panel. By default ProFtpd FTP server is configured to not display hidden files.
To fix this edit ProFtpd main configuration file /etc/proftpd.conf add line below:
ListOptions “-a”
inside <Global> </Global> section.
Check ProFtpd configuration using command:
# proftpd -t6
Checking syntax of configuration file
Syntax check complete.
Restart service.
1. If your ProFTPD server installed as part of xinetd:
# /sbin/service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
2. If your ProFTPD server installed as standard Linux service:
# /sbin/service proftpd restart
or
# /etc/init.d proftpd restart
Sometimes it can be useful to verify if system, PHP and MySQL date and time is synced.
I am using this set of commands to check:
# date ; php -r "echo date('r').PHP_EOL;" ; mysql -e "SELECT NOW();"
Also, it can be useful to check the same information on remote server without logging in to it. It can be done using the same above set of commands plus ssh utility:
ssh taras@shkodenko.com 'date ; php -r "echo date(\"r\").PHP_EOL;" ; mysql -e "SELECT NOW();"'
Sometimes, when I am working on Linux, some programs are hanging system, so further work is impossible.
I am using this set of commands to find out PID and other data of hanged process in good readable format (KeePass as example):
$ ps aux |head -n 1; ps aux |grep -v grep |grep -i pass
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
1000 29015 13.1 0.2 824732 40408 ? Sl 14:56 0:02 /usr/bin/mono /usr/bin/KeePass/KeePass.exe
Using this command below to terminated hanged process:
$ kill -s 9 29015
Do you have something to say more on this subject?
Sometimes using MySQL Workbench I am getting this kind of errors:
Failed to Connect to MySQL at xxx.yyy.zzz.aaa:3306 with user db_user
Can’t connect to MySQL server on ‘xxx.yyy.zzz.aaa’ (113)
To fix it add configuration directive:
skip_name_resolve = off
to main MySQL configuration file /etc/my.cnf using your favorite text editor (mine is Vim).
to section [mysqld]
and restart MySQL server using command as root:
# /etc/init.d/mysqld restart
Sometimes it can be useful to get random array value in PHP.
You can use my function below to do it:
function getRandomArrayValue($a) { $k = array_rand($a); $v = $a[$k]; return $v; }
If you have any ideas how to make it better: all your comments are welcomed.
My general transfer Magento website on Linux procedure
1. Export MySQL database to SQL dump to file using phpMyAdmin or mysql command-line:
mysqldump -h localhost -u db_user -p db_name > ./db_name.sql
…or any other utility.
MySQL database host, name, user and password can be found in file ./app/etc/local.xml
Example section with db settings:
<config>
<global>
<resources>
<db>
<table_prefix><![CDATA[]]></table_prefix>
</db>
<default_setup>
<connection>
<host><![CDATA[localhost]]></host>
<username><![CDATA[db_user]]></username>
<password><![CDATA[db_password]]></password>
<dbname><![CDATA[db_name]]></dbname>
<initStatements><![CDATA[SET NAMES utf8]]></initStatements>
<model><![CDATA[mysql4]]></model>
<type><![CDATA[pdo_mysql]]></type>
<pdoType><![CDATA[]]></pdoType>
<active>1</active>
</connection>
</default_setup>
2. If you transfer Magento from one domain (domain1.com) to another (domain2.com) replace all matches in SQL dump file using vim:
domain1.com
—>
domain2.com
:%s/domain1.com/domain2.com/g
:w
or
http://domain1.com
—>
http://domain2.com
:%s/http:\/\/domain1.com/http:\/\/domain2.com/g
:w
or using Perl, sed or any other utility.
I am prefering to make SHA1 checksum using command:
sha1sum -b ./db_name.sql
and archive it after each replace:
tar cpjf ./db_name.sql-N.tar.bz2 ./db_name.sql
for each saved sql file version.
Do not forget to replace both www. and without www. domain name versions.
3. Make all files backup.
For example:
cd /var/www/vhosts/domain1.com/httpdocs
tar cpjf /var/www/vhosts/domain1.com/private/domain1.com.tar.bz2 ./ –exclude ./var/cache –exclude ./var/reports
4. Copy backup to new server using scp (ssh secure copy):
scp /var/www/vhosts/domain1.com/private/domain1.com.tar.bz2 domain2@domain2.com:/home/domain2/
or lftp (via plain ftp):
lftp -e ‘put -a -O / /var/www/vhosts/domain1.com/private/domain1.com.tar.bz2; bye;’ -u domain2,ftp_password domain2.com
or any other FTP client.
5. Restore files from backup:
cd /home/user2/public_html/
tar xjf /home/user2/domain1.com.tar.bz2 ./
mkidr -pv ./var/cache
mkidr -pv ./var/reports
Make both ./var/cache and ./var/reports writable for web server user e.g. apache or nobody using chmod.
6. Restore MySQL database from file:
mysql -h localhost -u db_user -p db_name < ./db_name.sql
7. Change Magento settings in file ./app/etc/local.xml suitable for new server.
8. Do not forget to check all custom .htaccess rules (custom php_value, rewrite rules, password protection, etc.) to match paths and server configuration at new server.
9. If you go from dev to production do not forget to check ./robots.txt file:
User-agent: *
Disallow: /
--->
User-agent: *
Allow: /
and vise versa.
Do you have any thoughts about this subject?