微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

单台服务器部署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           |
+--------------------+
| @R_525_4045@ion_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();
 }
?>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