CentOS8 本地安装 LEMP 环境,Linux nginx Mariadb PHP on localhost

0.先更新软件源为阿里源:

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
dnf update

Wordpress 整站迁移:https://blog.csdn.net/lggirls/article/details/104304620

1. 安装 最新稳定版 nginx  当前是 1.18版

 vi /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
# 真正安装
dnf update 
dnf install nginx

2. 安装mariadb

curl -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
./mariadb_repo_setup
dnf install perl-DBI libaio libsepol lsof boost-program-options
dnf install MariaDB-server
mysql_install_db
# 启动数据库,之后才好配置root账号
systemctl start mariadb.service
systemctl enable mariadb.service
#配置root密码等
mysql_secure_installation

3. 安装最新版 php

# 增加最新稳定版的源
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

# 显示当前最新的php, 目前是8.0版
dnf module list php

# 对 要安装的php 先进行设置
dnf module reset php

# 开启8.0 版的支持
dnf module enable php:remi-8.0

#正式安装
dnf install php php-fpm php-opcache php-gd php-curl php-mysqlnd 

#查看安装的版本
php -v

启动设置三连
systemctl start nginx php-fpm
systemctl enable php-fpm
systemctl enable nginx

4. php 与nginx配合工作起来的配置

 

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

找到下列两行, 将默认的 apache 替换为 nginx
user = apache
group = apache
# 将下面第1行前面增加一个英文的分号,注销掉,添加第2行
;listen = /run/php-fpm/www.sock
listen = 127.0.0.1:9000;

# 重启php和nginx
systemctl restart php-fpm nginx

5. 测试运行良好与否

vi /usr/share/nginx/html/info.php
内容:

<?php
 phpinfo();
?>


在浏览器输入 http://server-ip-address/info.php

一般是打不开的,需要对mginx的配置文件进行修改
vi /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index index.php index.html index.htm; #增加index.php
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    # 用下面这个 location所包含的内容进行替换即可, 主要是 root行;127.0.0.1行;SCRIPT 行的修改
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_param PATH_INFO                $fastcgi_script_name;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

6. 安装phpMyAdmin  ,图形化的mysql 管理工具

http://server-ip-address/info.php/phpMyAdmin/

数据库的命令行操作:  https://blog.csdn.net/lggirls/article/details/106034933 

#修改phpMyAdmin的认证方式,主要是修改phpMyAdmin目录下的config.inc.php这个文件,

cd /usr/share/nginx/html/phpMyAdmin/
cp config.sample.inc.php config.inc.php
vi config.inc.php

#修改的配置项和内容:
$cfg['Servers'][$i]['auth_type'] = 'http'; (默认的配置内容为空或者cookie,这里改为http)
 $cfg['blowfish_secret'] = '123456789'; (配置文件现在需要一个短语密码的解决方法)
通过http://主机ip/phpMyAdmin 打开mysql的管理界面
注:若出现  “session_start(): open(SESSION_FILE, O_RDWR) failed: Permission de... ”  的错误提示,则需要对报错信息涉及到的文件的权限进行配置;提示少扩展,就安装对应的扩展即可
chown nginx:nginx /var/lib/php/session
mkdir /usr/share/nginx/html/phpmyadmin/tmp

chown nginx:nginx /usr/share/nginx/html/phpmyadmin/tmp

7. 修改php的上传文件大小的限制

通过打开的 info.php 页面查看 php.ini 文件的位置; 我这里是 /etc/php.ini

vi /etc/php.ini

# 最常用的几个设置及其含义:
file_uploads = on ;                        #是否允许通过HTTP上传文件;
upload_tmp_dir ;                           #文件上传至服务器时,储临时文件的位置;
upload_max_filesize = 128m ;               #允许上传的文件大小的最大值;
post_max_size = 128m ;                     #指通过表单POST给PHP的所能接收的最大值,包括表单里的所有值;
max_execution_time = 600 ;                 #每个PHP页面运行的最大时间值(秒),默认30秒
max_input_time = 600 ;                     #打开一个PHP页面,接收数据所需能占用的最大时长;
memory_limit = 128m ;                      #打开一个PHP页面所能占用的最大内存,默认8M
date.timezone = PRC                        #设置默认时区为中国,去掉前面的分号
#把上述参数修改后,在网络所允许的正常情况下,就可以上传大体积文件了
# 总结一下,好找到对应的项目
max_execution_time = 600
max_input_time = 600
memory_limit = 64m
file_uploads = on
upload_tmp_dir = /tmp
upload_max_filesize = 64m
post_max_size = 128m

