Ubuntu Server Construction Primer is a free web course for building a server from scratch on Ubuntu, one of the Linux distributions. The goal is to build a Web system development environment. If you build a Web development environment, you can almost complete the database environment for data analysis.
In this course, we will build a scalable, modern, real-time web-enabled web application on Ubuntu.
We will explain how to install a web server on Ubuntu, create a web application, connect to the web application from the web server with a reverse proxy, and publish it to the outside. Use Perl's web framework as a sample web application.
As of November 17, 2021, the version of Ubuntu has been confirmed on Ubuntu 18. Unless otherwise noted, it is assumed to work on Ubuntu 20 and Ubuntu 16.
If you like this free Ubuntu course, why not share it with others?
Make Ubuntu available
Let's make Ubuntu available.
Proceed to the console screen where you can execute commands, and then log in as the initial user.
Next, create a user on the console screen. Let's create two users, one to run the web application (myapp) and one to our own (for example, kimoto).
Add user There is an "-m" option, set a password, and add it to the sudo group.
Create the "myapp-group" group that your web application will need. This is required for web application users, development users, and Apache users to access the data directory.
Next, let's add myapp and developer users (eg kimoto) to "myapp-group".
Open the following ports in the firewall settings of the network provided by the hosting service. If you are building your server on-premises, use the ufw command to open the following ports.
|SSH||SSH port (default port 22 is dangerous)|
|Development web app||3000|
|Production web app||8080|
Port 3000 is the default port for the Mojolicious development server.
If you have multiple developers, open another port from the packet filter as needed (3001, 3002, etc.).
Port 8080 is the default port number for Mojolicious's production server.
If you run multiple web applications, open another port from the packet filter as needed (8081, 8082, etc.).
Using SSH client
Let's connect to the server with SSH from your computer so that you can execute commands and edit files.
Command execution on SSH client
In the case of Windows, TeraTerm is a tool for connecting to an SSH server with an SSH client and executing commands.
There are SSH clients that work on other Windows such as PuTTY, so you can use it as you like. so.
For Mac, you can use the ssh command from the terminal.
Use SCP to edit files on the server
You can edit files on the server using a protocol built on SSH called SCP.
WinSCP is the SCP client for Windows.
There is software on your Mac that can replace WinSCP on Windows, so install it.
SSH server settings
Time zone setting
Let's set the time zone to "Asia / Tokyo".
Let's install the packages required to build the Web system development environment. Default package will install what is missing.
Installation may not work, so make sure you have the latest version of apt first.
First, let's build a web server, application server, mail sending server, and DB server all in one machine.
Installation of C language / C ++ compiler / linker.
Compression / decompression
- Installing net-tools-deprecated but if you want to use ifconfig, arp, route, netstat for the time being
Installation of programming language. In alphabetical order.
- Java installation
- Install nodejs
- Perl installation
- PHP installation
- Installing Python 2 i>
- Installing Python 3
- Install Ruby
Creating a directory for data
Create a directory for your data to store files uploaded from your web application or to store JSON that summarizes your data in batch. This directory is where web applications launched by the "myapp" user and other development users upload files. Let's set appropriate permissions.
If you want to use an attached disk and make it a directory for data, follow these steps first. A directory for the data called "/ datadrive" will be created.
To use the default disk of the application server, create "/ datadrive" with the mkdir command.
sudo mkdir / datadrive
Then make this data directory writable to application users and other development users.
This completes the data directory.
Install and check the startup of the Redis server, which is the storage server for volatile information.
Make sure the Redis server is up by running "sudo systemctl status redis-server" in the following article.
Database server MariaDB
Install and check the startup of MariaDB, which is a database server.
Install database server and related libraries
- Installing mariadb-client --MariaDB client
- Installing mariadb-server --MariaDB database server
- Installing libmysqlclient-dev --MariaDB client headers and libraries
- Installing libmariadb-dev --MariaDB database headers and libraries
Confirm database server startup
Make sure MariaDB is running by running "sudo systemctl status mariadb" in the following article.
MariaDB server initialization
Let's initialize the database server MariaDB.
Check the startup of cron, which is a resident application for executing periodic programs.
Confirmation of cron startup
Make sure Apache is running by running "sudo systemctl status cron" in the following article.
Let's make the initial settings of crontab.
Install and configure Apache, the web server.
Set up a reverse proxy to connect to Mojolicious applications.
Set up SSL so that you can connect via HTTPS.
Install Apache and make sure it is running.
- Installation of apache2 --Apache version 2 series which is a web server
- Start / stop / restart / check the status of Aapache
Apache configuration file
Go to the Apache configuration file directory and configure Apache settings. Let's see how to check if the Apache config file is correct and how to enable the Apache config.
- Apache configuration file location
- Test if the Apache configuration file is correct
- Enable / Disable Apache Configuration File --Basic Settings / Module Settings / Site Settings
Enable the Apache module required to configure the reverse proxy and SSL.
- Enable mod_ssl for HTTPS communication with Apache
- Enable mod_rewrite module in Apache
- Enable mod_headers module in Apache
- Enable mod_proxy module in Apache
- Enable mod_proxy_http module in Apache
- Enable the proxy_wstunnel module for WebSocket reverse proxy in Apache
Creating a web application
Creating a web application. I'm using Perl's web framework as a sample.
If you want stability, install "perl-5.20.3" which has no problems with CPAN module installation and warning display.
If you want the latest secure version, install "perl-5.30.3".
Then deploy the web application.
Let the batch program find the path to the web application's library. Be prepared to create a batch program in addition to your web application.
Let's add it to "~ / .bashrc".
vi ~ / .bashrc
export PERL5LIB = / home / myapp / webapp / lib
Get domain name and set DNS server
Get the domain and associate the domain name with the server IP address. Required for publishing websites on the Internet and for portable settings on email sending servers.
Creating an email address and setting up a DNS server
Install postfix to send mail. Apply for a cloud email service so that you can send emails.
Connection between web server and web application
Let's connect the web server and the web application. A reverse proxy is a mechanism that transparently passes an HTTP request received by a Web server to another server application. After launching the web application, use a reverse proxy to pass the HTTP request to the web application.
Obtaining an SSL certificate and setting SSL
Issue an SSL certificate and configure SSL to receive requests over HTTPS.
- HTTPS support --Automation of SSL certificate acquisition / renewal / renewal of Let's Encrypt
- Describe the SSL certificate settings in the Apache configuration file
Systemd management of web applications
Let's set the Web application to start automatically when the OS restarts.
Procedure for building an environment with VPS or public cloud
The individual procedures using VPS and cloud server are published below.
- Summary of procedures for creating a Web system development environment with Sakura VPS + Ubuntu 18 + Perl
Ubuntu related information
Information related to Ubuntu.
Linux server management
Click here to learn about the vi text editor, basic Linux commands, and how Linux works.