Welcome to another LowEndBox Linux tutorial! In this article, we will design and configure a high performance server that will allow you to manage multiple websites using the latest software available. Our server will be based on CentOS 7 Theinux, APache 2.4, MariaDB (a fork of MySQL) and PHP 7.3. This combination of software is called a "LAMP" stack.
Why would we want to manually configure a LAMP stack instead of installing a control panel like Virtualmin or cPanel that would do it for us? Sometimes we want to create a custom server with only the specific features you want. Or, we want to know how all the software works and is configured. Perhaps we want to save the full power of our servers to serve sites rather than spend a system time running a control panel. Whatever your reason, even a small low-end VPS can host multiple sites with a little configuration.
Of course, there are many tutorials on the LAMP stack. Some show you how to simply install Linux, Apache, MariaDB and PHP in a default configuration that is suitable only for hosting a single website. In addition, many of them rely on the default installation of CentOS, which contains outdated software, such as PHP 5.4.
We will intensify a few notches. In this tutorial, we will show you how to use a default installation of CentOS 7 and configure it with the latest software with a powerful configuration on which you will be proud to host several websites. But we do not stop there. This tutorial will also help you understand Why we made the design choices we make and How all the components interact with each other.
In future articles, we will add features. Make sure to come back later!
As mentioned, a LAMP server is simply Linux, Apache, PHP and MariaDB. To do it right, there are some things to consider. One of the reasons why CentOS 7 is an amazing server operating system, is that it promotes stability and security above all else. As a result, the CentOS repositories provide PHP 5.4 and MariaDB 5.5, which corresponded to the current version of CentOS 7. These are very old versions of PHP and MariaDB. PHP 5.4 is no longer usable with modern software such as WordPress.
To remedy these problems, we will configure our server to obtain the software from other repositories offering PHP 7.3 and MariaDB 10.3.15 (at the time of publication). In the interest of this tutorial, we will assume that the server has only one IP address. Our own server is a VPS 1 core with 512 MB of memory and 15 GB of disk. Let's start!
Log in to the control panel of your VPS provider and start by setting the hostname of your server. It must be something called a "fully qualified domain name" or FQDN. It will look like "server.yourdomainname.tld". You must use a prefix such as "server" before any chosen name. We will set up hosting for "your-domainname.tld" later in the process.
In the control panel of your VPS provider, it will provide you with a way to install your operating system of your choice. You will want to choose "CentOS 7 Minimal 64 bit" or something. Here's what it looks like on our LowEndBox:
Write down the root password and wait for the end of the installation. When finished, log in and set up your SSH keys. If you do not know how to do this, do not worry. We have you covered in our other tutorial "Using SSH keys to connect to your VPS".
Now that you're connected, it's time to meet some basic configuration needs. The first thing to do is to disable SELinux. Use the following command to do this:
sed -i / # 39; s / SELINUX =. * $ / SELINUX = disabled / / / / selinux / config
Now, restart the server (just type "reboot" and press enter), then log back in. Make sure SELinux is disabled with the "getenforce" command:
Disabled – perfect! We can now proceed to the following preparations: Allow traffic on port 80 through the firewall. Your VPS provider may have included CentOS 7's built-in FirewallD, but they may not have it. Let's see first. Use the following command to determine whether it is installed:
rpm -qa | grep firewalld
You should see the following output:
If you do not do it, then FirewallD must be installed with the following command:
yum-y install firewalld
You can now open port 80 (http) and reload the firewall rules:
firewall-cmd --zone = public --add-service = http --permanent firewall-cmd --reload
The final preparation is to install software sources that will provide us with the latest versions of PHP and MariaDB. Paste the following commands in your terminal:
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | hit yummy install http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum-config-manager --enable remi-php73 yum makecache fast
Now that the initial setup is complete, we can start installing what will turn our minimal CentOS 7 installation into a true LAMP server. For starters, we'll install some basic utilities that we might need later, including the simple Linux nano text editor. Run this command:
yam-y install sysstat lsof traceroute whois ftp ftp nano yum-utils
We will install Apache (the HTTP daemon, also called httpd) and MariaDB:
yam-y install httpd mariadb-server mariadb mod_ssl
We want Apache and MariaDB to start automatically when the server starts. We also want to start them now:
systemctl enable httpd.service systemctl activate mariadb systemctl start httpd.service systemctl start mariadb
Now let's clean up the MariaDB installation with the "mysql_secure_installation" command. Here's what it looked like on our server:
Your current root password will be empty, just press Enter. Now you will be asked to set a root password for MariaDB. This is done do not must match the server's root password. It is however recommended to set a secure password, as you would for the root Linux user. Be sure to write down the password that you set because it is essential for the operation and configuration of the server. Just press Enter for the rest of the questions asked by the script.
Your results should look like this:
Apache is a modular program, but it does not know how to run PHP scripts. A PHP script produces an output that Apache can pass on to anyone who requests it, but PHP must do most of the work. For this, Apache has an interface called Common Gateway Interface, or CGI. The official documentation of Apache explains it this way:
"The CGI (Common Gateway Interface) defines a way for a Web server to interact with external programs that generate content, often called CGI programs or CGI scripts."
Other methods have appeared after CGI, including DSO, suPHP and FastCGI. For a thorough review of these technologies, we recommend this fantastic article by Chris Wiegman.
The PHP manager we are going to use is not specifically mentioned in this article, but PHP FastCGI Process Manager (PHP-FPM) is an implementation of FastCGI. PHP-FPM is very fast because PHP is always ready for Apache to give it something to do. This is secure because PHP scripts are run under the ownership of the site owner.
Let's see now how we are going to configure Apache for website hosting. There are two types of hosting: virtual and not virtual hosting. Non-virtual hosting means that a website is directly linked to an IP address. Each website must have its own IP address. This is what you have if you download a website directly into / var / www / html after installing Apache. It also means that you are very limited in the number of websites that you can host on a server (one).
Virtual hosting means that websites are linked to a domain name instead, all sites can use the same IP address. Each website will have its own Linux user, Apache configuration file and PHP-FPM configuration file. You can add as many virtual hosts as your server can manage, instead of being limited to only one website per server. Let's go into the current configuration job. We will explain along the way.
We have already installed the Remi repository because it contains everything needed to install PHP 7.3 with PHP-FPM. In addition to PHP-FPM, we will also install most of the most commonly used modules, including the mysqlnd module that allows PHP to talk to MariaDB.
Paste this command into your SSH session:
youtube php73 php73-php-php73-php-php-php-php-php-php-php-php php73-php-mbstring php73 php-php php73-php-xml php73-php-xmlrpc php73-php-opcache php73-php-pecl-ssh2 php73-php-gd php73-php-bcmath php-pear-Net-Curl.noarch php73-php-pecl-imagick php73-php-xml php73-php-xmlrpc php73-php-pecl-mcrypt
We also want to use PHP 7.3 from the command line. So we will call the Software Collection Utility, which makes things easier:
scl active php73 bash
All software is in place. It is now time to add a new user to our server and set up a website, then we will have our first fully configured virtual host and we can start hosting websites. The second part will be published shortly, be sure to come back!