CentOs Installation and Configuration of a Server, L. A. M. P. (Linux, Apache, Mysql Server) with Virtual Hosts, Multiple

There are plenty of control panels able to configure a LAMP server generic with any linux distribution, or almost. Other pay are also compatible with other platforms such as windows.

Many commands in this guide can be aggregated into a single one, however i prefer to divide them to help identify any errors. This guide has been tested step by step and assumes that you have installed a centos system 7 clean with the configured network.

If you have the sudo command installed and you are logged in as a normal user, you can simply enter the word "sudo" before the commands. But now we start to configure our "test server".

Configure the firewall

First of all you must be sure that your server to accept certain requests to certain ports. If the firewall is not installed, do not install it unless you know what you're doing or if you have the physical machine in front of you. If you have a router or a more complex network, I recommend that you read an article about the theory of networks, or an article on how to configure the virtual servers on a router to route traffic on certain ports. Here I will assume that you have a public address for a server available on the internet. Then, you should write these commands on your command prompt (shell).

Install Apache2

We open the doors to accept tcp connections on ports http (80) and httpd (443) to the default apache. Now we need to install apache2 as a simple web server by writing this command:

Start and Enable Apache2

After apache is installed, you need to avvare and enable the service (daemon) with this command

If you put the ip address of the server from a browser you should see the welcome page of apache and centos.

Configure the virtual hosts

To configure the virtual hosts on CentOS you should disable selinux or you will receive an error. To disable it temporarily so as to avoid having to restart the system, you can write

To be sure that this change lasts even after the reboot, you should edit the file /etc/sysconfig/selinux and be sure that the line on selinux is disabled as shown in this example:

Now we just need to create the configuration file for the virtual host that will put you inside the folder

In this article, we'll use the example of the domain example.com. You will need to replace the domain name example.com with your domain name.

Then create the configuration file

and insert the following lines:

Of course you need to also create the destination folder of the site and log if not exist:

At this point you need to restart apache

If your domain pointing to the server correctly, you should see the welcome page.

Considerations: I have read in many articles regarding the configuration of virtual hosts with CentOS that you recommend to create a specific folder containing the available sites and another that contains the enabled sites. This method is used in distributions based on debian and allows you to disable and enable a site simply by acting on the symbolic link. But this article is about CentOS, and then we shall follow the way of distributions based on RedHat.

Installation and configuration of Certbot (letsencrypt) for https support (optional but recommended)

If the site is dynamic, normally you may carry sensitive information and therefore it is a good idea to criptarle. To purchase a valid certificate, once it was an expensive operation, but now there is a system to acquire one totally free.

Make sure your DNS points to your server.

The first thing you need to do is install the apache modules for ssl support

And install the program certbot

To work in start-up phase, the https protocol must have a valid certificate. We can create this certificate in the following way

For this time, you can leave blank all the answers and you will have to wait until the end of the generation of the certificate. Since certbot check if the apache configuration is reasonable, we must add the instructions to the virtual host for the https protocol at the end of the file

Now we can create the certificate with certbot. Remember if you use a service such as Cloudflare you will need to pause it temporarily.

Now your domain should be visible from http://www.example.com . If you want users to be automatically redirected to https, you will need to modify the instructions of your virtual host with regard to the http protocol by adding the line

to the configuration file

as shown in this example

If you use services such as cloudflare or other methods of redirect do not enter this row or it will generate an endless loop of directives that it will return at the end an error on the browser.

Setup MariaDB (Mysql)

To install the mysql server, MariaDB, you have to write this command

Then you will need to start and enable the server

Now, mariadb is installed, but you should proceed to start the automatic safety of base because as it is, the service is configured with fewer restrictions as possible in order to be more convenient for developers. You can do this with the command

You will have to choose all the options that are recommended and you will need to enter a password for your root mysql account.

Considerations: CentOS has chosen to use MariaDB as the mysql server by default. However, I must tell you that this is a fork of the classic mysql server, and there might be some incompatibility issues when importing data. If you don't know the difference between mariadb and mysql community edition, I recommend you read an article on how to migrate data from a server mysql community release to a server, mariadb or how to migrate data from a server, mariadb-server mysql community release.

Installing PHP and the modules used by the CMS, the most common

To use the mysql, apache requires an intermediate program, which in our case is php. To install php with mysql support and all the forms most used by the most popular CMS type these commands

If you need to install other modules, you can search for them using the command

You can also filter the results with grep command. If for example, I want to display the modules with the inscription of pecl inside the name, I just have to write

Considerations: CenOS is a linux distribution, stable and conservative. The packages that you can install with the repository are the traditional tested. To install the latest versions, you should import the other repository. If you don't need to install the latest version of php, I suggest you to respect the choice of CentOS. If you need to install the version 7 of php, I recommend that you read an article relating to the installation and configuration of a LAMP (Linux Apache Mysql Php 7) server hosts multiple virtual on CentOS 7.

it | en | zh | es | ar | pt | id | ms | fr | ja | ru | de

// 2017-09-08 - 2019-06-29 // @ignistech #technology #computertechnology #systemsengineering #server #applications

Articles in this group

  1. CentOs Installation and Configuration of a Server, L. A. M. P. (Linux, Apache, Mysql Server) with Virtual Hosts, Multiple
  2. How to install the video drivers fglrx64_p_i_c-15.302-1.x86_64_rhel7_64a.rpm
  3. CentOs Installation et configuration d'un L.A.M.P. (Linux Apache Mysql Server) avec plusieurs hôtes virtuels
  4. Comment installer les pilotes vidéo fglrx64_p_i_c-15.302-1.x86_64_rhel7_64a.rpm
  5. To install CentOS 7 on VirtualBox, like any machine connected to the network
  6. Pour installer CentOS 7 sur VirtualBox, comme toute machine connectée au réseau
044.EU | Home | Terms | Privacy | Abuse | Hashtag