上传 msql 数据库文件过大,413 Request Entity Too Large 的问题

vi /etc/nginx/nginx.conf

在http{}

中间增加一行:
client_max_body_size 128m; 
这个128要和 php.ini 中
post_max_size = 128m  
upload_max_filesize = 128m 

的数值相同

8. 解决 WordPress 中,更换固定链接,引起无法打开其他网页的情况

例如, wordpress 安装在  /usr/share/nginx/html/wordpress/  这个相对于网站根目录的 二级目录下,则需要在nginx 的配置文档“/etc/nginx/conf.d/default.conf”  中,的 增加一个 location /  下增加一句 如下:


    try_files $uri $uri/ /wordpress/index.php?$args;

 将“wordpress”更改为你自己的安装文件夹名称, 

二、  Nginx Vhost的配置:计划配置  test.com  和 ceshi.com  这两个虚拟机
1.按照网络上普遍的做法。我们也取保留了  /usr/share/nginx/htm/  作为默认网站路径
新建  /var/www/test.com/html/     /var/www/ceshi.com/html/  两个虚拟机的专用路径

mkdir   /var/www/test.com/   /var/www/test.com/html/   /var/www/ceshi.com/    /var/www/ceshi.com/html/ 

2. 两个虚拟机的具体配置文件

cp  /etc/nginx/conf.d/default.conf   /etc/nginx/conf.d/test.com.conf
vi  /etc/nginx/conf.d/test.com.conf

内容如下:

server {
    listen      192.168.1.111:80;

    server_name            test.com    www.test.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
    root   /var/www/test.com/html;
    index index.html index.htm index.php;
    #下面这句配置,涉及到rewrite权限
    try_files $uri $uri/ /index.php?$args;

     # set client body size to 64M #
       client_max_body_size 64M;
    }

      location ~ \.php$ {
         root           /var/www/test.com/html;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  /var/www/test.com/html$fastcgi_script_name;
         include        fastcgi_params;
         fastcgi_param PATH_INFO                $fastcgi_script_name;
     }

}

 虚拟机   ceshi.com 的配置文件

cp /etc/nginx/conf.d/test.com.conf  /etc/nginx/conf.d/ceshi.com.conf

将里面的 test 替换为 ceshi 即可

vi /etc/nginx/conf.d/ceshi.com.conf
内容如下:

server {
    listen      192.168.1.222:80;

    server_name            ceshi.com    www.ceshi.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
    root   /var/www/ceshi.com/html;
    index index.html index.htm index.php;
    #下面这句配置,涉及到rewrite权限
    try_files $uri $uri/ /index.php?$args;

     # set client body size to 64M #
       client_max_body_size 64M;
    }

      location ~ \.php$ {
         root           /var/www/ceshi.com/html;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  /var/www/ceshi.com/html$fastcgi_script_name;
         include        fastcgi_params;
         fastcgi_param PATH_INFO                $fastcgi_script_name;
     }

}

检查一下配置是否正确:

nginx -t

出现:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

说明一切OK

3. 重启php-fpm、nginx 并测试

vi  /var/www/test.com/html/info.php

内容:
<?php
 phpinfo();
?>

重启服务
systemctl restart php-fpm nginx

4. 如果用windows 系统,要直接在浏览器中输入 www.test.com   www.ceshi.com 能直接转到我们的192.168.111和 192.168.222 ,则需要对 host文件进行修改。该文件需要修改权限后才能修改,请自行搜索教程。

在 windows 系统的    C:\Windows\System32\drivers\etc 文件夹下 的 hosts

在host 文件最后面添加以下内容:

192.168.1.111     www.test.com
192.168.1.222     www.ceshi.com

windows 更改hosts后立即生效 ,在命令行运行:     ipconfig /flushdns

然后,建议分别用两种浏览器,输入域名, 看是否能打开 http://www.test.com/info.php  和  http://www.ceshi.com/info.php


5. 一切正常的话,就可以愉快的 安装 Wordress、 Drupal  等建站软件了。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值