SHARE

Compress files inside directory

go directory:

cd /var/www/yourfile/

zip -r filename.zip .

import sql to database

mysql -u user -pyourpassword yourdatabase < your-file-db.sql

 

Compress and decompress folder

For compressing:

tar -cvzf tarballname.tar.gz itemtocompress

and for decompression:

tar xzvf file.tar.gz

Export database settings

simple:
mysqldump -u root -p <database> > /data/raidpsbkp2.sql
with procedures and functions
mysqldump -u root -p -R <database> > /data/raidpsbkp2.sql
//ignore views
mysqldump -u root -p -R --ignore-table=dps.vw_tour --ignore-table=dps.vw_user_booking <database> > /data/raidpsbkp2.sql

//custom tables
mysqldump -u root -p -R --skip-triggers dps photo photo_upload photocategory photocategoryrelation > /data/dpscustomtablesoct.sql

//ignoring triggers and data
mysqldump -u root -p -R --skip-triggers --no-data <database> > /data/raidpsbkp2.sql
//ignoring triggers
mysqldump -u root -p -R --no-create-info --skip-triggers <database> > /data/raidpsbkp2.sql
//stored procedures and triggers
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql

//no triggers, no data, no info

mysqldump -u root -p -R --database <database> --skip-opt --routines --no-create-info --no-data --no-create-db --skip-triggers > /var/www/raidpsproc2

Export all database to one file

mysqldump -u root -p --all-databases > alldb.sql

Compress sql file

gzip -9 /data/yourdatabase.sql

Send from host to other server

scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Give permissions 755 to files inside folder

First go to folder:

cd /yourfolder/

then give permissions:

chmod -R 755 *

Change owner/group to file inside folder

First go to folder:

cd /yourfolder/

then give permissions:

chown -R www-data:www-data *

Remove all files inside folder

go to folder

rm -rf /yourfolder/*

Backup files of your server

sudo tar -cvpzf backup.tar.gz --exclude=/swapfile --exclude=/backup.tar.gz --one-file-system /

or 

sudo tar -cpzf “$backupfilename”
-v
–exclude=cache
–exclude=/dev/*
–exclude=/lost+found/*
–exclude=/media/*
–exclude=/mnt/*
–exclude=/proc/*
–exclude=/sys/*
–exclude=/tmp/*
–exclude=/var/cache/apt/*
–exclude=/home/$USER/error.log /
2>/home/$USER/error.log

Once the command above has finished its run, look for the backup.tar.gz file inside the / folder and save it to an external file system. If ever you lose some files that need to be restored, just run the following command to restore them:

sudo tar -xvpzf /path/to/backup.tar.gz -C /restore/location --numeric-owner

copy the content of a folder /source to another existing folder /dest

cp -a /source/. /dest/

Using www-data through ssh and ftp

Set a password for www-data

sudo passwd www-data

Define a shell for www-data. You can do this using chsh or by editing /etc/passwd. Replace /usr/sbin/nologin or similar by /bin/bash on the line of the user.

nano /etc/passwd

Give permission for login via ssh, edit /etc/ssh/sshd_config and add the following line (do not forget to enumerate all the users that need ssh access)

AllowUsers www-data root

systemctl restart sshd

Removing apache from server

A very simple and straightforward way that worked for me is as follows:

Stop apache2.

sudo service apache2 stop

Uninstall Apache2 and its dependent packages.

sudo apt-get purge apache2 apache2-utils apache2.2-bin apache2-common

Use autoremove option to get rid of other dependencies.

sudo apt-get autoremove

Check whether there are any configuration files that have not been removed.

whereis apache2

If you get a response as follows apache2: /etc/apache2 remove the directory and existing configuration files.

sudo rm -rf /etc/apache2