Difference between revisions of "OPS345 Lab 4"
Line 64: | Line 64: | ||
** Log in as yoursenecaid, upload a picture, share a link to it. | ** Log in as yoursenecaid, upload a picture, share a link to it. | ||
* When done with everything, release the elastic ip. | * When done with everything, release the elastic ip. | ||
+ | * Confirm that everything still works. | ||
+ | * As a bonus, get rid of the index.php in the URLs. |
Revision as of 05:26, 30 September 2021
- Data that is often modified is typically stored in a database.
- AWS provides database services via RDS, though you could install your own DBMS like MariaDB on your own VM.
- In the AWS console go to RDS. Create ops345db, with a long password that's different from other passwords. Put it in ops345sgprivate. This one will be used/seen in plain text sometimes.
- It will complain about not having two subnets in different availability zones.
- In VPC/Subnets, create a new one in vpc-ops345 named subnet2-ops345, in us-east-1b instead of 1a. 10.3.45.128/25
- Go back and try again to create the database.
- Assign temporary elastic IP to yum install mariadb, no need for server.
- Will disassociate and release the elastic ip at the end of the lab.
- Do the rest of the lab as the regular user, don't use root.
- In the AWS Console go to RDS, and find the FQDN ("Endpoint") for the database. Such as ops345db.cobdogt5aykb.us-east-1.rds.amazonaws.com - record that.
- Try to connect: mysql -u root -plongdbpassword -h ops345db.cobdogt5aykb.us-east-1.rds.amazonaws.com
- It won't work, the firewall (SG) won't allow it. Modify ops345sgprivate to allow incoming TCP port 3306 (MySQL) from ops345sgprivate.
- Should be able to log in now. If you get something like this: "ERROR 1045 (28000): Access denied for user 'root'@'10.3.45.11' (using password: YES)" then double-check the master username under RDS/ops345db/Configuration and you can reset the password via Modify (might take a few minutes to propagate).
- Most mysql commands need to have a semicolon at the end.
- The mysql commandline is nothing like the linux shell. Have to use mysql (or plain SQL) commands.
- Out of the box show databases; shows 4 databses, all of which are used internally by mysql, they are not for you to store data.
- use mysql; show tables; select * from user; select user from user;
- mysql root is not the same as the linux root, but it is an administrator and you should only use it for creating users, databases, and assigning permissions.
- Typically you would use something like this: " MariaDB> grant all privileges on DATABASE_NAME.* TO 'USER_NAME'@'%' identified by 'PASSWORD'; " but that won't work on AWS RDS because your root user doesn't have ALL PRIVILEGES, so can't grant them to another user.
- Instead create a user first: CREATE USER 'andrewdb'@'%' IDENTIFIED BY 'andrewdbpassword';
- Find what privileges your root has: show grants for 'root';
- Give the most important ones to your db user: " GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON firstdb.* TO 'andrewdb'@'%'; "
- Log out from root
- mysql -u andrewdb -pandrewdbpassword -h ops345db.cobdogt5aykb.us-east-1.rds.amazonaws.com
- show databases; - note that the list is shorter.
- use firstdb;
- show tables;
- Create tables, insert data, select: https://www.guru99.com/mariadb-tutorial-install.html#6
- A realistic use case for your career: download and instal nextcloud.
- wget the .tar.bz2 (not zip)
- Extract it into /var/www/html so you have a /var/www/html/nextcloud/index.html
- https://docs.nextcloud.com/server/latest/admin_manual/installation/source_installation.html
- As root, vi /etc/httpd/conf.d/nextcloud.conf
Alias /nextcloud "/var/www/html/nextcloud/" <Directory /var/www/html/nextcloud/> Require all granted AllowOverride All Options FollowSymLinks MultiViews <IfModule mod_dav.c> Dav off </IfModule> </Directory>
- chown -R apache.apache nextcloud/
- Get an error:
This version of Nextcloud requires at least PHP 7.3 You are currently running 5.4.16. Please update your PHP version.
- amazon-linux-extras | grep php
- amazon-linux-extras enable php7.4
- yum clean metadata
- yum install php-cli php-pdo php-fpm php-json php-mysqlnd
- restart apache
- Get module errors from website, install them:
- amazon-linux-extras enable httpd_modules
- yum install php-dom php-gd php-mbstring
- Should now let you continue the setup.
- Create an admin account. Use ops345admin/nextcloudadminpass
- Create a new database and user and password nextclouddb/nextclouduser/nextclouddbpassword
- CREATE DATABASE nextclouddb;
- CREATE USER 'nextclouduser'@'%' IDENTIFIED BY 'nextclouddbpassword';
- GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE ON nextclouddb.* TO 'nextclouduser'@'%';
- Fill in the database details in the nextcloud web setup screen.
- Look around inside the nextcloud, create user yoursenecaid, unlimited quota
- Log in as yoursenecaid, upload a picture, share a link to it.
- As root, vi /etc/httpd/conf.d/nextcloud.conf
- When done with everything, release the elastic ip.
- Confirm that everything still works.
- As a bonus, get rid of the index.php in the URLs.