LDNMP(Linux Docker Nginx MySQL PHP)是一个轻量、极简化、自动化且100%开源的PHP集成环境安装脚本, 默认安装的PHP版本包含当前PHP所有扩展, 每个版本只更新最新的技术栈。LDNMP支持高度定制化, 方便开发者快速构建本地的PHP环境、且代码透明、无臃肿冗余代码、无垃圾数据产出、安装成功后自动删除对应软件包, 极少的占用磁盘空间。相对于控制面板,在安全性、CPU、内存、网络等资源上大大节流开支。
- 安装前先确保系统是干净的, 没有安装过任何环境, 如: Apache/Nginx/PHP/MySQL/MariaDB, 否则会存在端口冲突。
- 请自行安装 docke 及 docker-compose:
- docker 安装方法: https://docs.docker.com/engine/install/
- docker-compose 安装方法: https://docs.docker.com/compose/install/
- 支持主流 Linux 发行版本(基于 Debian / RedHat macOS 包括 OpenKylin 等国产操作系统)
操作系统 | 架构 | 软件要求 |
---|---|---|
linux/amd64 | x86_64 | docker docker-compose |
linux/arm64 | aarch64 | docker docker-compose |
服务 | 版本 |
---|---|
Nginx | 1.27.x |
MySQL | 9.0.x|9.1.x |
PHP | 8.3.x|8.4.x |
Adminer | latest |
Redis | 7.4.x |
应用版本更新与官方保持同步。
相对目录 | 描述 |
---|---|
./apps/mysql/conf | MySQL配置文件所在路径 |
./apps/mysql/data | MySQL数据存放目录 |
./apps/mysql/logs | MySQL日志存放路径 |
./apps/nginx | Nginx配置文件目录 |
./apps/nginx/ssl | Nginx证书存放目录 |
./apps/nginx/logs | Nginx日志存放目录 |
./web | 网站存放目录 |
./apps/php | PHP配置文件目录 |
./apps/php/logs | PHP-FPM日志目录 |
./apps/php/etc | php.ini php-fpm.conf 配置目录 |
./apps/redis/conf | Redis 配置文件所在目录 |
./apps/redis/data | 数据存储目录 |
安装相对目录可编辑
docker-compose.yaml
修改
Extension | PHP 8.4 | PHP 8.3 |
---|---|---|
amqp | ✓ | ✓ |
apcu | ✓ | ✓ |
apcu_bc | ||
ast | ✓ | ✓ |
bcmath | ✓ | ✓ |
bitset | ✓ | ✓ |
blackfire | ✓ | |
brotli | ✓ | ✓ |
bz2 | ✓ | ✓ |
calendar | ✓ | ✓ |
cassandra* | ||
cmark | ||
csv | ✓ | ✓ |
dba | ✓ | ✓ |
ddtrace* | ✓ | ✓ |
decimal | ✓ | ✓ |
ds | ✓ | ✓ |
ecma_intl* | ✓ | |
enchant | ✓ | ✓ |
ev | ✓ | ✓ |
event | ✓ | ✓ |
excimer | ✓ | ✓ |
exif | ✓ | ✓ |
ffi | ✓ | ✓ |
ftp | ✓ | ✓ |
gd | ✓ | ✓ |
gearman | ✓ | |
geoip | ||
geos* | ✓ | ✓ |
geospatial | ✓ | ✓ |
gettext | ✓ | ✓ |
gmagick | ✓ | ✓ |
gmp | ✓ | ✓ |
gnupg | ✓ | ✓ |
grpc | ✓ | ✓ |
http | ✓ | ✓ |
igbinary | ✓ | ✓ |
imagick | ||
imap | ✓ | ✓ |
inotify | ✓ | ✓ |
interbase | ||
intl | ✓ | ✓ |
ion | ✓ | ✓ |
ioncube_loader | ✓ | |
jsmin | ||
json_post | ✓ | ✓ |
jsonpath | ✓ | ✓ |
ldap | ✓ | ✓ |
luasandbox | ✓ | ✓ |
lz4* | ✓ | ✓ |
lzf | ✓ | ✓ |
mailparse | ✓ | ✓ |
maxminddb | ✓ | ✓ |
mcrypt | ✓ | |
md4c | ✓ | ✓ |
memcache | ✓ | ✓ |
memcached | ✓ | ✓ |
memprof* | ✓ | ✓ |
mongo | ||
mongodb | ✓ | ✓ |
mosquitto | ||
msgpack | ✓ | ✓ |
mssql | ||
mysql | ||
mysqli | ✓ | ✓ |
newrelic | ✓ | |
oauth | ✓ | ✓ |
oci8 | ✓ | ✓ |
odbc | ✓ | ✓ |
opcache | ✓ | ✓ |
opencensus | ||
openswoole | ||
opentelemetry | ||
parallel* | ✓ | ✓ |
parle* | ✓ | ✓ |
pcntl | ✓ | ✓ |
pcov | ✓ | ✓ |
pdo_dblib | ✓ | ✓ |
pdo_firebird | ✓ | ✓ |
pdo_mysql | ✓ | ✓ |
pdo_oci | ✓ | ✓ |
pdo_odbc | ✓ | ✓ |
pdo_pgsql | ✓ | ✓ |
pdo_sqlsrv | ✓ | ✓ |
pgsql | ✓ | ✓ |
phalcon | ✓ | |
php_trie | ✓ | ✓ |
phpy* | ✓ | ✓ |
pkcs11 | ✓ | ✓ |
pq | ✓ | ✓ |
propro | ||
protobuf | ✓ | ✓ |
pspell | ✓ | ✓ |
psr | ✓ | ✓ |
pthreads* | ||
raphf | ✓ | ✓ |
rdkafka | ✓ | ✓ |
recode | ||
redis | ✓ | ✓ |
relay | ✓ | ✓ |
saxon* | ✓ | ✓ |
seasclick | ✓ | ✓ |
seaslog | ✓ | |
shmop | ✓ | ✓ |
simdjson* | ✓ | ✓ |
smbclient | ✓ | ✓ |
snappy | ✓ | ✓ |
snmp | ✓ | ✓ |
snuffleupagus | ✓ | ✓ |
soap | ✓ | ✓ |
sockets | ✓ | ✓ |
sodium* | ||
solr | ✓ | |
sourceguardian | ✓ | |
spx | ✓ | ✓ |
sqlsrv* | ✓ | ✓ |
ssh2 | ✓ | ✓ |
stomp | ✓ | ✓ |
swoole | ✓ | ✓ |
sybase_ct | ||
sync | ✓ | ✓ |
sysvmsg | ✓ | ✓ |
sysvsem | ✓ | ✓ |
sysvshm | ✓ | ✓ |
tensor | ||
tideways | ✓ | ✓ |
tidy | ✓ | ✓ |
timezonedb | ✓ | ✓ |
uopz | ✓ | |
uploadprogress | ✓ | ✓ |
uuid | ✓ | ✓ |
uv | ✓ | ✓ |
vips* | ✓ | ✓ |
vld | ✓ | |
wddx | ||
wikidiff2* | ✓ | ✓ |
xdebug | ✓ | ✓ |
xdiff | ✓ | ✓ |
xhprof | ✓ | ✓ |
xlswriter | ✓ | ✓ |
xmldiff | ✓ | ✓ |
xmlrpc | ✓ | ✓ |
xpass* | ✓ | ✓ |
xsl | ✓ | ✓ |
yac | ✓ | ✓ |
yaml | ✓ | ✓ |
yar | ✓ | ✓ |
zephir_parser | ✓ | ✓ |
zip | ✓ | ✓ |
zmq | ✓ | ✓ |
zookeeper | ||
zstd | ✓ | ✓ |
此扩展来自 https://github.com/mlocati/docker-php-extension-installer 参考示例文件
PS: the pre-installed PHP extensions are excluded from this list.
You can list them with the following command (change php:8.4.2-fpm-alpine
to reflect the PHP version you are interested in):
$ docker run --rm php:8.4.2-fpm-alpine php -m
[PHP Modules]
Core
ctype
curl
date
dom
fileinfo
filter
hash
iconv
json
libxml
mbstring
mysqlnd
openssl
pcre
PDO
pdo_sqlite
Phar
posix
random
readline
Reflection
session
SimpleXML
sodium
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
启动过程: 拉取代码 - 拉取镜像 - 启动服务, 其中 PHP 镜像是基于官方 PHP 镜像默认安装了所有 PHP 扩展, 因此无需再安装 PHP 扩展, 开箱即用。
- clone项目
git clone https://github.com/bdbin/ldnmp.git
或
wget https://github.com/bdbin/ldnmp/archive/refs/heads/main.zip
unzip main.zip
- 设置目录权限
chmod -R 777 ldnmp*
chmod 644 ldnmp*/apps/mysql/conf/my.cnf
- 进入项目目录, 执行以下命令启动服务
docker-compose up -d
或
docker compose up -d
-
安装完成后,在浏览器中访问:http://localhost:8084 或 https://localhost:8085 (自签名HTTPS) 就能看到安装后的效果, PHP代码在文件./web/index.php
-
可访问 http://localhost:8086 访问 Adminer 管理 MySQL 数据库
-
安装完成后,执行如下命令可查看 MySQL 密码,账号默认:root
cat docker-compose.yaml | grep MYSQL_ROOT_PASSWORD
- 安装完成后,执行如下命令可查看 Redis 密码,账号默认:无
cat ldnmp*/apps/redis/conf/redis.conf | grep requirepass
- 默认会自动安装
docker-compose.yaml
中所有的服务, 即: Nginx, MySQL, PHP, Adminer、Redis - 只安装 Nginx
docker-compose up -d nginx
- 只安装 PHP
docker-compose up -d php
- 只安装 MySQL
docker-compose up -d mysql
- 只安装 Redis
docker-compose up -d redis
- 只安装 Nginx, MySQL, PHP, Adminer
docker-compose up -d nginx mysql php adminer
- 可根据需要编辑
docker-compose.yaml
找到PHP_EXTENSIONS
默认是所有的 PHP 扩展, 根据需要删除或增加https://github.com/mlocati/docker-php-extension-installer
中支持的 PHP 扩展, 多个扩展以空格分隔 - 编辑完成后, 执行如下命令开始构建
docker-compose build
或
docker compose build
- 执行如下命令启动构建后的服务
docker-compose up -d
或
docker compose up -d
重启 Nginx
docker restart nginx
重启 MySQL
docker restart mysql
重启 PHP
docker restart php
重启 Adminer
docker restart adminer
重启 Redis
docker restart redis
可选参数: docker <stop|start|restart> servicename
服务 | 容器暴露端口 | 默认端口 |
---|---|---|
Nginx | 8084(http)/ 8085(https) | 80/443 |
PHP | 9000 | 9000 |
MySQL | 3307 | 3306 |
Adminer | 8086 | 8080 |
Redis | 6379 | 6379 |
可编辑
docker-compose.yaml
修改对应服务的端口
-
找到 docker-compose.yaml 文件所在目录,执行如下命令停止服务
docker-compose down
-
在终端执行如下命令可删除所有数据
rm -rf apps docker-compose.yaml web
-
在终端执行如下命令删除 Docker 镜像
docker rmi $(docker images | grep 'php|nginx|mysql|redis' | awk '{print $3}')
卸载删除意味着所有数据将不复存在且不可逆, 请先备份。卸载删除意味着所有数据将不复存在且不可逆, 请先备份。