ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2021-10-17 11:02:26  阅读:211  来源: 互联网

标签:单台 LNMP nginx yum php71w 服务器 php root handsome


LNMP架构

单台节点部署

环境准备:

  • nginx
  • mysql
  • php

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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有