Last active
April 23, 2024 08:27
-
-
Save joelbowen/5278142 to your computer and use it in GitHub Desktop.
Amazon EC2 Basic Linux Commands for New Servers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*****************CONNECTING TO THE EC2************************/ | |
// Open Terminal, cd into the directory where you have your .pem | |
// You may need to change the permissions of the .pem to 600 | |
chmod 600 pemfile.pem | |
// SSH into your instance | |
ssh -i pemfile.pem ec2-user@<AssociatedIp OR PublicDNS> | |
// Allow RSA additions, keychain, etc. | |
// Go Root Permissions | |
sudo su | |
/**********************Install Apache************************/ | |
// Use yum to install Apache (preloaded on EC2) | |
yum install httpd | |
//Start apache | |
service httpd start | |
/**********************Install PHP***************************/ | |
yum install php php-mysql | |
// Restart Apache | |
service httpd restart | |
// You should now be able to nvaigate to your servers' default | |
// apache page by navigating to http://<IP or Public DNS> | |
// To test your PHP install do the following: | |
cd /var/www/html | |
// Create a test.php file | |
vi test.php | |
Type i to start the insert mode | |
Type <?php phpinfo() ?> | |
Hit esc to exit insert mode | |
Type :wq to write the file and quit vi | |
// You should now be able to navigate to your IP/test.php | |
/**********************Install MySQL***********************/ | |
yum install mysql-server | |
// Start MySQL | |
service mysqld start | |
// Create a database | |
mysqladmin -uroot create <DB Name> | |
//Secure the MySQL install | |
mysql_secure_Installation | |
// Answer the wizard questions as follows: | |
// Enter current password for root: Press return for none | |
// Change Root Password: Y | |
// New Password: Enter your new password | |
// Remove anonymous user: Y | |
// Disallow root login remotely: Y | |
// Remove test database and access to it: Y | |
// Reload privilege tables now: Y | |
// REF: http://bit.ly/Z0bG1O |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/**********************Install PHPMyAdmin*******************/ | |
//EC2 instances come with yum installer which includes EPEL | |
// (EPEL : Extra Packages for Enterprise Linux ) | |
// however by default the packages are disabled, to enable | |
// them edit the epel.repo in etc/yum.repos.d | |
// simply enable the first block | |
sudo nano /etc/yum.repos.d/epel.repo | |
//Then you will have package access to PHPMyAdmin | |
sudo yum install phpmyadmin | |
//phpMyAdmin is installed in /usr/share/phpMyAdmin which is | |
// not naively accessible from the web, you can either create | |
// a symbolic link in your html directory, or create a virtual | |
// host (that points to your symbolic link) - here we will create | |
// the symbolic link: | |
ln -s /usr/share/phpMyAdmin/ /var/www/html/<Folder Name> | |
//Name <Folder Name> whatever you want the relative directory to be | |
// now you can point a vhost to this folder, or just nav directly to it | |
//If you try to navigate to this folder now you may get a 403 | |
// in this case, you will need to find the phpMyAdmin.conf file | |
sudo nano /etc/httpd/conf.d/phpMyAdmin.conf | |
//NOTE: You may need to verify the spelling/casing of the file name | |
//Comment out the #Order Allow,Deny AND #Deny from all for the | |
// phpMyAdmin directory | |
//NOTE: You must have already installed mySQL and setup a root password to login! | |
//To remove phpMyAdmin: | |
yum erase phpmyadmin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*****************CONNECTING TO THE EC2************************/ | |
// Open Terminal, cd into the directory where you have your .pem | |
// You may need to change the permissions of the .pem to 600 | |
chmod 600 pemfile.pem | |
// SSH into your instance | |
ssh -i pemfile.pem ec2-user@<AssociatedIp OR PublicDNS> | |
// Allow RSA additions, keychain, etc. | |
// Go Root Permissions | |
sudo su | |
/*****************SETTING UP BLOCK STORAGE*********************/ | |
// Create and associate an EBS, then check to see if it is mounted | |
df -h | |
// Device is normally maounted in dev as xvda, xvdb, xvdc and so on. | |
// If not shown as mounted, check available devices | |
lsblk | |
// If it is not mounted | |
fdisk -l | |
// Get the correct directory by looking at the disk sizes, it may | |
// have a name like /dev/xvda, b, c, etc. | |
// You MAY need to format and create a file structure | |
sudo mkfs -t ext3 <Device Name> | |
// <Device Name> is the "/dev/xvdb" string | |
// Then create a directory to mount to | |
sudo mkdir <Directory Name> | |
// Mount the EBS to the directory you created | |
sudo mount <Device Name> <Directory Name> | |
// NOTE: You will need to repeat this process each restart unless | |
// you add the device to the fstab or create a script that | |
// automatically mounts the volume on startup | |
// REF: http://bit.ly/Z094kp | |
/*****************OWN THE EBS DIRECTORY*********************/ | |
// Navigate to root and set ownership of the EBS to the ec2-user | |
chown -R ec2-user /<Mounted Directory> | |
// -R owns all subfolders |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment