CentOS

Nginx

  1. 下载源代码
  2. 安装依赖包

    yum install -y pcre-devel zlib-devel
    
  3. 编译、安装和配置

基础虚拟主机配置:

http {
    server {
        listen       80;
        listen       [::]:80;
        server_name  _;

        root /var/www/html/;
        index index.php;

        client_max_body_size 50m;

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_buffering off;
            fastcgi_read_timeout 360s;
            include fastcgi.conf;
            fastcgi_index index.php;
        }
    }
}

MySQL

  1. 安装官方源

    wget -cv https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm rpm -Uvh mysql80-community-release-el7-1.noarch.rpm

  2. 修改 /etc/yum.repos.d/mysql-community.repo,启用需要的 MySQL 版本

  3. 安装 MySQL
    $ yum install mysql-community-server
    $ service mysqld start
    $ # MySQLd root 的初始密码会输出到日志文件 /var/log/mysqld.log 中
    $ mysql_secure_installation     # For MySQL 5.6+
    

PHP

  1. 下载源代码

    wget -cv https://www.php.net/distributions/php-5.6.40.tar.gz
    
  2. 安装依赖包

    yum install -y libxml2-devel openssl-devel libcurl-devel libmcrypt-devel \
        bzip2-devel libvpx-devel libjpeg-devel libpng-devel libXpm-devel
    
  3. 编译安装

    $ ./configure --with-mysql --with-mysqli --with-iconv-dir \
        --with-zlib \
        --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath \
        --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl \
        --enable-mbregex --enable-fpm --enable-mbstring \
        --with-mcrypt --enable-ftp --with-openssl \
        --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip \
        --enable-soap --with-pear --with-gettext --enable-fpm --with-fpm-user=nobody \
        --with-fpm-group=nobody --with-bz2 --with-gd --with-curl
    
    $ make; make install
    
  4. 配置启动

    $ cd /usr/local/etc; mv php-fpm.conf.default php-fpm.conf
    $ php-fpm
    

phpMyAdmin

  1. 下载源代码并解压到目标目录

    wget -cv https://files.phpmyadmin.net/phpMyAdmin/4.9.11/phpMyAdmin-4.9.11-all-languages.tar.gz
    
  2. 访问 phpMyAdmin/setup/index.php 生成配置文件 config.inc.php 内容

    • 使用 cookie 认证模式和 MySQL root 密码

Pasted Graphic

Tools

yum install lrzsz
yum install unzip

Ubuntu

Nginx

  • 安装

    apt install nginx
    service nginx start
    
  • 添加虚拟主机:

    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
    
        root /var/www/html/;
        index index.php;
    
        client_max_body_size 50m;
    
        location ~ \.php$ {
            fastcgi_pass unix:/run/php/php5.6-fpm.sock;    # Default listen by ppa:ondrej/php
            fastcgi_buffering off;
            fastcgi_read_timeout 360s;
            include fastcgi.conf;
            fastcgi_index index.php;
        }
    }
    

    MySQL 8

  • 安装

    apt install mysql-server
    service mysql start
    
  • 安装成功后,执行 mysql_secure_installation,执行完成后,可以使用 root 无密码登录

  • 为了兼容老版本 phpMyAdmin,需要为 root 添加密码,并且更改默认认证方式

    [mysqld]
    default_authentication_plugin = mysql_native_password
    
  • 安装 mkpasswd 生成密码

    apt install mkpasswd
    mkpasswd --chars 10
    
  • 为 root 设置密码

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_password';
    FLUSH PRIVILEDGES;
    

PHP5.6

2019 年版本了,很多依赖库在 Official Repo 中已经找不到了,直接编译基本不能成功。幸好找到了一个 ppa 源,提供了 5.6,7.x,8.x:

add-apt-repository ppa:ondrej/php

随后就可以安装 php5.6-xxx 等包和插件了,基本上常用的插件都可以直接使用 apt 安装。

apt install php5.6-fpm php5.6-bz2 php5.6-mysql php5.6-mbstring php5.6-zip

phpMyAdmin

  1. 需要下载和 PHP 匹配的版本,为 PHP 5.6 需要下载:https://files.phpmyadmin.net/phpMyAdmin/4.9.3/phpMyAdmin-4.9.3-all-languages.zip
  2. 使用配置文件助手生成 config.inc.php:phpMyAdmin/setup/index.php
    • 使用 cookie 认证模式和 MySQL root 密码
  3. 将 config.inc.php 保存到 phpMyAdmin/ 下面
    <?php
    /*
     * Generated configuration file
     * Generated by: phpMyAdmin 4.9.3 setup script
     * Date: Sat, 24 May 2025 10:55:53 +0000
     */
    
    /* Servers configuration */
    $i = 0;
    
    /* Server: localhost [1] */
    $i++;
    $cfg['Servers'][$i]['verbose'] = '';
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['port'] = '';
    $cfg['Servers'][$i]['socket'] = '';
    $cfg['Servers'][$i]['auth_type'] = 'cookie';
    $cfg['Servers'][$i]['user'] = 'root';
    $cfg['Servers'][$i]['password'] = '840I7LmpSs!@#';
    $cfg['Servers'][$i]['AllowNoPassword'] = false;
    
    /* End of servers configuration */
    
    $cfg['blowfish_secret'] = '<f.sA5D`N{1=w7"t[SSM05R{=Ih=!+7';
    $cfg['DefaultLang'] = 'en';
    $cfg['ServerDefault'] = 1;
    $cfg['UploadDir'] = '';
    $cfg['SaveDir'] = '';
    $cfg['TempDir'] = '/tmp';
    ?>
    
    1. 访问 phpMyAdmin/index.php,根据错误提示修复一些内容;
Comments

不要轻轻地离开我,请留下点什么...

comments powered by Disqus

Published

Category

Nginx

Tags

Contact