Instructions on how to install LAMP on Centos 7 - HOSTVN Blog

In this article, HOSTVN will guide you in detail how to install LAMP on Centos 7 - Linux Apache, MariaDB, PHP-FPM, PhpMyAdmin.

Instructions on how to install LAMP on Centos 7

What is LAMP?

LAMP is the abbreviation commonly used to indicate the use of software Linux, Apache, MySQL / MariaDB and PHP / PHP-FPM to create a Web server environment to help deploy websites on the Internet environment.

Install LAMP on Centos 7

If you do not know how to connect VPS via SSH, you can see the instructions below

(embed) https://www.youtube.com/watch?v=vehg7pWWm3s (/ embed)

Step 1: Install Apache and configure it basically

1. Turn off Selinux

To turn off Selinux you run the following command

2. Install Apache

To install Apache on centOS, run the following commands

If you use Firewalld then you will need to open the port to be able to access the website

3. Basic Apache configuration

For the convenience of editing files, you can connect to VPS via SFTP according to the following instructions

(embed) https://www.youtube.com/watch?v=Im8c0jaEMu0 (/ embed)

To configure Apache, open the file /etc/httpd/conf/httpd.conf

Screenshot_104

Here are the parameters to fix

#ServerName www.example.com:80
DirectoryIndex index.html

Please correct it as follows

ServerName www.example.com: 80
DirectoryIndex index.html index.htm index.php

Instead www.example.com by any domain name. Next you add 2 rules below the line Listen 80

ServerTokens Prod
KeepAlive On
ServerSignature Off

Screenshot_105

3. Turn on Userdir

By default, the directory containing the code will be in / var / www / html, with function of userdir allows to move the directory containing the code to another location and easily manage vhost for each user.

To turn on Userdir, open the file /etc/httpd/conf.d/userdir.conf. Here you need to fix the following rules

UserDir disabled
#UserDir public_html

Revised as follows

#UserDir disabled
UserDir public_html

Screenshot_106

Next you find the following rule

Fix it as follows

Screenshot_112
4. Block access to IP VPS automatically redirects to website on VPS

By default, when accessing the IP of VPS or when pointing a domain name to VPS but this domain is not configured for vhost, you will be redirected to any website on VPS, this is not recommended and to restrict hey guys, open the file /etc/httpd/conf/httpd.conf and add above the line IncludeOptional conf.d / *. Conf The following rules:

www.example.com configuration same ServerName in the file httpd.conf

Screenshot_113

4. Create a virtual host (vhost) for the website

Virtual Host is a configuration file in Apache that allows multiple domains to run on the same server. There is another concept mentioned in Nginx that has the same function as the Virtual Host called Server Block.

All vhost files will be in the directory /etc/httpd/conf.d/. For convenience, each website should have a separate vhost, for example: hostvn.net.conf

In this example, the website will be created hostvn.net with the corresponding vhost is /etc/httpd/conf.d/hostvn.net.conf with the following content:

Screenshot_107

Next, you need to create the directory containing the website source code and the directory containing the log file with the following commands

5. Start Apache

Next you need to proceed to start Apache by running the following 2 commands

6. Check

After configuration is complete you point the domain to vps and then create the file /home/hostvn.net/public_html/index.html With the following content and type your domain name in the address bar of the browser to check

Screenshot_109

Step 2: Install MariaDB

MariaDB is an open source product separated from the open source by the developer community of the relational database management system MySQL in the direction of not having to pay fees with the GNU GPL. MariaDB was developed with the lead of the original developers of MySQL, due to concerns over MySQL being acquired by Oracle Corporation.

MariaDB oriented to maintain high compatibility with MySQL, to ensure library support and to best integrate with MySQL APIs and commands.

In this tutorial HOSTVN will guide you to install MariaDB instead of Mysql. By default, CentOS repo is only available for MariaDB 5. To install MariaDB 10 you need to create your own repo.

1. Create a MariaDB 10 installation repo

You create the file /etc/yum.repos.d/mariadb.repo with the following content

2. Install MariaDB

To install MariaDB, run the following command

3. Set the root password

After installing MariaDB you proceed to set the root password by running the following 2 commands

Enter current password for root (enter for none): Hit the Enter key
Switch to unix_socket authentication (Y / n): n
Change the root password? (Y / n): Y
New password: Enter the root password you want to create
Re-enter new password: Retype the root password
Remove anonymous users? (Y / n): Y
Disallow root login hack? (Y / n): Y
Remove test database and access to it? (Y / n): Y
Reload privilege tables now? (Y / n): Y

Step 3: Install PHP-FPM and the necessary Modules

1. Install PHP-FPM

To install PHP-FPM you run the following commands

2. Basic php configuration

All necessary php configuration will be in the file /etc/php.ini. Some basic parameters you can edit as follows

; date.timezone =
expose_php = On
short_open_tag = Off
; max_input_vars = 1000
disable_functions =

You revise it as follows:

date.timezone = "Asia / Ho_Chi_Minh"
expose_php = Off
short_open_tag = On
max_input_vars = 3000
disable_functions = exec, system, passthru, shell_exec, proc_close, proc_open, dl, popen, show_source, posix_kill, posix_mkfifo, posix_getpwuid, posix_setpgid, posix_setsid, posix_setuid, posix_setgid, posix_sete_ixu

3. Configuration of running PHP-FPM

You open the file /etc/httpd/conf.d/php.conf Find the line SetHandler application / x-httpd-php edited into SetHandler "proxy: fcgi: //127.0.0.1: 9000"

Screenshot_110 - install LAMP on CentOS 7

Next restart apache to reload config

4. Start PHP-FPM

After completing the configuration, you run the following 2 commands to start PHP-FPM

5. Check

To check if PHP-FPM is working, create the file /home/hostvn.net/public_html/info.php with the following content

Next access the file info.php on the browser to check

Screenshot_111 - install LAMP on CentOS 7

Step 4: Install PhpMyAdmin

phpMyAdmin is a free and open source tool written in PHP for administering MySQL through a web browser. It can perform many tasks such as creating, modifying or deleting databases, tables, fields or records; execute SQL statements; or manage users and grant database access.

1. Install PhpMyAdmin

To install PhpMyAdmin, run the following commands one after the other

  • Note: Access phpmyadmin.net To get the link down to the latest version
2. Configure PhpMyAdmin

The configuration file of PhpMyadmin is the file config.inc.php. First you need to run the following command

Next open the file /usr/share/phpMyAdmin/config.inc.php and edit the following parameters

  • Find $ cfg (‘blowfish_secret’) = ”; Add any paragraph of characters between the single quotes. For example: $ cfg (‘blowfish_secret’) = ‘dsa123e12rwDSADs1few12tr3ewg3s2df3sAD’;
  • Add to the end of the file: $ cfg (‘TempDir’) = ‘/ usr / share / phpMyAdmin / tmp / ';

Next you need to create folders tmp for PhpMyAdmin

3. Configure vhost for PhpMyAdmin

To be able to access PhpMyAdmin you will need at vhost for it. Create the file /etc/httpd/conf.d/phpmyadmin.conf with the following content

Restart apache to load the configuration

4. Check

Next you access ip-vps / pma or domain-name / pma To test

Screenshot_114 - install LAMP on CentOS 7

References

Conclude

Through this article HOSTVN I showed you how to install LAMP on CentOS 7. If you have any comments, you can leave a comment below. Also see the CSF Firewall Installation Guide on CentOS 7.