Practical 10

 Configuring Web(apache) and FTP Serverssq

We will configure the Web server and FTP server in our system(Ubuntu 20.04LTS). We will make use of the virtual machine. You can get help related to ftp command with the command <man ftp>.

Configuring Apache Web Server

Q. What is an Apache web server?

- one of the most widely used open-source web server software programs in the world. It's a critical component of the technology stack that powers the World Wide Web. The Apache Software Foundation develops and maintains Apache.

Q. Which port number is used by the Apache webserver by default?

- The default port number used by the Apache web server for unencrypted HTTP traffic is port 80.


1. Install the Apache webserver with the command <sudo apt install apache2>

2. Once the installation is done, use the command <sudo systemctl status apache2> to check the server's status. You should see the output similar to the picture below.


Note: If you get the status inactive, use the following command to activate it.
1. <sudo systemctl start apache2> 
2. <sudo systemctl status apache2> [ Now you should be able to see the status as active]
3. <sudo systemctl enable apache2 > [This will make sure when your system boots, it will automatically start the apache2]

3. Open the web browser, and access the following URL:
a. http://localhost
b. http://127.0.0.1

You should be able to see the output similar to the picture below.

4. Your web server code resides in the location /var/www/html directory. Paste the screenshot of the content inside the html directory.
 

5. Inside it, you can upload your website code base. The starting point of the website should be an index.html file. Since the default index.html file already exists, you can delete it can create your own file or if you want to keep it, then rename it to something else.[Optional]

6. Now create an index.html file, it should have the following things inside it:
    a. Title: <Module Code of Fundamental of Computing>
    b. Body: It should have your name, registration number, and your picture.
Paste the screenshot of your website below.

Virtual Host Configuration
What is a virtual host in an Apache web server? Explain in detail.
cd
We will create two websites using the same Apache web server.

1. Create two folders called “teach“ and “learn” inside the /var/www/ folder.

2. See the group name and user name of both folders, in case if the user and group are root then change it back to your username. You can use the command <sudo chown user_name:group_name learn>. Replace the user_name and group_name with your user_name. In case you are not sure what is your user_name, you can use the command <whoami>. Similarly, change the group and user name for folder teach.

3. Now inside both folders, create an index.html file. Write a few HTML codes inside it. You can make use of your Front End Web Development module concept. Make sure the content inside each index.html file is different.

4. Navigate inside the folder /etc/apache2/sites-available/. Inside it, you will find a default configuration file called 000-default.conf. For our virtual host, we will create a similar configuration file. For that, we will create learn.conf and teach.conf files. Since the configuration will be similar, we will just copy the content of the default file. 
    a. <sudo cp 000-default.conf learn.conf>
    b. <sudo cp 000-default.conf teach.conf>

5. Now open both files in your choice of code editor. We will modify it with the following content.
    a. learn.conf

<VirtualHost *:80>
ServerName www.learn.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/learn/
ErrorLog ${APACHE_LOG_DIR}/learn_error.log
CustomLog ${APACHE_LOG_DIR}/learn_access.log combined
</VirtualHost>


b. teach.conf

<VirtualHost *:80>
ServerName www.teach.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/teach/
ErrorLog ${APACHE_LOG_DIR}/teach_error.log
CustomLog ${APACHE_LOG_DIR}/teach_access.log combined

</VirtualHost>



6. Now let’s disable the default configuration file with the command <sudo a2dissite 000-default.conf> and let’s enable our new configuration file with the following commands
    a. <sudo a2ensite learn.conf>
    b. <sudo a2ensite teach.conf>

7. Now finally restart the Apache web server with the command <sudo systemctl restart apache2>.

8. Finally in order to access the website by the name, let's configure the /etc/hosts file. I hope you remember the purpose of this file. Open the /etc/hosts file, enter these two lines of instructions in it, and save it.

    127.0.0.1  www.learn.local
    127.0.0.1  www.teach.local


10. Take the screenshot of both websites and paste it below.


11. Explain what the following attributes represent in the above configuration file:

a. ServerName: Specifies the domain name the virtual host should respond to.
b. ServerAdmin: Provides the server administrator's contact email for issue notifications.
c. DocumentRoot: Defines the directory where website content is stored.
d. ErrorLog: Designates the location for error log messages specific to the virtual host.
e. CustomLog: Specifies where access logs for the virtual host are recorded

FTP Server Configuration

