LAMP installation and configuration

Started by alex.thomson, Aug 08, 2022, 03:42 AM

Previous topic - Next topic

alex.thomsonTopic starter

I want to tell you how I accidentally got my hands on a motherboard from a laptop, a couple more components and decided to try to save on hosting provider and make a kind of "server" for my website, which doesn't exist yet.



Suitable for my needs. The power consumption is ridiculous, the cooling is passive, even the battery is alive, it lasts for about 4-5 hours of operation. The site will be quite simple - this is my educational project.

Briefly about the characteristics:

    Processor: Intel Atom processor E3800

    Memory: 2 Gb SODIMM DDR3

    Storage device: FoxLine 8Gb HalfSlim SATA SSD

    Network interfaces:

        Realtec RTL810xE Fast Ethernet controller 100Mbit

        Realtec RTL8723BE PCIe Wireless Network Adapter

Installing Debian 11

I first downloaded the Debian 11 iso, then downloaded Rufus and created a bootable flash drive. There is nothing special to describe, the program is intuitive: just select the image for recording, select the media, but which image to write and press start.

The bootable flash drive is ready - let's proceed with the installation. I did not use the graphical installation, but chose the Install option.


some of the devices require non-free (non-free) firmware. It can be loaded from external media, such as a USB flash drive. In my case, the motherboard has only two usb ports: one is occupied by the keyboard, the other by the flash drive with which the system is installed. But there is also a card reader!

I got the SD card and, having written the required file to it (link to rtl8723befw_36.bin), clicked yes. Now the wi-fi module will work. After that, a window pops up with the choice of the network adapter that we will use. I chose wi-fi.

Here, many will say - STOP, the wi-fi channel is already wired and they will be right, but I'm not doing professional hosting, this is just a project for self-development, besides, isn't it interesting how it will work after the installer has picked up the firmware;) So, I select the wi-fi module and in the next window I see available wireless networks. I choose my nik's_wireless, enter the password and everything is connected.

Next, I set the hostname (debian), domain name (lan), root password, full username (Nikolai Kutuzov), account name (nikkutuwdzov), account password, time zone.

Then work with partitions (Guided - use entire disk), select the disk on which we will install the system. I chose the suggested scheme (All files in one partition). I click Finish partitioning and write changes to disk - I finish with the markup and write the changes to disk. I set up the package manager  - deb.debian.org - NO). I am almost at the finish line and I am offered to choose which software to install, I left the asterisks only for the web server and ssh server.


WiFi setup

During installation, I connected to my wi-fi network, but after rebooting, there is no connection. First of all, LOCALLY log in as root and execute the command:

# /sbin/iwconfig

  wlp4s0 is our interface (you may call it differently), it is not connected to any network. We'll fix everything now.

Restrict user rights to the file to protect the key (pre-shared key) (PSK):

# chmod 0600 /etc/network/interfaces

Let's edit the file:

# nano /etc/network/interfaces

"auto" will enable the wlp4s0 interface at system startup. If this is not needed, you can remove or comment out this line.


I'm only interested in the address lines - this will be the ip address of this computer, netmask - the subnet mask, gateway - the main gateway and dns-nameservers - the ip address of the dns server (I registered the server from google). Next comes wpa-ssid - this is the name of your wireless network, and wpa-psk is its password. I am using the static address shown in the screenshot. Save the changes in the file (ctrl+o), close the file (ctrl+x) and reboot:

# systemctl reboot
Setting up sudo

After the reboot, ssh login will be available, which I will use. I will show on the example of MacOS, because I myself use this specific system. I think that on other systems, connecting via ssh will not be a truble.

In the terminal I type ssh nikkutuwdzov @192.168.1.111, where nikkutuwdzov is the username (not root), and 192.168.1.111 is the ip address I specified above. I enter the password and voila - I'm in the system. First, I installed sudo so that I don't have to run as root. Runs in three commands:

$ su - to switch to root and enter the password

# apt update - update package list

# apt install -y sudo - install sudo

 After installation, I typed the command:

# visudo


I go to the line after root ALL=(ALL:ALL) ALL and write there nikkutuwdzov ALL=(ALL:ALL) ALL, where instead of nikkutuwdzov enter your username.

   I save the changes to the file (ctrl+o), exit nano (ctrl+x) and switch from root to my user:

  # su nikkutuwdzov


FTP setup

To configure FTP I execute the following commands. By the way, now you can feel the beauty of sudo. I will use the previously installed sudo:

