Setting up a web server with Ubuntu Server 22.04.1 LTS

Setting up a web server with Ubuntu Server 22.04.1 LTS.

Initialisation

Connecting via SSH.

If installed from the Setup menu on a VPS, connect as root, add a general user and give sudo permission.

Log out and login via SSH with the added user.

SSH server configuration

Disable root user login.

Firewall configuration

Enable firewall.

Next, add rules for communication permissions on the port for SSH connections with ufw allow.

Check with the ufw status verbose command.

If there are no problems with the added rules, the settings can be reloaded.

Installing ‘Apache2’

Check with your browser.

If the default Ubuntu 22.04 Apache web page is displayed, OK.

Virtual host configuration

If you want to assign a hostname that can be used by other users, via FTP or others, configure it in the /var/www directory as public/USER_NAME/DOMAIN_NAME.

*After creating the user, assign ownership of the USER_NAME directory.

If you are the only one using the domain of the virtual host, the following:

There is a method of using user directories, but for some reason it didn’t work, so this way of configuration works.

Create a new configuration file in /etc/apache2/sites-available/DOMAIN_NAME.conf.

In the example, create /var/www/vhosts/example.com/logs.

Use the a2ensite tool to enable the DOMAIN_NAME.conf file you have created.

Check for configuration errors.

If you see output as following, restart Apache.

Create index.html in /var/www/vhosts/example.com/httpdocs, and then go to http://example.com from a browser, and if the HTML file you created is displayed, you have succeeded.

E.g. index.html

Get a SSL certificate using Let’s Encrypt

Install certbot python3-certbot-apache

Enable SSL ports on the firewall.

To make Let’s Encrypt generate an SSL, enter the following command.

To edit the configuration file, /etc/apache2/sites-available/vhost-le-ssl.conf

Install MariaDB

Install PHP

To install a version other than installed by default

Add repository.

Install phpMyAdmin

Select apache2 (press spacebar ‘*’), select [Ok] and press [Enter] on the keyboard.

When prompted to confirm database installation, select No & Enter.

The configuration file is /etc/phpmyadmin

Install PHP Composer

If you installed a version of PHP other than the default one.

Install vsftpd

Changes and additions

Create an empty file /etc/vsftpd.chroot_list.

Create /etc/vsftpd/vsftpd_user_conf, create USER_NAME file, describe user root directory.

In /etc/vsftpd, create the ftpuser_list file, a list of users to connect to via FTP.

コメント

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