How to Install and configure LAMP-server (Linux, Apache, MariaDB/MySQL, PHP) in CentOS/RHEL 7


LAMP is an acronym denoting the set of (complex) server software, widely used in the World Wide Web. LAMP is named after the first letters of its constituent components:

  • Linux is the Linux operating system;
  • Apache is a Web server;
  • Mariadb/MySQL is a database management system;
  • PHP is a programming language used to create Web applications (other than PHP can mean other languages such as Perl and Python).


 

Install the Apache Web server

Install the httpd package, run it and make any necessary changes to the firewall for it to work:

Open in browser link http://example.com/ and make sure that the Web server is running.
 
Now configure HTTPS on Apache:
Install the special plug-in for Apache and configure it (the Secure Sockets Layer (SSL) certificates required for operation of the module, we will use the already available, which we created in this post)):

Open in browser link https://example.com/ and make sure that the Web server runs by using the HTTPS protocol.
 

Installation of MariaDB (MySQL)

Install the required packages will run and configure SQL Server:

Do not pay attention to the error:

It has no effect, and in the following versions of MySQL this error will be gone. Here is a description of the bug on the website developers.
If you plan to connect to the SQL Server from the outside, you want to allow connections to port 3306 in firewall and configure the MariaDB to work on this port:

 

Installing PHP

Set and change some of the default settings:

Open the link https://example.com/phpinfo.php in your browser and make sure that PHP is running. Making sure that PHP is working to remove the test script:

 

Installing phpMyAdmin

First install phpMyAdmin:

Then set the IP addresses with which are allowed to connect to phpMyAdmin:

Now turn the SELinux permission Web server to make network connections, and sending mail:

Restart the Web server:

Open the link in your browser https://example.com/phpMyAdmin/setup/ and configure phpMyAdmin.
In the first window “Browse” in the “Server” click on the button “New server”. Fill in the fields “User name”, “Host Server”, select the connection type and click on the button “Apply”. If you need to add more servers to the list – you can repeat this several times.
After this switch in the “Settings” window, open the “Security” tab and put a check mark next to “Prefer the SSL connection” and click on the button “Apply”.
Now in the window “Browse” in the “Configuration file” select the default language and click on the “Save” button.
Now save the configuration in the Web browser and move it to the directory /etc/phpMyAdmin, and then delete the config folder:

 

Create a virtual host in Apache

Install the cronolog, in order to be able to write to the log files with the names of access_log.YYYY-MM:

First prepare the Apache virtual host to work in Debian-style:

In order to disable the virtual host – will have to run the command:

But in order to turn off virtual host, you will need to run the command:

So it’s a bit to automate, we will create in your .bashrc file a couple of aliases:

Now to disable the virtual host you need to execute the command:

And for enable:

Now let’s create our virtual host configuration file:

If HTTPS — the second part of the file, you can not write.
Just create the necessary folders and test file index.html:

Now make Apache reread the config files:

After these steps, you can try to open the link in your browser http://vhost.example.com/.
 
You need to be aware of the nuances of setting default aliases for Web applications with CentOS virtual hosts. Consider the example of phpMyAdmin. After you install phpMyAdmin in the file /etc/httpd/conf.d/phpMyAdmin.conf contains the following lines:

It is a normal aliases. But the problem is that if they leave in this file, it will work for all virtual hosts together! To avoid this, in this file, you need to comment out these aliases and move them to a separate configuration file:

Note the file extension, it is specifically not .conf, but .cnf, otherwise the contents of the config will be triggered where there is no need to. As for the point of including these aliases will be in the right places add this line IncludeOptional conf.d/aliases.cnf. First, we’ll add it to the file /etc/httpd/conf.d/vhost.conf:

as well as in the /etc/httpd/conf.d/ssl.conf file (aliases to the same work over https):

If you include the aliases for a virtual host, you can do this, add the IncludeOptionalcode> to the desired block .. in the configuration file.
 
After registering, be sure to run the command:

Leave a Reply