Q. What is the FTP server? Give an example of an FTP server.
An FTP server is a software application or service running on a server that allows users to connect and transfer files to and from the server. Some example can be ProFTPD server (Linux) and FileZilla Server (Windows).
What is the default port number that your FTP server uses?
The default port number for FTP is 21.

We will set up the vsftpd FTP server in our system.

1. You can install it with the command <sudo apt install vsftpd>.

2. Check whether the FTP server is running or not. The service name is called vsftpd. Paste the screenshot below.

3. The configuration file related to the server can be accessed from “/etc/vsftpd.conf”. Open the file and observe the content in it. Also, the location for the FTP server is created at “/srv/ftp” which is empty. You can check it.

4. By default, the user in your system can log in to the FTP server using the command <ftp 127.0.0.1>. Provide the username and password. You should be then inside the FTP server. You should see the output similar to the picture given below. 

Paste the screenshot of your login. Also, what is the directory name you are provided with when you log in? Use the relevant command that you have learned in Linux to display the directory name. 

5. You can use most of the commands that you have learned in Linux. Try out some and see whether it is working or not.ls

6. Go inside the directory “/srv/ftp/” and create a file called ftp.txt as a normal user(i.e., you don’t have to log in as an ftp user). Basically, you can keep any kind of files. For the demonstration purpose, we are using the ftp.txt file. Write some dummy text inside it. So that when we download it we can verify that we have downloaded the right file.

7. Now log in as the FTP user from your home directory using the Step 3 command. After that navigate to the directory “/srv/ftp/”. Now you can download that file with the command <get ftp.txt>.  Paste the screenshot of the command output. 

8. Now log out from the FTP server with the command <bye> or <exit>.  You should be able to see the file ftp.txt in your home directory. You can check with the command  <ls>. You can see the content of the ftp.txt file using the command <cat> to make sure that is the correct file.

9. By default, you won’t be able to upload files to the ftp server. So to upload the file, let’s change the configuration file called “/etc/vsftpd.conf>. 

10. Open it using your choice of editor, then search for the line #write_enable=YES. Uncomment the line by deleting the #(hash) symbol. Then save the file..

11. Now restart the FTP server. You can use the command < sudo systemctl restart vsftpd>. Check the status of the server. Just to make sure that the changes have not broken/crashed the server. It should be active and running without any errors.

12. In your home directory, create another file called ftpUpload.txt and write some dummy text in it. Now we will try to upload this file to the FTP server.

13. Log in to the FTP server, then navigate to the directory “/srv/ftp/”. We will upload it to this directory. Now to upload the file, use the command <put /home/sumukus/ftpUpload.txt backup_ftpUpload.txt>. Right after the put command, it is the absolute path to the file. In your case, replace that with your file path. Then next is the file name of the FTP server. In case you get the permission issue, resolve it. [Hint: Set the file permission for directory “/srv/ftp”. Paste the screenshot of the put command below. You can check the file in the FTP server with the command <ls>. A file called backup_ftpUload.txt should be there.

14. If you notice, when the default user login to the FTP server, it has the present working directory as its home directory. But I want the FTP user to be in the location “/srv/ftp” as its working directory. So to do that let’s create the FTP user with the working directory at “/srv/ftp”. We will create a user called ftp1 with its working directory at “/srv/ftp/”. You can use the command <sudo adduser -d /srv/ftp ftp1>. Also, set the password for the user ftp1. You will need it when you log in to the FTP server using this user.

15. Now login as the user ftp1 in the FTP server. Then run the command <pwd>. You should see the output as “/srv/ftp/”. Paste the screenshot below.

16. Now let’s try to access the FTP server from our host operating system. Open the CMD and log in to the FTP server using the command <ftp ip_address_of_ftp_server>. Replace the ip_address_of_ftp_server with your FTP server IP address. You should be able to access it. 

Q. So far what are the commands that you have used in this practical? List all. Just the command, not the entire command usage.

sudo systemctl status apache2
/var/www/html 
sudo chown user_name:group_name learn
whoami
/etc/apache2/sites-available/
sudo cp 000-default.conf learn.conf
sudo cp 000-default.conf teach.conf
sudo a2dissite 000-default.conf
sudo a2ensite learn.conf
sudo a2ensite teach.conf
sudo systemctl restart apache2
/etc/vsftpd.conf
sudo adduser -d /srv/ftp ftp1
ftp ip_address_of_ftp_server


















Comments

Popular posts from this blog

Introduction to Linux D02

Network Devices B02

Network Models C01