We're almost done. You could actually stop now and tell people you've successfully installed and configured a UNIX web and file server. But wouldn't it be more fun if you actually had a webpage on your web server? And wouldn't it be AMAZING if there was another user besides you who could actually create new files and webpages for your server?
Of course it would! I thought you seemed like a fun person.
It doesn't actually matter what order you do these last steps, unless you want to experience the thrill of using one of the users you created to add files or webpages to your server. If you want that, then do the section on "chmod" first, since that will grant your user access to the server.
8. Change Permissions to the File and Web Server Directories
We're going to use the "chmod" command to "change mode" on the file and web server directories, so that other users have permission to read, write, and execute files on the server. Fully describing chmod is beyond the scope of this guide, but there is some great information out there already on the subject. Here's a great place to learn more:
https://en.m.wikibooks.org/wiki/A_Quick_Introduction_to_Unix/Permissions
We're just going to use chmod 777 to change the permissions on this file. This is almost certainly not what you would choose in an actual organization, since this makes the file accessible to everyone, but it works for this project and for you to learn how to change permissions to a file.
From the command line:
sudo chmod 777 /srv/ftp
Now your created user should be able to place files onto the file server. To test this, go to another machine on your network. I'm using a Windows 7 machine to do this - here are the commands I'm using to test:
Although you could simply adjust the settings on /srv/ftp/www so that your user can upload a webpage to the server, we're going to do this from the terminal for the opportunity to learn an additional skill: mounting a USB drive and moving information from a USB device to the local drive using the command line.
First, you need to find out where your USB drive is located. Place the USB with the HTML file you created into one of the USB slots. Then go to the command line, and type:
sudo fdisk -l
You will need to exercise a little critical thinking in reading the output - you should see your media listed as something like "/dev/sdb1". You will know it's the correct one by identifying the size of the volume, which should be different from other volumes the system lists, such as your hard drive. Removing any other plugin media you have will make this easier.
Next, you're going to create a directory for your media and mount the USB drive. Type:
sudo mkdir /media/usb
Then:
sudo mount /dev/sdb1 /media/usb
The second command allows you to access the USB files from your local directory. Next, you will use the move command to move the HTML file to the web server. Enter:
sudo mv /media/usb/yourHTMLfilename.html /srv/ftp/www/yourHTMLfilename.html
When you're finished moving files to your web server, unmount the USB drive:
sudo umount /media/usb
Then reboot your server machine entirely, by typing:
sudo reboot
After it restarts, go check to see if your webpage appears on your server, either by pulling it up in a web browser on another computer on your network, or by looking at the file directory by accessing /srv/ftp/www and entering either the ls or dir commands.
Final Notes:
If you've learned what I hope for you to have learned and sufficiently tested out this method, you will probably notice that the admin user on the server does not have access to the FTP server on any machine except the server itself, but does have access to the HTML file, and the user chrooted to the FTP directory has access to the FTP file, but only the original index page from Apache. However, you should have a much more functional understanding of a number of UNIX commands and navigating the file system.
Creating groups or using the symlink commands would likely make for a more functional server for multiple users in an enterprise application. I will post additional links as I find more information about the subject.
I hope this was of use to you. If you have any comments, questions, or suggestions, I would love to hear from you. Thanks for stopping by!
Of course it would! I thought you seemed like a fun person.
It doesn't actually matter what order you do these last steps, unless you want to experience the thrill of using one of the users you created to add files or webpages to your server. If you want that, then do the section on "chmod" first, since that will grant your user access to the server.
8. Change Permissions to the File and Web Server Directories
We're going to use the "chmod" command to "change mode" on the file and web server directories, so that other users have permission to read, write, and execute files on the server. Fully describing chmod is beyond the scope of this guide, but there is some great information out there already on the subject. Here's a great place to learn more:
https://en.m.wikibooks.org/wiki/A_Quick_Introduction_to_Unix/Permissions
We're just going to use chmod 777 to change the permissions on this file. This is almost certainly not what you would choose in an actual organization, since this makes the file accessible to everyone, but it works for this project and for you to learn how to change permissions to a file.
From the command line:
sudo chmod 777 /srv/ftp
Now your created user should be able to place files onto the file server. To test this, go to another machine on your network. I'm using a Windows 7 machine to do this - here are the commands I'm using to test:
- Press Windows button and type "run" (without quotation marks)
- Select "Run" application from list
- Type "cmd" into the prompt
- Type "ftp your.server.ip.address"
- Enter added user's username and password at the prompts
- Enter "bin" to ensure binary mode (always do this when you're accessing an ftp server to avoid headaches from ASCII)
- Create and save a document on the desktop of the Windows machine outside of the terminal.
- Back at the terminal, type "put C:\Users\username\Desktop\filename.extension
- You can access the file name under "properties" by right clicking on the file icon on the desktop.
- The message "226 Transfer complete" lets you know that you've successfully added a file!
Nice work!
9. Create a Web Page and Save to USB Drive
There are so many ways you can do this. I'm not going to teach you any html here - there are plenty of places to learn that elsewhere online. You have many easy options at your disposal. You will probably want to use a computer with a GUI to do this, though, if you're not planning on learning the basics of HTML programming. Easy options:
- Open a document in a text editor like Notepad. Edit it however you like, and save it as an HTML file by replacing the default .txt extension with .html.
- Use a free website generator to make a webpage. Right click on the page and select "View page source". Copy and paste the source code into a text document and save as an HTML file.
- Go to a website you like and copy the source code, save into HTML file.
- Leave the default "index" file listed on your web server - there's already a (boring) page there, haha. Although it does have some good information about Apache...
Then save your HTML file onto a USB drive. I'm guessing that if you're this far into this guide, you probably don't need instructions on how to do that, but if you do, there are plenty of instructions online. It's not complicated if you're using a computer with a GUI.
10. Place Your HTML File onto the Apache2 Server and Test Accessibility
10. Place Your HTML File onto the Apache2 Server and Test Accessibility
Although you could simply adjust the settings on /srv/ftp/www so that your user can upload a webpage to the server, we're going to do this from the terminal for the opportunity to learn an additional skill: mounting a USB drive and moving information from a USB device to the local drive using the command line.
First, you need to find out where your USB drive is located. Place the USB with the HTML file you created into one of the USB slots. Then go to the command line, and type:
sudo fdisk -l
You will need to exercise a little critical thinking in reading the output - you should see your media listed as something like "/dev/sdb1". You will know it's the correct one by identifying the size of the volume, which should be different from other volumes the system lists, such as your hard drive. Removing any other plugin media you have will make this easier.
Next, you're going to create a directory for your media and mount the USB drive. Type:
sudo mkdir /media/usb
Then:
sudo mount /dev/sdb1 /media/usb
The second command allows you to access the USB files from your local directory. Next, you will use the move command to move the HTML file to the web server. Enter:
sudo mv /media/usb/yourHTMLfilename.html /srv/ftp/www/yourHTMLfilename.html
When you're finished moving files to your web server, unmount the USB drive:
sudo umount /media/usb
Then reboot your server machine entirely, by typing:
sudo reboot
After it restarts, go check to see if your webpage appears on your server, either by pulling it up in a web browser on another computer on your network, or by looking at the file directory by accessing /srv/ftp/www and entering either the ls or dir commands.
Final Notes:
If you've learned what I hope for you to have learned and sufficiently tested out this method, you will probably notice that the admin user on the server does not have access to the FTP server on any machine except the server itself, but does have access to the HTML file, and the user chrooted to the FTP directory has access to the FTP file, but only the original index page from Apache. However, you should have a much more functional understanding of a number of UNIX commands and navigating the file system.
Creating groups or using the symlink commands would likely make for a more functional server for multiple users in an enterprise application. I will post additional links as I find more information about the subject.
I hope this was of use to you. If you have any comments, questions, or suggestions, I would love to hear from you. Thanks for stopping by!