我的博客

centos 7 搭建 WordPress(nginx、php-fpm、mariaDB)

目录
  1. 安装 Nginx
  2. 安装 mariaDB
  3. 安装 php
    1. 方法一
    2. 方法二
    3. 方法三(编译安装)
  • 测试 PHP 环境是否安装成功
  • 错误解决
  • 其他
  • 参考资料
  • 安装 Nginx

    教程

    开启 nginx ipv6 监听

    vi /usr/local/nginx/conf/nginx.conf

    在 server {} 里加一句

    listen [::]:80 ipv6only=on;

    安装 mariaDB

    yum install mariadb-server

    启动和自启动

    1
    2
    systemctl start mariadb  # 开启服务
    systemctl enable mariadb # 设置为开机自启动服务

    初始配置

    mysql_secure_installation

    创建表和用户

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    mysql -p
    Enter password:
    Welcome to the MariaDB monitor. Commands end with ; or \g.
    Your MariaDB connection id is 11
    Server version: 5.5.64-MariaDB MariaDB Server

    Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

    MariaDB [(none)]> CREATE DATABASE `wordpress` CHARACTER SET utf8 COLLATE utf8_general_ci;

    安装 php

    方法一

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 安装EPEL yum存储库
    yum install epel-release -y
    # 安装Remi存储库
    rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
    # 安装 PHP 7.3
    yum --enablerepo=remi-php73 install php
    yum -y remove php*
    yum list php* | grep 73
    yum install php73 php73-cli php73-fpm php73-common php73-devel

    以上安装 php 参考 Centos7安装PHP7.2

    方法二

    1
    2
    3
    rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    yum install php73-php php73-php-fpm php73-php-cli php73-php-common php73-php-devel php73-php-mysqlnd
    1
    systemctl enable php-fpm

    以上安装 php 参考 Centos7安装PHP7.2

    方法三(编译安装)

    1. 这里找最新发行版 https://www.php.net/downloads.php

    2. 下载

      wget https://www.php.net/distributions/php-7.3.10.tar.gz

    3. 解压

      tar -xzvf php-7.3.10.tar.gz

    4. 安装

      1. 进入目录 cd php-7.3.10

      2. configure(这步成功了才能继续)

        1
        2
        3
        ./configure --enable-fpm --with-mysqli --with-zlib --with-curl
        make
        make install
      3. make

        很遗憾遇到了内存耗尽 ‘virtual memory exhausted: Cannot allocate memory’

        free -m 看到

        1
        2
        3
        4
        [root@centos-s-1vcpu-1gb-sfo2-01 php-7.3.10]# free -m
        total used free shared buff/cache available
        Mem: 991 155 691 12 144 672
        Swap: 0 0 0

        增加 swap 文件

        1. mkdir /opt/images/
        2. dd if=/dev/zero of=/opt/images/swap bs=1024 count=2048000
        3. mkswap /opt/images/swap
        4. swapon /opt/images/swap

        再次 free -m

        1
        2
        3
        4
        [root@centos-s-1vcpu-1gb-sfo2-01 php-7.3.10]# free -m
        total used free shared buff/cache available
        Mem: 991 161 79 12 749 645
        Swap: 1999 0 1999

        看到已经多了 2 GB 的 swap。

        使用完毕后删掉可以释放硬盘空间

        1. swapoff swap
        2. rm -f /opt/images/swap
      4. make install

      5. 创建配置文件

        1
        2
        3
        4
        cp php.ini-development /usr/local/php/php.ini
        cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
        cp sapi/fpm/php-fpm /usr/local/bin
        cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
    1. 启动 php-fpm

      php-fpm

      没有输出就是成功了

    ##

    配置 nginx, vi /usr/local/nginx/conf/nginx.conf,以下注释去掉,第 5 行需要修改一下

    1
    2
    3
    4
    5
    6
    7
    location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }

    测试 PHP 环境是否安装成功

    1. echo "<?php phpinfo(); ?>" >/usr/local/nginx/html/index.php
    2. /usr/local/nginx/sbin/nginx -s reload
    3. 访问 /index.php

    错误解决

    出现了 Call to undefined function gzinflate() 错误,是因为我编译 php 的参数每加 –with-zlib。解决过程间我另一篇博客

    其他

    另一个 configure 参数

    1
    ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc  --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd  --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl  --enable-sockets --with-xmlrpc --without-pear  --enable-session

    https://blog.csdn.net/yana_balabala/article/details/82467215

    参考资料

    https://www.cnblogs.com/neco/p/6144784.html

    https://www.cnblogs.com/imzye/p/5066838.html

    https://www.php.cn/php-weizijiaocheng-414091.html

    评论无需登录,可以匿名,欢迎评论!