If you want to set up a web server and look for some tips, this article is for you. Here are instructions for setting up a web server (LAMP = Linux + Apache + MySql + PHP) on OS Ubuntu 20.04, in connection with:

Apache 2
PHP 7
Mysql Sever 8

To start, go to the CLI (command-line user interface). You can open it with Ctrl + Alt + T combination. If you don't want to set up a local webserver, then you need to connect to your server via SSH.

Once you are on a proper instance in the terminal enter super user mode (root or sudo user). Run the following command:

sudo su

and enter the password to your account, if required.

Take the following steps to install the web server:

1. Update the available package information. Run this command:

sudo apt update

* In the examples, the commands that must be executed by the superuser beginning with the word sudo. You do not have to use sudo while in superuser mode.

2. Install the Apache 2 webserver.

sudo apt install apache2

3. Install the MySQL database server.

sudo apt install mysql-server

After the MySQL database server was installed, run the following command:

mysql -uroot

Also, enter these commands, one by one, to create a new user: 

CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY '<New-Password-Here>';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit

4. Install php7.4 and all necessary PHP libraries to work with Apache 2 and modern platforms, like Magento 2.

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

sudo apt install php7.4 libapache2-mod-php7.4 php7.4-curl php7.4-intl php7.4-zip php7.4-soap php7.4-xml php7.4-gd php7.4-mbstring php7.4-bcmath php7.4-common php7.4-xml php7.4-mysqli

5. Enable the apache mods to work with php7, rewrite, and restart the webserver.

sudo a2enmod php7.4
sudo a2enmod rewrite
sudo service apache2 restart

Follow the link and check if your local web server is working: http://127.0.0.1/ (alternative http://localhost/). If everything is correct, the following page will open:

Перевірки роботи mysql сервера

6. Change the user based on which the webserver will run.

For this edit the following file /etc/apache2/envvars.

sudo gedit /etc/apache2/envvars 

find these strings there:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

and replace them with:

export APACHE_RUN_USER=your_user
export APACHE_RUN_GROUP=your_group

where your_user — the name of your Ubuntu user (the one you want to edit files with), and your_group — group this user belongs to. Usually, the names of the user and the group are the same.

Save the file and reload the webserver.

sudo service apache2 restart

7. Change the owner of the web directory.

A web directory is a folder where your web application, such as Magento 2, is located. The goal is to give your user complete control over that folder. Run the following command:

chown -R your_user:your_group /var/www/html

8. Increase the memory limit (RAM) that is allowed for PHP.

By default, this value is 128 MB, which is insufficient to work e.g. with Magento 2.

Open the /etc/php/7.3/apache2/php.ini file for editing:

sudo gedit /etc/php/7.4/apache2/php.ini

find the following string

memory_limit = 128M

change it to

memory_limit = 1024M

save changes and reload the webserver once again.

sudo service apache2 restart

9. Change the virtual host settings.

Edit this file

/etc/apache2/sites-available/000-default.conf

and add the following code to the middle of the VirtualHost node:

<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>

Save changes and reload the web server

sudo service apache2 restart

10. Install MySQL

To manage MySQL databases, for example, to create new databases we recommend to install phpMyAdmin.