On this page

用docker搭建PHP网站环境

用docker搭建LNMP建站环境 深度解读 nginx mysql php 搭建全过程

  1. 创建云服务器
  2. 连接云服务器
    1. ssh-keygen命令生成密钥
    2. ssh-copy-id 自动上传公钥
    3. 关闭密码登录
    4. 使用 mosh 提高连接速度
  3. 创建LNMP环境
    1. Docker 安装
    2. 下载LNMP配置文件
    3. 使用Docker安装LNMP环境
  4. 搭建phpMyadmin数据库管理软件
    1. 修改nginx配置
    2. 下载phpMyadmin软件
    3. 安装phpMyadmin软件
    4. 测试phpMyadmin软件

docker lnmp 配置文件

wget  https://github.com/codewhynet/docker-lnmp/archive/refs/heads/main.zip

安装mysql 数据库扩展

 docker exec -it docker_lnmp-8.1-fpm-1  docker-php-ext-install mysqli  pdo_mysql

nginx server config

server {

    listen      8055;

    server_name  localhost;

    root /home/_www_home/www_site/www.phpmyadm.web/phpMyAdmin;

    index index.html index.htm index.php;

    location / {
          try_files $uri /index.php;
    }
    
    location ~ /index\.php|/js/messages\.php$ {
        fastcgi_pass   docker_lnmp-8.1-fpm-1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ \.php$ {
        return 500;
    }
}


下载 phpMyadmin

wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip

phpMyadmin config



/**
 * First server
 */
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'docker_lnmp-mysql-1';
$cfg['Servers'][$i]['hide_db'] = '(information_schema|phpmyadmin|mysql|sys|performance_schema)';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = "qq123456";




获取docker ip 地址 连接 ssh tunnel

    docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)


ssh  -CfNg -L   127.0.0.1:6300:172.18.0.3:8055  [email protected]

    1  clear
    2  vim /etc/ssh/sshd_config.d/50-cloud-init.conf 
    3  sudo apt install mosh
    4  ufw allow 60000:60009/udp 
    5  apt install neovim tmux
    6  service ssh restart 
    7  exit
    8  # Add Docker's official GPG key:
    9  sudo apt-get update
   10  sudo apt-get install ca-certificates curl gnupg
   11  sudo install -m 0755 -d /etc/apt/keyrings
   12  curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
   13  sudo chmod a+r /etc/apt/keyrings/docker.gpg
   14  # Add the repository to Apt sources:
   15  echo   "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
  "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" |   sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
   16  sudo apt-get update	
   17  sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
   18  docker ps
   19  wget  https://github.com/codewhynet/docker-lnmp/archive/refs/heads/main.zip
   20  mkdir /home/_docker_site
   21  cd /home/_docker_site/
   22  unzip ~/main.zip 
   23  mv docker-lnmp-main/  docker_lnmp
   24  ls
   25  cd docker_lnmp/
   26  ls
   27  bash docker_lnmp.sh 
   28   docker exec -it docker_lnmp-8.1-fpm-1  docker-php-ext-install mysqli  pdo_mysql
   29  docker ps
   30  docker restart docker_lnmp-8.1-fpm-1
   31  ls
   32  nvim config/nginx/conf.d/www.phpmyadmin.web.conf
   33  cd data/www_site/
   34  ls
   35  mkdir www.phpmyadm.web
   36  cd www.phpmyadm.web/
   37  ls
   38  wget https://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.zip
   39  unzip  phpMyAdmin-5.2.1-all-languages.zip 
   40  mv phpMyAdmin-5.2.1-all-languages  phpMyAdmin
   41  ls
   42  cd phpMyAdmin/
   43  cp config.sample.inc.php config.inc.php 
   44  nvim config.inc.php 
   45  docker ps
   46  docker restart docker_lnmp-nginx-1
   47   docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
   48   docker inspect --format='{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
   49  mkdir tmp
   50  chown www-data tmp/
   51  ls
   52  dokcer ps
   53  docker ps
   54  docker exec -it docker_lnmp-mysql-1  mysql -uroot -p
   55  cd
   56  ls