lnmp+workpress 搭建记录

nginx 安装

  1. 安装依赖和编译工具

    1
    2
    3
    4
    yum -y install gcc gcc-c++ autoconf automake make # c编译器
    yum install -y pcre pcre-devel # 解析正则的pcre库
    yum install -y zlib zlib-devel # 添加对gzip的支持
    yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel # S
  2. 解压nginx

    1
    tar -zxf nginx-1.25.3.tar.gz
  3. 编译nginx

    1
    2
    ./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
    make && make install
  4. 添加防火墙端口

    1
        firewall-cmd --add-port=80/tcp --permanentfirewall-cmd --reload
  5. 配置 /opt/nginx/conf/nginx.conf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #第35行开始
    server {
    listen 80;
    server_name localhost;
    root /opt/wordpress/;
    error_page 500 502 503 504 /50x.html;
    client_max_body_size 20M;
    location test/ {
    rewrite ^test(.*)$ wp-admin$1 last;
    }
    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root /opt/wordpress/;
    index index.php index.html index.htm;
    }

    #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 html;
    }
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
    location ~ .php$ {
    root /opt/wordpress/;
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass 127.0.0.1:9001; # 配置一个php不需要这一行
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
  6. 检查和重载配置

    1
    2
    /opt/nginx/sbin/nginx -t     #检查配置
    /opt/nginx/sbin/nginx -s reload #重载配置

mysql安装

  1. 添加mysql的rpm源

    1
    rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
  2. 安装

    1
    2
    rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022  #mysql密钥更新,需要先更新密钥
    yum -y install mysql-community-server –nogpgcheck
  3. 启动mysql并设置为开机自启

    1
    2
    systemctl start mysqld
    systemctl enable mysqld
  4. 查看mysql默认密钥

    1
    cat /var/log/mysqld.log | grep password
  5. 初始化mysql

    1
    mysql_secure_installation
  6. 创建数据库

    1
    2
    3
    4
    create database wordpress;
    create user admin@"%" identified by "Abc123.";
    grant all privileges on wordpress.* to admin@"%" identified by "Abc123.";
    flush privileges;

PHP安装

  1. 安装PHP依赖

    1
    yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel sqlite-devel oniguruma-devel
  2. 下载PHP

    1
    wget https://www.php.net/distributions/php-7.3.28.tar.gz
  3. 解压编译

    1
    2
    3
    4
    5
    tar -zxf php-7.3.28.tar.gz
    cd php-7.3.28
    ./configure -prefix=/opt/php -with-zlib-dir -enable-mbstring -enable-soap -enable-calendar -with-curl -disable-rpath -enable-inline-optimization -with-bz2 -with-zlib -enable-sockets -enable-sysvsem -enable-sysvshm -enable-pcntl -enable-mbregex -enable-exif -enable-bcmath -with-mhash -with-pdo-mysql -with-mysqli -with-openssl -with-fpm-user=nobody -with-fpm-group=nobody -enable-ftp -with-gettext -with-xmlrpc -with-xsl -enable-opcache -enable-fpm -with-iconv
    make all install
    make test #检查编译
  4. 配置PHP

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf
    cp /opt/php/etc/php-fpm.d/www.conf.default /opt/php/etc/php-fpm.d/www.conf
    #修改www.conf文件
    user = nginx
    group = nginx
    #创建nginx用户
    useradd nginx -s /usr/sbin/nologin
    #复制源码包php.inie文件
    cp php-7.3.28/php.ini-development /opt/php/lib/php.ini
    #修改最大上传文件为20M
    vim /opt/php/lib/php.ini
    upload_max_filesize = 20M
  5. 启动PHP

    1
    2
    /opt/php/sbin/php-fpm
    ps -ef | grep php-fpm #查看服务状态

WordPress

  1. 解压至nginx配置目录

    1
    tar -zxf wordpress -C /opt
  2. 在浏览器输入IP进行配置

  3. 在wp-config.php添加配置

    1
    2
    3
    4
    5
    vim /opt/wordpress/wp-config.php
    define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp');
    define("FS_METHOD", "direct");
    define("FS_CHMOD_DIR", 0777);
    define("FS_CHMOD_FILE", 0777);xxxxxxxxxx tar -zxf wordpress -C /optvim /opt/wordpress/wp-config.phpdefine('WP_TEMP_DIR', ABSPATH.'wp-content/tmp'); define("FS_METHOD", "direct"); define("FS_CHMOD_DIR", 0777); define("FS_CHMOD_FILE", 0777);