ข่าว:

บางหมวดหมู่ทำไว้สำหรับสมาชิกบอร์ด AMSS++&SMSS&PMSS&RMSS โดยเฉพาะนะครับ ทั่วไปไม่เห็น ดังนั้นสมัครเป็นสมาชิกบอร์ดไว้ครับ

Main Menu

How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack On CentOS 7/RHEL 7

เริ่มโดย ไท อุบล, 31 กรกฎาคม 2017, :20:08:27 หลังเที่ยง

หัวข้อก่อนหน้า - หัวข้อถัดไป

ไท อุบล

How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack On CentOS 7/RHEL 7

LEMP is a combination of operating system and open-source software stack. The acronym LEMP is derived from first letters of Linux, engine-x (Nginx) HTTP Server,MariaDB database, and PHP/Perl/Python.

In this tutorial, we are going to cover how to install LEMP server on Redhat/CentOS 7.

here: here:


Step 1. Install MariaDB

– Install MariaDB:

# sudo yum install mariadb mariadb-server

– Start / Enable MariaDB:

# sudo systemctl start mariadb
# sudo systemctl enable mariadb

– Secure MySQL:

– To make the MariaDB secure by using the mysql_secure_installation command u can take a look to this tutorial: Securing MySQL server / Mariadb with mysql_secure_installation
Step 2. Install Nginx

– Nginx will not be found in the official CentOS repository, so we need to install the EPEL Repository first.

# sudo yum install epel-release

– Now, install Nginx with following command:

# sudo yum install nginx -y

– Enable / Start Nginx:

# sudo systemctl enable nginx
# sudo systemctl start nginx

– If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

# sudo firewall-cmd --permanent --add-service=http # Allow HTTP Traffic
# sudo firewall-cmd --permanent --add-service=https # Allow HTTPS Traffic
# sudo firewall-cmd --reload # Reload firewalld configuration

Step 3. Install PHP and PHP-FPM

– Below is the command to install PHP with php-fpm and common modules.

# yum install php-fpm php-mysql php-cli php

– Start / Enable PHP-FPM:

# sudo systemctl enable php-fpm
# sudo systemctl start php-fpm

Step 4. Configuring Nginx to work with PHP-FPM

-1 Editing php.ini File:

– Open the php.ini file and find the cgi.fix_pathinfo directive, uncomment it by removing the ; and set it to 0:

# sudo vi /etc/php.ini

cgi.fix_pathinfo=0

-2 Editing www.conf file:

# sudo vi /etc/php-fpm.d/www.conf

– Find the listen directive (it should be the first), and verify that it is set to listen for PHP traffic using a Unix socket (instead of port 9000):

listen = /run/php-fpm/php-fpm.sock

– Find the listen.owner and listen.group directives, uncomment them, and modify them as follows:

listen.owner = nginx
listen.group = nginx

– Find the Unix user/group of processes section, and change the user and group from apache to nginx:

user = nginx
group = nginx

– Save and close the file:

3- Restart PHP-FPM:

# sudo systemctl restart php-fpm

4- Create a new Nginx configuration file:

# sudo vi /etc/nginx/conf.d/default.conf

– Paste the following code into this file:

server {
    listen    80;
    server_name  your_server_ip;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

– Save and close the file:

– Restart Nginx:

# sudo systemctl restart nginx

Step 5. Verify and Test PHP

– Create an info.php file to ensure PHP is running:

# sudo vi /usr/share/nginx/html/info.php

– Paste the following content:

<?php phpinfo(); ?>


– Open in the web browser:

http://your server's IP address/info.php


We hope this tutorial was enough Helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!
วันนี้คุณยิ้มให้ใครหรือยัง