Centos7 configuring LNMP server environment

Time:2021-11-25

Modify the yum source to the domestic Yum source(Original:https://www.cnblogs.com/xjh713/p/7458437.h…

  1. Backup local Yum source
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
    2. Get Alibaba Yum source configuration file
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.re…
    3. Update cache
    yum makecache
    4. View
    yum -y update

Installing nginx(Original:https://blog.csdn.net/qq_26245325/article/…
Because the resource versions of CentOS default Yum source are relatively old, as a person pursuing a new version. Of course, the default old version will not be installed. Therefore, the nginx installation source should be set before installation.
You can view the latest version information on nginx official website:

Mainline version: mainline is the main version of nginx, which can be said to be the development version
Stable version: the latest stable version, which is recommended for the production environment
Legacy versions: the stable version of the legacy old version
1. Install the EPEL release source
yum install -y epel-release
2. Set nginx installation source
vim /etc/yum.repos.d/nginx.repo
Add the following code:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1

3. Install nginx and set auto start
yum install -y nginx
systemctl enable nginx
4. View version information and start
nginx -v
systemctl start nginx

Install PHP 7.2(Original:https://newsn.net/say/centos-php72-yum.htm…
Like nginx, the default PHP version of CentOS’s Yum source is 5.0。 Obviously not enough. All here choose to install php7.2.
The yum source address of PHP higher version has two parts, one is EPEL release, and the other is from webtatic.
1. Because EPEL release is installed when nginx is installed, all you need to do here is:
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtat…
2. Clear the original PHP (if any)
yum -y remove php

3. Install PHP and extensions
yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
4. Start PHP FPM service
systemctl enable php-fpm.service
systemctl start php-fpm.service
5. Finally, you can check the PHP version
php -v
6. PHP extensions are as follows. You can continue to install according to your personal needs
php72w-cli
php72w-common
php72w-devel
php72w-embedded
php72w-fpm
php72w-gd
php72w-mbstring
php72w-mysqlnd
php72w-opcache
php72w-pdo
php72w-xml
php72w
php72w-bcmath
php72w-dba
php72w-enchant
php72w-imap
php72w-interbase
php72w-intl
php72w-ldap
php72w-mcrypt
php72w-odbc
php72w-pdo_dblib
php72w-pear
php72w-pecl-apcu
php72w-pecl-imagick
php72w-pecl-xdebug
php72w-pgsql
php72w-phpdbg
php72w-process
php72w-pspell
php72w-recode
php72w-snmp
php72w-soap
php72w-tidy
php72w-xmlrpc
php72w-pecl-igbinary
php72w-intl
php72w-memcached
php72w-pecl-mongodb

Install MySQL 5.7(Original:https://www.cnblogs.com/bigbrotherer/p/724…
Download and install the official Yum repository for MySQL
wget -i -c http://dev.mysql.com/get/mysql57-community…
yum -y install mysql57-community-release-el7-10.noarch.rpm
Install and start MySQL
yum -y install mysql-community-server
systemctl start mysqld.service
Find mysql5.7 default password
grep “password” /var/log/mysqld.log
Centos7 configuring LNMP server environment
Enter database
mysql -uroot -p
The password rule conflict is found when modifying the password. Modify the password rule
set global validate_password_policy=0;
set global validate_ password_ length=1; (the default minimum length is 4)
Finally, change the password
set password for [email protected] = password(‘123456’);
Uninstall the corresponding Yum repository
yum -y remove mysql57-community-release-el7-10.noarch

So far, the LNMP server environment of centos7 has been built. Next, prepare to do a simple access operation to verify that the server environment is OK.
First, the nginx directory is soft connected to the / var / www directory https://www.cnblogs.com/kex1n/p/5193826.html )
ln -s /etc/nginx /var/www/nginx
Configure the defalut.conf file in the conf.d directory under the nginx directory

vim /var/www/nginx/conf.d/default.conf
server {
listen       80;
server_ name  www.hyd1010.top;                                      // Modify the domain name to listen to. The default is localhost
#charset koi8-r;
#access_log  /var/log/nginx/host.access.log  main;
location / {
    root   /var/www/html;                                                       // Modify to access path
    index  index.html index.htm;
    try_ files $uri $uri//index.php?$ query_ string;                       // Add the following code
}
#error_page  404              /404.html;
# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /var/www/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass   http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
Location ~ \. PHP ${// unlock the following comments
    root           /var/www/html;                                                          // Modify path
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_ param  SCRIPT_ FILENAME  $document_ root$fastcgi_ script_ name;          // modify
    include        fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}

}

Because my file directory here is to visit / var / www / HTML / index.php. So make the following changes. If you don’t want to change the path: create an index.php file under the default path

The following code should be added to the location:
try_files $uri $uri/ /index.php?$query_string;

Open the comment of location ~. PHP $and modify its fastcgi_ Param is the following value:
SCRIPT_FILENAME $document_root$fastcgi_script_name;

The contents of the index.php file are as follows:
<?php phpinfo(); ?>

Finally, visit your server’s external IP (if there is no domain name) or your domain name + / index.php. The PHP version information page shows that it is successful

This work adoptsCC agreement, reprint must indicate the author and the link to this article

Recommended Today

Apache sqoop

Source: dark horse big data 1.png From the standpoint of Apache, data flow can be divided into data import and export: Import: data import. RDBMS—–>Hadoop Export: data export. Hadoop—->RDBMS 1.2 sqoop installation The prerequisite for installing sqoop is that you already have a Java and Hadoop environment. Latest stable version: 1.4.6 Download the sqoop installation […]