Skip to content

Instantly share code, notes, and snippets.

@azamtav
Last active February 8, 2025 12:36
Show Gist options
  • Save azamtav/deb8075f41d5b7eff43c49bb286d9853 to your computer and use it in GitHub Desktop.
Save azamtav/deb8075f41d5b7eff43c49bb286d9853 to your computer and use it in GitHub Desktop.

Dotnet

dotnet clean
dotnet ef database update
dotnet build
dotnet publish
sudo systemctl restart adap-app.service

MYSQL

Login

mysql -u root -p

Creating Databases

CREATE DATABASE database DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
GRANT ALL ON database.* TO 'username'@'localhost';
FLUSH PRIVILEGES;

Changing Passwords

ALTER USER 'userName'@'localhost' IDENTIFIED BY 'New-Password-Here';

Delete User

DROP USER 'userName'@'localhost';

Exporting

mysqldump -u username -p --all-databases > dump.sql
mysqldump -u username -p --databases db1 db2 db3 > dump.sql

Importing

One database

mysql -u username -p New_DB_Name < dump.sql

Multiple Databases

mysql -u root -p < alldb.sql

Size of MySQL Databases

SELECT table_schema AS "Database", 
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" 
FROM information_schema.TABLES 
GROUP BY table_schema;

Select all users

SELECT user FROM mysql.user;

Apache

Restart

sudo systemctl restart apache2

Config

sudo apache2ctl configtest

Enable/Disable Sites

sudo a2ensite example.com
sudo a2dissite example.com

List Sites

a2query -s

PHP Version

sudo a2enconf php7.4-fpm
sudo a2enconf php8.0-fpm

sudo a2disconf php8.0-fpm
sudo a2disconf php7.4-fpm

Modules

List all modules

sudo apache2ctl -M

Environmentl Variables

source /etc/apache2/envvars

Symlinks

ln -s /path/where/source/is link

Certificates

Apache

sudo certbot --apache -d example.com -d www.example.com

Nginx

sudo certbot --nginx -d example.com -d www.example.com

Delete certificate

sudo certbot delete --cert-name example.com

List Certificates

sudo certbot certificates

Permissions

sudo chown -R www-data:www-data /var/www/html/folder

# Get the octal permission of folder: 
stat -c "%a %n" /folder

Clear Swapspace

sudo swapspace -e

Disk Usage

df -h
du -sh *

Restart

sudo shutdown -r now

Background Jobs

CTRL + Z will make a job pause bg - will make it run in the background jobs - list the jobs fg job_number - will foreground the job

Zipping Files

zip -r zipfile.zip folder
unzip filename.zip -d /path/to/directory
tar -xzvf latest.tar.gz

File Count

find directory | wc -l

System Information

landscape-sysinfo

Message of the Day

sudo run-parts /etc/update-motd.d/

Wordpress

Override URLs

define('WP_HOME','https://yourdomain.com');
define('WP_SITEURL','https://yourdomain.com');

Update URLs in Database

UPDATE wp_options SET option_value = http://www.domain_name WHERE option_name = 'home' OR option_name = 'siteurl';

Change username

UPDATE wp_users SET user_login = 'New Username' WHERE ID =

SSH

sudo nano ~/.ssh/authorized_keys
sudo systemctl reload sshd

sudo nano /etc/ssh/sshd_config
PasswordAuthentication no

Copying key

ssh-copy-id username@server

SCP

To copy a file from B to A while logged into B:

scp -rC /path/to/file username@a:/path/to/destination

-C enables compression

Packages

Clean

sudo apt-get autoclean 
sudo apt-get autoremove 

Laravel

sudo chown -R www-data:www-data /path/to/your/laravel/app 
sudo chmod -R 775 /path/to/your/laravel/app/storage 
sudo chmod -R 775 /path/to/your/laravel/app/bootstrap/cache 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment