Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".

Debian10 ; FTP server, Web server Apache

1. FTP server installation

1.1 Install vsftpd

Install
# apt install vsftpd

FTP Port21 permission
# ufw allow ftp

Edit vsftpd configuration file

# 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

Next, create a new vsftpd.chroot_list under /etc.
Add your Debian user name (e.g. debian-user) to this file.

# vi /etc/vsftpd.chroot_list
debian-user

Finally, enable vsftpd and reboot

# 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.

# ufw allow http

Install Apache2

# apt -y install apache2

Basic Configuration of Apache2

# vi /etc/apache2/conf-enabled/security.conf
# Line 25: Change
ServerTokens  Prod

# 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

# vi /etc/apache2/apache2.conf

# Line 70: Server name added.
ServerName <Domain Name>
# Line 172: Change
AllowOverride ALL

# vi /etc/apache2/sites-available/000-default.conf
# Line 11: Change administrator address
ServerAdmin  hoge@hoge.com
# systemctl restart apache2

2.2 Apache2; using Perl scripts

Install and enable Perl.

# apt -y install perl

Enable the CGI module.
# a2enmod cgid
Enabling module cgid.
To activate the new configuration, you need to run:
systemctl restart apache2

Restarting Apache
# 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
# 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.
# chmod 705 /usr/lib/cgi-bin/sample_script
operation check
# curl http://localhost/cgi-bin/sample_script
Hello CGI
In the rare case that you get a “curl: command not found” message
# apt install curl
check again

2.3 Apache2; using PHP scripts

Install PHP

# apt -y install php php-cgi libapache2-mod-php php-common php-pear php-mbstring

Configuring Apache2

# a2enconf php7.3-cgi
Enabling conf php7.3-cgi.
To activate the new configuration, you need to run:
systemctl reload apache2
# systemctl restart apache2

Editing the PHP configuration file

# 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”
# systemctl restart apache2

Create a PHP test page and check it works
Creating a test page

# 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>

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

# cd /etc/apache2/sites-available/
# cp 000-default.conf vhost-hoge.com.conf

Edit the configuration file

# vi vhost-hoge.com.conf
<VirtualHost *:80>
~Abbreviation~
ServerName hoge.com
ServerAdmin hoge@hoge.com
DocumentRoot /var/www/html/hoge.com
~Abbreviation~
ErrorLog ${APACHE_LOG_DIR}/hoge.com.error.log
CustomLog ${APACHE_LOG_DIR}/hoge.com.access.log combined
~Abbreviation~
</VirtualHost>

Disable the default configuration file by putting a symbolic link to it

# cd /etc/apache2/sites-available/
# a2ensite vhost-hoge.com.conf
# a2dissite 000-default.conf  Default disable
# systemctl restart apache2

Edit the hosts file

# vi /etc/hosts
127.0.0.1 hoge.com

Create directory

# mkdir /var/www/html/hoge.com

Create a test page and check it works.

# vi /var/www/html/hoge.com/index.html
<html>
<body>
<div style=”width: 100%; font-size: 40px; font-weight: bold; text-align: center;”>
Virtual Host Test Page
</div>
</body>
</html>
タイトルとURLをコピーしました