Contents
1. FTP server installation
1.1 Install vsftpd
1 |
# apt install vsftpd |
1 |
# ufw allow ftp |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# vi /etc/vsftpd.conf # Do not allow anonymous users to log in anonymous_enable=NO # Allow login by local user account local_enable=YES # Allow the use of FTP commands to make changes to files write_enable=YES # Set the permission values to be applied to new files. # Each digit indicates owner, group, and other, and the bit indicates rwx local_umask=022 # Change the user's login directory to the user's root directory. chroot_local_user=YES # Users will no longer be able to access outside of the login directory chroot_list_enable=YES # Exclude users listed in vsftpd.chroot_list from the above restrictions chroot_list_file=/etc/vsftpd.chroot_list # Allow uploads by ASCII ascii_upload_enable=YES # Allow downloading by ASCII ascii_download_enable=YES # Line 131: Uncomment (enable bulk transfer of entire directory) ls_recurse_enable=YES |
Add your Debian user name (e.g. debian-user) to this file.
1 2 3 |
# vi /etc/vsftpd.chroot_list debian-user |
1 |
# systemctl restart vsftpd |
1.2 Check the FTP connection.
Use FFFTP, a Windows FTP client, to check.
Open FFFTP and select Connect from the menu bar.
A window called "Host List" will open. Select a new host.
A window called "Host Settings" will open. Enter the following and press OK
1. host configuration name (any name)
2. Hostname (IP address in Debian) 192.168.11.100
3. User name (Debian user name) hoge
4. password ********
You will be returned to the Host List window. Press Connect.
A window called "Save Encryption Status" will open. Select Yes.
If you can see the Windows directory on the left and the Debian directory on the right, the connection is successful.
If you cannot connect, turn Passive mode on and off.
2. WEB server Apache2 installation
2.1 Apache2 Installation and Configuration
Open port 80 before installing Apache2.
1 |
# ufw allow http |
Install Apache2
1 |
# apt -y install apache2 |
Basic Configuration of Apache2
1 2 3 4 |
# vi /etc/apache2/conf-enabled/security.conf # Line 25: Change ServerTokens Prod |
1 2 3 4 |
# vi /etc/apache2/mods-enabled/dir.conf # Line 2: Check for file names that can be accessed only by directory name. DirectoryIndex index.html index.htm index.php |
1 2 3 4 5 6 |
# vi /etc/apache2/apache2.conf # Line 70: Server name added. ServerName <FQDN> # Line 172: Change AllowOverride ALL |
1 2 3 4 |
# vi /etc/apache2/sites-available/000-default.conf # Line 11: Change administrator address ServerAdmin <mail-address> |
1 |
# systemctl restart apache2 |
2.2 Apache2; using Perl scripts
Install and enable Perl.
1 |
# apt -y install perl |
Enable the CGI module.
1 2 3 4 |
# a2enmod cgid Enabling module cgid. To activate the new configuration, you need to run: systemctl restart apache2 |
Restarting Apache
1 |
# systemctl restart apache2 |
When the CGI module is enabled, the [/usr/lib/cgi-bin] directory will be allowed to execute CGI by default.
By creating and deploying the [/usr/lib/cgi-bin/index.cgi] script, you can access [http://(Apache2 server)/cgi-bin/index.cgi]. Note that this setting treats all files under [/usr/lib/cgi-bin] as CGI, so non-CGI files cannot be displayed.
Let's create the following test script and see if it works.
Create a test script
1 2 3 4 5 |
# cat > /usr/lib/cgi-bin/sample_script <<'EOF' #!/usr/bin/perl print "Content-type: text/html\n\n"; print "CGI TEST\n"; EOF |
Grant permissions to script files.
1 |
# chmod 705 /usr/lib/cgi-bin/sample_script |
operation check
1 2 |
# curl http://localhost/cgi-bin/sample_script Hello CGI |
In the rare case that you get a "curl: command not found" message
1 |
# apt install curl |
check again
2.3 Apache2; using PHP scripts
Install PHP
1 |
# apt -y install php php-cgi libapache2-mod-php php-common php-pear php-mbstring |
Configuring Apache2
1 2 3 4 |
# a2enconf php7.3-cgi Enabling conf php7.3-cgi. To activate the new configuration, you need to run: systemctl reload apache2 |
1 |
# systemctl restart apache2 |
Editing the PHP configuration file
1 2 3 4 5 |
# vi /etc/php/7.3/apache2/php.ini # Line 841: upload_max_filesize = 2M → upload_max_filesize = 200M # Line 956: Uncomment and set time zone date.timezone = "Asia/Tokyo" |
1 |
# systemctl restart apache2 |
Create a PHP test page and check it works
Creating a test page
1 2 3 4 5 6 7 8 9 10 11 |
# vi /var/www/html/index.php <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> <?php print "PHP Test Page"; ?> </div> </body> </html> |
Go to "http://<server IP address>/index.php"
If you see a page like the following, you are good to go.
2.4 Virtual Host Configuration
Copy the default configuration file and configure the virtual host settings
1 2 |
# cd /etc/apache2/sites-available/ # cp 000-default.conf vhost-hoge.com.conf |
1 2 3 4 5 6 7 8 9 10 11 12 |
# vi vhost-hoge.com.conf <VirtualHost *:80> ~Abbreviation~ ServerName <FQDN> ServerAdmin <mail-address> DocumentRoot /var/www/html/<FQDN> ~Abbreviation~ ErrorLog ${APACHE_LOG_DIR}/<FQDN>.error.log CustomLog ${APACHE_LOG_DIR}/<FQDN>.access.log combined ~Abbreviation~ </VirtualHost> |
1 2 |
# cd /etc/apache2/sites-available/ # a2ensite vhost-hoge.com.conf |
1 |
# a2dissite 000-default.conf |
1 |
# systemctl restart apache2 |
1 2 3 |
# vi /etc/hosts 127.0.0.1 <FQDN> |
1 |
# mkdir /var/www/html/<FQDN> |
1 2 3 4 5 6 7 8 9 |
# vi /var/www/html/<FQDN>/index.html <html> <body> <div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;"> Virtual Host Test Page </div> </body> </html> |