Ubuntu Server 20.04 NTP , FTP , WEB server

1. Install an NTP server

# apt -y install chrony
# vi /etc/chrony/chrony.conf
# 17 to 20 lines:Comment the default settings and add an NTP server in your own timezone
#pool ntp.ubuntu.com     iburst maxsources 4
#pool 0.ubuntu.pool.ntp.org iburst maxsources 1
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2
pool ntp.nict.jp iburst
# Add to last line (Range of time synchronisation allowed)
allow 192.168.11.0/24
Settings reflect
# systemctl restart chrony
# Operation check
# chronyc sources
10 Number of sources = 4
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================
^- ntp-b2.nict.go.jp             1   6    37    27   +150us[ +150us] +/- 5360us
^- ntp-a2.nict.go.jp             1   6    37    26   +215us[ +215us] +/- 5529us
^* ntp-b3.nict.go.jp             1   6    37    28    +13us[  -13us] +/- 5814us
^- ntp-a3.nict.go.jp             1   6    37    28   -466us[ -466us] +/- 6069us

2. Install the FTP server vsftpd

①Install

# apt install vsftpd

②Open PORT 21 at UFW

# ufw allow ftp
# ufw reload

③Configuration file changes

# vi /etc/vsftpd.conf

# Line 14.
Listen=YES

# Line 22.
Listen_ipv6=NO

# Line 25.: Do not allow anonymous users to log in
anonymous_enable=NO

# Line 28.: Allow local user accounts to login
local_enable=YES

# Line 31.:Allow the use of FTP commands to make changes to files
write_enable=YES

# Line 35.:Set the permission values to be applied to new files
# Each digit indicates owner, group, other, and the bit indicates rwx
local_umask=022

# Line 122.:Change the user’s login directory to the user’s root directory
chroot_local_user=YES

# Line 123.:Users will no longer have access outside the login directory
chroot_list_enable=YES

# Line 125.:Users listed in vsftpd.chroot_list are excluded from the above restrictions
chroot_list_file=/etc/vsftpd.chroot_list

# Line 99.:Allow ASCII uploads
ascii_upload_enable=YES

# Line 100.:Allow ASCII downloads
ascii_download_enable=YES

# Line 131.:Uncomment (enable bulk transfer of whole directories)
ls_recurse_enable=YES

④Create vsftpd.chroot_list

# vi /etc/vsftpd.chroot_list
Fill in only the user name in the new file and finish saving.
<user name>

⑤Restart vsftpd

# systemctl restart vsftpd

⑥Check with FTP client
This time we will use FFFTP.
Open FFFTP and select Connect from the menu bar.
This will open a window called Host List. Please select a new host.

「General」tab open
Fill in the following fields
1.Profile Name (any name)
2.Host Name/Adress(Server IP address)
3.Username(General User Name)
4.Password/Phrase(General user password)

You are now back in the Host List window. Please press Connect

The window Saving the encryption status will open. Please select Yes

If you see the Windows directory on the left and the Ubuntu directory on the right, you have successfully connected.
If you can’t get through, turn Passive mode on and off.

3. Apache2 installation

First allow port http:80 and port https:443 on UFW

# ufw allow http
# ufw allow https
# ufw reload

3.1 Install Apache 2

# apt -y install apache2

3.2 Apache2 Basic Configuration

# vi /etc/apache2/conf-enabled/security.conf
# Line 25.:change
ServerTokens  Prod
# vi /etc/apache2/mods-enabled/dir.conf
# Line 2.:Check which file names can be accessed by directory name only
DirectoryIndex  index.html index.htm index.php
# vi /etc/apache2/apache2.conf
# Line 70:Server name added
ServerName <Your domain name>
# Line 172:change
AllowOverride ALL
# vi /etc/apache2/sites-available/000-default.conf
# Line 11:Change of administrator’s address
ServerAdmin <your mailaddress>
Apache restart
# systemctl restart apache2

3.3 Apache2 : Using Perl Scripts

Enable CGI and configure it to use Perl scripts
①Install Perl

# apt -y install perl

②Enable and restart the CGI module

# a2enmod cgid
# systemctl restart apache2

③Check CGI modules are enabled
Test script creation

# cat > /usr/lib/cgi-bin/test_script <<‘EOF’
#!/usr/bin/perl
print “Content-type: text/html\n\n”;
print “Hello CGI\n”;
EOF

Granting permissions to script files

# chmod 705 /usr/lib/cgi-bin/test_script

Operation check

# curl http://localhost/cgi-bin/test_script
“curl: If you get the message “Command not found”
# apt install curl
again
# curl http://localhost/cgi-bin/test_script
Hello CGI

3.4 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.4-cgi
Enabling conf php7.4-cgi.
To activate the new configuration, you need to run:
systemctl reload apache2
# systemctl restart apache2
# vi /etc/php/7.4/apache2/php.ini
# Line 846 : change
#upload_max_filesize = 2M
upload_max_filesize = 200M
# Line 962:Uncomment and set time zone
date.timezone = “Asia/Tokyo”

③Create a PHP test page to see how it works

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

Access “http://<server IP address>/index.php” in your browser
If you get a screen like this, you have succeeded

3.5 Apache2 : Virtual Host Configuration

①Copy the default configuration file(The file name is arbitrary, in this case “vhost-yourdomain.conf” as an example)
Virtual host configuration

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

②Edit the configuration file you have created

# vi vhost-yourdomain.conf
<VirtualHost *:80>
~省略~
ServerName <Your domain name>
ServerAdmin <Administrator email address>
DocumentRoot /var/www/html/<Your domain name>/
    ~Abbreviations~
ErrorLog ${APACHE_LOG_DIR}/<Your domain name>.error.log
CustomLog ${APACHE_LOG_DIR}/<Your domain name>.access.log combined
    ~Abbreviations~
</VirtualHost>

③Disable the default configuration file by symlinking to it

# cd /etc/apache2/sites-available/
# a2ensite vhost-yourdomain.conf
# a2dissite 000-default.conf  Default disablement
Apache再起動
# systemctl restart apache2

④Editing the hosts file

# vi /etc/hosts
127.0.0.1 <Your domain name>

⑤Create directory

# mkdir /var/www/html/<Your domain name>

⑥Create a test page and check it works

# vi /var/www/html/<Your domain name>/index.html
<html>
<body>
<div style=”width: 100%; font-size: 40px; font-weight: bold; text-align: center;”>
Virtual Host Test Page
</div>
</body>
</html>

⑦Check by accessing “http://<server IP address>/index.html” in your browser

タイトルとURLをコピーしました