Common Linux commands you need to know to manage an Amazon EC2 Linux server

BASICS OF CONNECTING

STEP 1 - YOU NEED A PPK KEY FILE FOR SECURITY

Putty: www.putty.org

1a) Use puttygen to generate a .ppk file from the amazon .pem key file.

1b) Launch Putty.

Put in Hostname: ec2-user@youripaddress port 22

Connection type: ssh

Go to ssH, auth, . Point to your private key file (ppk file):

STEP 2 - USE WINSCP TO CONNECT AND EDIT FILES

A) Download WinSCP: www.winscp.net

B) Hostname: put in your IP address

C) Username: ec2-user

D) Use the PPK encryption file as your password.

STEP 3 - CONNECTING TO MY SQL

How to create a HEIDI connection to MYSQL database on Amazon ec2:

Heidi SQL: http://www.heidisql.com/

https://vtvlab.wordpress.com/2011/12/13/connect-to-mysql-server-from-heidisql-with-ssh/

Good comparison of SQL versions:

http://troels.arvin.dk/db/rdbms/#insert

MANAGING PHP

EDIT PHP.ini with PUTTY:

1) sudo nano /etc/php.ini

2) Make a change

3) To restart apache: sudo service httpd restart

Edit .htaccess (httpd.conf)

1) sudo nano /etc/httpd/conf/httpd.conf

2) Make and change and save

3) Restart service sudo service httpd restart

To view PHP log:

sudo nano /var/log/httpd/error_log

To view log view of default sendmail log function:

sudo nano /var/log/maillog

MANAGING HARD DRIVES

To check hard drive space from putty:

df -h

To see partition detail:

lsblk

Shows you partition size.

Modify the volume size from AWS management console.

Connect to your instance via SSH.

Expand the size on the volume partition eg.

sudo growpart /dev/xvda 1

Resize the volume partition

sudo resize2fs /dev/xvda1

TO FIND LARGE FILES:

sudo find / -type f -size +10M -exec ls -lh {} \;

TO DELETE A FILE:

sudo rm /var/log/httpd/ssl_error_log-20200614

Managing large log files:

Some log files get so big that you can't even open them. But you can look at the first or last 100 entries:

sudo tail -n100 /var/log/httpd/ssl_error_log

sudo head -n100 /var/log/httpd/ssl_error_log

If using HTML glyphecons and fonts don't work and you get a CORS message, edit httpd file:

<FilesMatch ".(eot|ttf|otf|woff|woff2)">

Header set Access-Control-Allow-Origin "http://etfanalyst.com"

</FilesMatch>