A comprehensive LAMP stack environment built using Docker Compose, featuring:
- PHP
- Apache
- MySQL
- phpMyAdmin
- Redis
Note: This Docker Stack is intended for local development and is not suitable for production use.
-
Clone the repository:
git clone https://github.com/kevinpareek/lamp-docker.git cd lamp-docker
-
Configure environment variables:
./lamp.sh config
Follow the prompts to set up the necessary environment variables.
-
Build and start the LAMP stack:
./lamp.sh start
-
Start:
./lamp.sh start
-
Stop:
./lamp.sh stop
-
Restart:
./lamp.sh restart
- Web Server: Accessible at
http://localhost
orhttps://localhost
(if SSL is configured). - phpMyAdmin: Accessible at
http://localhost:8080
orhttps://localhost:8443
.
-
Add a new application: Ensure your custom domain (e.g., example.com) points to 127.0.0.1 if not using the default localhost.
./lamp.sh addapp <app_name> [domain]
<app_name>
: Name of the application.[domain]
: (Optional) Custom domain, defaults to<app_name>.localhost
.- Place your code in
[DOCUMENT_ROOT]/[APPLICATIONS_DIR_NAME]/<app_name>
. - Create a database in phpMyAdmin (
http://localhost:8080
) namedsql_<app_name>
.
-
Open application code in VS Code:
./lamp.sh code <app_name>
<app_name>
: Name of the application. If omitted, you'll be prompted to select an application.
-
Backup:
./lamp.sh backup
-
Restore:
./lamp.sh restore
following command to log in to the container via SSH:
./lamp.sh cmd
- Generate SSL certificates for a domain:
./lamp.sh ssl <domain>
<domain>
: The domain for which to generate SSL certificates.
We use tool like mkcert to create an SSL certificate. So need to install mkcert first to generate SSL certificates.
-
This package comes with default configuration options. You can modify them by creating a
.env
file in your root directory. To make it easy, just copy the content from thesample.env
file and update the environment variable values as per your need. -
The installed version of PHP and MYSQL depends on your
.env
file.
By default, the following modules are enabled:
- rewrite
- headers
If you want to enable more modules, update
./bin/phpX/Dockerfile
. Rebuild the Docker image by runningdocker compose build
and restart the Docker containers.
By default, the following extensions are installed (may differ for PHP versions <7.x.x):
- mysqli
- pdo_sqlite
- pdo_mysql
- mbstring
- zip
- intl
- mcrypt
- curl
- json
- iconv
- xml
- xmlrpc
- gd
If you want to install more extensions, update
./bin/webserver/Dockerfile
. Rebuild the Docker image by runningdocker compose build
and restart the Docker containers.
phpMyAdmin is configured to run on port 8080. Use the following default credentials:
- URL:
http://localhost:8080/
- Username:
root
- Password:
tiger
Xdebug comes installed by default, and its version depends on the PHP version chosen in the .env
file.
Xdebug versions:
- PHP <= 7.3: Xdebug 2.X.X
- PHP >= 7.4: Xdebug 3.X.X
To use Xdebug, enable the settings in the ./config/php/php.ini
file according to the chosen PHP version.
Example:
# Xdebug 2
#xdebug.remote_enable=1
#xdebug.remote_autostart=1
#xdebug.remote_connect_back=1
#xdebug.remote_host = host.docker.internal
#xdebug.remote_port=9000
# Xdebug 3
#xdebug.mode=debug
#xdebug.start_with_request=yes
#xdebug.client_host=host.docker.internal
#xdebug.client_port=9003
#xdebug.idekey=VSCODE
Install the Xdebug extension "PHP Debug" in VS Code. Create the launch file so that your IDE can listen and work properly.
Example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
// "port": 9000, // Xdebug 2
"port": 9003, // Xdebug 3
"pathMappings": {
// "/var/www/html": "${workspaceFolder}/www" // if you have opened VSCODE in root folder
"/var/www/html": "${workspaceFolder}" // if you have opened VSCODE in ./www folder
}
}
]
}
Make a breakpoint and run debug. After these configurations, you may need to restart the container.
Redis runs on the default port 6379
.
We welcome contributions! If you want to create a pull request, please remember that this stack is not built for production usage, and changes should be good for general purposes and not overspecialized.
Please note that we simplified the project structure from several branches for each PHP version to one centralized master branch. Please create your PR against the master branch.
This stack is designed for local development to quickly create creative applications. In production, you should modify at a minimum the following subjects:
- PHP handler: mod_php => php-fpm
- Secure MySQL users with proper source IP limitations
This project is licensed under the MIT License. See the LICENSE file for details.