LNMP website framework construction (yum method)

Table of contents

1. Nginx yum installation

1) Build nginx-related yum source

2) Refresh the yum warehouse, install and start the nginx service 

Two, mysql yum installation 

1) Uninstall all packages related to mysql

2) wget mysql related yum source

Additional: the second method (you can choose one of the above)

3. Start the mysql service and do some preliminary settings

View the initial password of the database installed by yum:

 Database password modification

4) Stop the version update and stabilize the operation of the database 

3. Yum installation of php

1) Obtain the relevant yum source of php

2) Install related dependent extension modules  

3) nginx supports PHP parsing

Four, lnmp connection test

1) Connection test between nginx and php 

2) lnmp connection test

Test Results: 


1. Nginx yum installation

1) Build nginx-related yum source

Note: The software packages obtained in this installation are all from the httpd source (provided by the software package manufacturer). So remember not to use local sources directly to install all packages as usual 

vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

2) Refresh the yum warehouse, install and start the nginx service 

yum clean all && yum makecache
yum install nginx -y 
nginx -v
 
systemctl start nginx
systemctl enable nginx

Two, mysql yum installation 

1) Uninstall all packages related to mysql

—— Prepare the environment for the package of the new mysql version, so as to prevent the old version from interfering with the implantation of the new version

yum remove mariadb* -y

2) wget mysql related yum source

Note: wget will place the downloaded file in the current directory by default 

cd /opt  
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
(注意:当这一步执行完成以后,会在/etc/yum.repos.d中
生成mysql-community.repo 和mysql-community-source.repo )
 
yum -y install mysql-community-server

cd /etc/yum.repos.d
sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo
yum -y install mysql-community-server

Additional: the second method (you can choose one of the above)

wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
cd /etc/yum.repos.d
sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo
yum -y install mysql-server

3. Start the mysql service and do some preliminary settings

systemctl start mysqld.service
systemctl enable mysqld.service
systemctl status mysqld.service

View the initial password of the database installed by yum:

grep "password" /var/log/mysqld.log			#在日志文件中找出root用户的初始密码
 
 
grep "password" /var/log/mysqld.log | awk '{print $NF}'

 Database password modification

mysql  -u root -p

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';     #密码设置要求有 大小写字母、数字和符号 组合
 
grant all privileges on *.* to root@"%" identified by "Admin@123" with grant option; #允许所有通过数据库密码访问的主机
flush privileges; #刷新数据库

4) Stop the version update and stabilize the operation of the database 

yum -y remove mysql57-community-release-el7-10.noarch     #为了防止每次yum操作都会自动更新,卸载这个软件

3. Yum installation of php

1) Obtain the relevant yum source of php

Note: Download to keep the network smooth

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2) Install related dependent extension modules  

yum -y install php72w \
php72w-cli\
 php72w-common\
 php72w-devel\
 php72w-embedded\
 php72w-gd\
 php72w-mbstring\
 php72w-pdo\
 php72w-xml\
 php72w-fpm\
 php72w-mysqlnd\
 php72w-opcache \
 php72w-redis

systemctl start php-fpm
systemctl enable php-fpm
php -v

3) nginx supports PHP parsing

cd /etc/nginx/conf.d
//给default.conf 做一个备份,防止配置修改错误,无法还原
cp default.conf   default.conf.bak

Modify the default configuration of php:

vim /etc/nginx/conf.d/default.conf
......
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;  #将 /scripts 修改为nginx的工作目录
        include        fastcgi_params;
    }

After saving the configuration and restarting the service:

systemctl restart nginx

Four, lnmp connection test

1) Connection test between nginx and php 

Create a php page test for access testing

cd /usr/share/nginx/html
vim index.php
<?php
phpinfo();
?>

Test Results:

2) lnmp connection test

vim /usr/share/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.80.10','root','Admin@123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>

Test Results: 

Note that firewalld and selinux must be turned off before testing the mysql connection (these two are the source of all evil for testing) 

おすすめ

転載: blog.csdn.net/qq_21003381/article/details/130988011