其他分享
首页 > 其他分享> > 单台服务器部署LNMP架构测试

单台服务器部署LNMP架构测试

作者:互联网

LNMP架构

单台节点部署

环境准备:

1.nginx环境准备

1.配置nginx源
[root@handsome ~]# cat /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

2.安装nginx(方便操作这里我们直接用yum安装)
[root@handsome ~]# yum install -y nginx

3. nginx配置文件,采用了80跳转443
[root@handsome ~]# cat /etc/nginx/conf.d/wordpress.conf 
server {
    listen 443;
    server_name hugelnb.cn;
    ssl on;
    root /code/huge/wordpress; 
#    index index.html index.htm; 上面配置的文件夹里面的index.html
    ssl_certificate  ssl_key/1_hugelnb.cn_bundle.crt; #改成你的证书的名字
    ssl_certificate_key ssl_key/2_hugelnb.cn.key; # 你的证书的名字
    access_log /var/log/nginx/blog_access.log main;
    error_log /var/log/nginx/blog_error.log notice;
    location / {
      index index.html index.php index.htm;
    }
    location ~ \.php$ {
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include /etc/nginx/fastcgi_params;
   }
}
server {
    listen 80;
    server_name hugelnb.cn;
    rewrite ^(.*)$ https://$host$1 permanent; #把http的域名请求转成https
}

4.创建存放ssl证书的目录,将申请的证书上传到这里
[root@handsome ~]# mkdir -p /etc/nginx/ssl_key

5.上传指定服务到指定的目录,我这里上传是时wordpress
[root@handsome ~]# mkdir -p /code/huge

6.授权目录文件nginx权限
[root@handsome ~]# chown -R nginx.nginx /code/huge

2.安装php

这里用的是我之前缓存的rpm包
进入存放php,rpm包的目录,直接本地安装即可
[root@handsome ~]# yum localinstall -y *

配置yum源可直接yum安装
[root@handsome ~]# cat /etc/yum.repos.d/php.repo
[webtatic-php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0
 yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
 
[root@handsome ~]# systemctl start php-fpm
[root@handsome ~]# systemctl enable  php-fpm
修改pfp的配置文件,用户和nginx同步

[root@handsome ~]# vim /etc/php-fpm.d/www.conf 
[root@handsome ~]# egrep -n '^user|^group' /etc/php-fpm.d/www.conf
8:user = nginx
10:group = nginx
修改服务记得重启
[root@handsome ~]# systemctl reload php-fpm.service 
[root@handsome ~]# ps -ef |grep php-fpm

3.安装数据库(为了方便我们直接yum安装)

[root@handsome ~]#

#安装 运行MySQL
[root@handsome ~]# yum install mariadb-server -y
[root@handsome ~]# systemctl start mariadb.service
[root@handsome ~]# systemctl enable  mariadb.service
[root@handsome ~]# ps -ef |grep mysql   看进程
[root@handsome ~]# ss -lntup|grep mysql  看端口 3306

进MySQL
[root@handsome ~]# mysql 
[root@handsome ~]# mysqladmin -u root password "123456"   设置密码

[root@handsome ~]# mysql -u root -p 123456     进入MySQL

##查看所有数据库
show databases;
##查看所有表;
show tables from mysql ;  #绝对路径
use mysql    #cd   
show tables ;  #ll 
##查看表中数据
select user,host from mysql.user;   #cat /etc/passwd 查
看当前数据库用户信息.
select 字段(列)   from 数据库.表

#根据产品 创建数据库
create database wordpress;

#drop database wordpress;
MariaDB [(none)]> show databases;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql             |
| performance_schema |
| test               |
| wordpress         |
+--------------------+ 5 rows in set (0.00 sec)

检查是否可用

#nginx + php 
[root@handsome ~]# cat /code/blog/info.php
<?php
phpinfo();
?>
浏览器访问hugelnb.cn/info.php

检测php+数据库

cat /code/huge/mysqli.php
[root@handsome ~]#vim  /code/blog/mysqli.php
[root@handsome ~]# cat  /code/blog/mysqli.php
<?php
//$link_id=mysqli_connect('主机名','用户','密码');
 
 $link_id=mysqli_connect('localhost','root','123456') or mysqli_error();
//$link_id=mysqli_connect('localhost','test','');
 if($link_id){
 echo "mysql successful by oldboy !";
 } else{
 echo mysqli_error();
 }
?>

标签:单台,LNMP,nginx,yum,php71w,服务器,php,root,handsome
来源: https://www.cnblogs.com/andy996/p/15416334.html