$ sudo apt install vsftpd - to install vsftpd (link on Wikipedia)

$ sudo systemctl status vsftpd

active (running) - says that everything is working and everything is fine.

Now let's create a unique user for ftp:

$ sudo adduser

I add the created FTP user to the list of allowed users for login:

$ echo "ftpuser" | sudo tee -a /etc/vsftpd.userlist

Create and assign appropriate directory access and ownership rights:

$ sudo mkdir -p /home/ftpuser/ftp_dir

$ sudo chmod -R 750 /home/ftpuser/ftp_dir

$ sudo chown -R ftpuser: /home/ftpuser/ftp_dir

 It took a few more manipulations for the final adjustment. To do this, I slightly corrected the configuration file, after installing vim:

$ sudo apt install -y vim

$ sudo vim /etc/vsftpd.conf

I will not list each line independently, but rather show on the screenshots what needs to be uncommented, what to change and what to add. If someone wants to repeat my experience or just take some of the information, I will only be happy, but this article is not a guide.


mariadb setup

The next step was to set up the database. I am using mariadb. It is installed with a simple command:

 $ sudo apt install -y mariadb-server

After installation, you need to execute the initial configuration script:

$ sudo mysql_secure_installation

All preconfiguration comes down to a few answers:

    Enter the root password for the current database (not to be confused with the system root!). It's empty, so I just press enter;

    When installed on Debian systems, the MariaDB root user is configured to authenticate with the unix_socket plugin rather than with a password. In many cases, this provides greater security and convenience, but it can also complicate things if you need to grant administrator rights to an external program (such as phpMyAdmin).
Therefore, I answered negatively to the proposal to use this plugin, since I plan to install phpMyAdmin later;

    When prompted to set the root password, I press n. The point is that in Debian, the mariadb root account is strictly tied to automated system maintenance, so we shouldn't change that password. Later I will set up an additional account for password access;

    When asked about deleting anonymous users, I answer "y";

    To deny connection under root, I remotely answer "y";

    Delete test database - "y";

    Finally, we save the changes by answering the last question with "y".


Now, as I said in point 3, I set up an extra account for logging in with a password:

$ sudo mariadb

MariaDB [(none)]> GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

MariaDB [(none)]> FLUSH PRIVILEGES;

MariaDB [(none)]> exit

Checking:

  $ mariadb -u admin -p

Installing and configuring php and phpMyAdmin

In the future, you will need to create a database and a user for it. The most convenient way, in my opinion, is phpMyAdmin, and we will install it. First you need to install a few packages:

$ sudo apt install -y php libapache2-mod-php php-mysql

Then fix the file:

$ sudo vim /etc/apache2/mods-enabled/dir.conf


Install phpMyAdmin:

$ sudo apt install -y phpmyadmin

During installation, several configuration windows will open, we do everything as in the screenshots (I set the password the same as when setting up an extra mariadb user)

We first check apache, it should have worked from the very beginning without any config, for this we type the ip-address of our "server" in the browser line, in my case 192.168.1.111

Check phpMyAdmin - 192.168.1.111/phpmyadmin

 All setup went smoothly. I did not come across any nuances. I hope that for others who want to do the same following to my description, everything will go smoothly as well. Next, we need a static ip-address - it is provided (for a fee, of course) by the provider, the domain name (it has been bought for five years, but has not been used to this day) and since I have a "server" behind the firewall of the router on openWRT , you need to open the necessary ports.

It will also detail how to set up virtual hosts, obtain a certificate for a future website (for free!) and install wordpress. There was a lot of information, perhaps it was necessary to break it into several parts, but it turned out as it happened.
  •  

kosmon

AX201 test result on my computer to the provider's server in my city, 5 ms ping. And the author does not need to play, in his case the ping is insignificant. There may be nuances in terms of data transfer speed, because.
there is only one channel for all devices connected to the router, but this is also not essential for the author's web server. In a high-rise building, neighbors who have occupied all channels can interfere, but in ours there are only 2 routers at 5 GHz, all the rest are sitting at 2.4 GHz on the provider's modems.

I'm not saying that we urgently need to switch to the air - the main idea was that Wi-Fi is no longer inferior to a wired connection. The main traffic consumption now is from mobile devices, how to connect them via copper or optics?
And copper is not bad only as long as there are no more than 4 devices in the house, otherwise the pile of switches and wires begins .
  •