网站首页 > 技术 正文

centos8安装nginx+php+mysql

唐哲 2020-11-23 20:30:46 技术 14169 ℃ 2 评论

    先修改ssh端口号。

    vi /etc/ssh/sshd_config

    添加:Port 2666

    image.png

    这样,保存后重启,下次就要用2666端口登录了。

    

安装nginx

    这是nginx网站上的安装说明:

    http://nginx.org/en/linux_packages.html#RHEL-CentOS

    按上面网页中的命令执行就可以了。

    下图红框中是打开开发版,建议不要执行,我觉得使用稳定版比较好。

    image.png

    image.png

    systemctl enable nginx  #设置nginx为开机启动

    systemctl start nginx  #启动nginx服务

    重启:nginx -s reload

    嫌上面的麻烦,直接一句:yum install nginx,就好了。


安装php

    命令:yum install php php-opcache php-gd php-curl php-mysqlnd

    设置自动启动:systemctl enable --now php-fpm

    修改用户名:

    vi /etc/php-fpm.d/www.conf

        user = nginx
        group = nginx

    确保/var/lib/php目录具有正确的所有权:

    chown -R root:nginx /var/lib/php

    完成后,重新启动PHP FPM服务:

    systemctl restart php-fpm

    接下来,编辑Nginx虚拟主机指令,并添加以下位置块,以便Nginx可以处理PHP文件:

    server {

        # . . . other code

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

    编辑php的www.conf文件:

    vi /etc/php-fpm.d/www.conf   

    image.png

    为了使新配置生效,请重新启动Nginx服务:

    sudo systemctl restart nginx


安装mysql

    命令:yum install mariadb-server

    systemctl start mariadb #启动服务
    systemctl enable mariadb #设置开机启动
    systemctl restart mariadb #重新启动
    systemctl status mariadb #查看下状态
    systemctl stop mariadb.service #停止MariaDB

    mysql数据库安全配置

    命令:mysql_secure_installation

    会问一些问题:

        Enter current password for root (enter for none):
            (直接enter,預設MariaDB沒有密碼)
        Switch to unix_socket authentication [Y/n]
            (n,切換到unix_socket身份驗證)
        Change the root password? [Y/n]
            (Y,設定ROOT密碼)
        Remove anonymous users? [Y/n]
            (Y,移除匿名登入)
        Disallow root login remotely? [Y/n]
            (Y,移除遠端root登入權限)
        Remove test database and access to it? [Y/n]
            (Y,移除測試資料庫及帳號)
        Reload privilege tables now? [Y/n]
            (Y,重新載入權限表)



本文TAG:

已有2位网友发表了看法

  • 招投标

    招投标  评论于 [2021-01-30 18:01:22]  回复

    博客很棒 欢迎回访我哦

欢迎 发表评论:

请填写验证码
«    2024年2月    »
1234
567891011
12131415161718
19202122232425
26272829
搜索
网站分类
站点信息
  • 文章总数:89
  • 页面总数:1
  • 分类总数:4
  • 标签总数:19
  • 评论总数:96
  • 浏览总数:604706
控制面板
您好,欢迎到访网站!
  查看权限
唐哲 - 和仲科技