Web Development 701 ~ S(ecure) SH(ell)
Today in Web701 we learned about SSH so that we can access a remote server for hosting out web technologies on. I have had experience with SSH before since that is how I connect to my raspberry pi’s and my onion omega, though I prefer the terminal SSH cli to a GUI like putty. Yet another advantage of Linux is that distributions come with SSH pre-installed. An example of SSH through the terminal looks like ssh <username>@<domain>
.
Then it will ask for a password, and boom its that easy.
Once logged into the server we had to make sure that our default PHP applications were working by visiting <domain>/~<username>. If the application is working/running it should return a page that gives us something like PHP Version 7.3.3-1+ubuntu16.04.1+deb.sury.org+1
and a whole bunch of other information. This worked for me so onto the next thing, which is to access our MySQL database. Before we access the database, we have to write a quick bit of sql to test with.
The test sql can be found below.
DROP <username>db;
CREATE <username>db;
USE <username>db;
DROP TABLE Test;
CREATE TABLE Test (
Name Varchar(50)
);
INSERT INTO Test(Name)
VALUES ("This"),
("is"),
("a"),
("test");
Our tutor suggested running the command below with > test.sql
on the end but it hung when I attempted so I will be running the SQL script from within MySQL. After a quick ddg search I found out how to do so.
To access our MySQL database, we had to type the command mysql -u <first 3 letters of username> -p
and provide the corresponding password.
Now to run the script we enter the command source <path to sql file>
. The result looks something like below.
mysql> source ./test.sql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 4 rows affected (0.01 sec)
Records: 4 Duplicates: 0 Warnings: 0
+------+
| Name |
+------+
| This |
| is |
| a |
| test |
+------+
4 rows in set (0.00 sec)
We also discussed S(ecure)C(opy)P(rotocol) for transferring files from one computer to the remote server. I have also had some previous experience with SCP as I use it for when I am transferring files between my laptop and my raspberry pi’s or onion omega devices. Examples of how to execute SCP from the terminal can be found here. I am not going to provide an example as there are multiple ways to structure a SCP command, so I suggest you refer to the link.