zoukankan      html  css  js  c++  java
  • linux centos8 搭建LNMP平台(linux+nginx+mysql+php)

    LNMP环境和软件版本
    名称 版本号 查询命令
    linux系统 CentOS Linux release 8.2.2004 (Core) cat /etc/redhat-release
    Nginx nginx-1.14.1-9.module_el8.0.0+184+e34fea82.x86_64 rpm -qa | grep nginx
    mariadb mariadb-server-10.3.17-1.module_el8.1.0+257+48736ea6.x86_64 rpm -qa | grep mariadb
    php php-7.2.24-1.module_el8.2.0+313+b04d0a66.x86_64 rpm -qa | grep php
    一、安装Nginx
    1、查看是否安装过nginx。

    rpm -qa | grep nginx

    2、有就卸载nginx。

    yum remove -y "nginx*"

    3、重新安装nginx。

    yum install -y nginx

    4、查看启动状态。

    systemctl status nginx

    5、启动nginx。

    systemctl start nginx

    6、添加开机启动。

    systemctl enable nginx

    7、设置防火墙开放tcp80端口。

    firewall-cmd --zone=public --add-port=80/tcp --permanent
    firewall-cmd --reload
    firewall-cmd --query-port=80/tcp

    8、使用浏览器访问http://192.168.16.144/,显示如下界面,说明安装的nginx服务正常运行。

    9、由上图内容可知,默认主页index.html位于默认目录/usr/share/nginx/html中。若要发布自己的网站内容,替换index.html主页内容即可。例:主页内写入内容 “This is a Nginx test.” 。使用浏览器访问http://192.168.16.144,则显示如下界面内容。若要更换主页目录位置,需在nginx配置文件/etc/nginx/nginx.conf中设置目录路径。
    echo "This is a Nginx test." > /usr/share/nginx/html/index.html

    二、安装mysql数据库
    1、查看是否安装过mariadb。

    rpm -qa | grep mariadb

    2、有就卸载mariadb。

    yum remove -y "mariadb*"

    3、重新安装mariadb-server。

    yum install -y mariadb-server

    4、启动mariadb。

    systemctl start mariadb

    5、查看启动状态。

    systemctl status mariadb

    6、添加开机启动。

    systemctl enable mariadb

    7、设置mysql数据库root账号密码。

    mysqladmin -uroot password 'yourpassword'

    mysql_secure_installation

    8、root账号登陆mysql。

    mysql -uroot -p

    9、登陆mysql后可以使用如下命令重新设置当前账户数据库密码。

    MariaDB[(none)]> set password=password('123456');

    10、创建一个新用户mysql,密码为123456,授权远程计算机使用账号mysql登陆数据库,并立刻刷新权限。

    MariaDB[(none)]>grant all on . to 'mysql'@'%' identified by '123456';
    MariaDB[(none)]>flush privileges;

    上述语句表示使用"mysql"账户,"123456“”密码从任何主机连接到mysql服务器,并赋予所有的权限。

    11、退出mysql数据库。

    MariaDB[(none)]> quit;

    MariaDB[(none)]> exit;

    12、设置防火墙开放tcp3306端口。

    firewall-cmd --zone=public --add-port=3306/tcp --permanent
    firewall-cmd --reload
    firewall-cmd --query-port=3306/tcp

    13、远程计算机连接服务器数据库时使用如下命令,输入密码即可登录mysql数据库。

    mysql -umysql -p -h 192.168.16.144 -P 3306

    三、安装PHP
    1、查看是否安装过php。

    rpm -qa | grep php

    2、有就卸载php。

    yum remove -y "php*"

    3、重新安装php。

    yum install -y php

    4、创建文件/usr/share/nginx/html/index.php,写入内容 “”。

    touch /usr/share/nginx/html/index.php
    echo "" > /usr/share/nginx/html/index.php

    5、重启nginx服务,使用浏览器访问http://192.168.16.144,如果显示如下,则说明php安装成功。

    systemctl restart nginx

  • 相关阅读:
    Autodesk Infrastructure Map Server(AIMS)/MapGuide API 培训材料第6章
    安装Vault Professional Server的一些问题
    Autodesk Infrastructure Map Server(AIMS)/MapGuide API 培训材料第2章
    C++的构造函数和析构函数
    一些常用的字符串hash函数
    类的operator new与operator delete的重载
    计算字符串的相似度(编辑距离)
    C++的重载(overload)与重写(override)
    穷举法解24点游戏
    C语言字符串库函数的实现
  • 原文地址:https://www.cnblogs.com/huangdashu/p/13914724.html
Copyright © 2011-2022 走看看