diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dfbd14c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +php/www/basic/ diff --git a/README.md b/README.md index 916efcb..db8714a 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,15 @@ htaccess files generated can be switched to nginx with this ## Leaf create (cli to make a starter app if nothing already) leaf create my-app --mvc +sudo docker exec -it aLeaf-php leaf create html/mvc --mvc leaf create basic --basic composer create-project leafs/mvc:v4.0-beta my-app ## Shared folders in windows (virtualbox) VMs -Need to do this or symlinks don't work, and that messes up a bunch of composer stuff \ No newline at end of file +Need to do this or symlinks don't work, and that messes up a bunch of composer stuff + + +### Ignore this, in future for my own less-dependency application +leaf create basic --basic +leaf install bareui +mkdir basic/app/{controllers,database,models,routes,views/{components,errors,layouts,pages}} -p // https://askubuntu.com/a/828864 diff --git a/db/mysql/.gitignore b/db/mysql/.gitignore new file mode 100644 index 0000000..76bedae --- /dev/null +++ b/db/mysql/.gitignore @@ -0,0 +1,5 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore + diff --git a/db/schema.sql b/db/schema.sql new file mode 100644 index 0000000..ac24077 --- /dev/null +++ b/db/schema.sql @@ -0,0 +1,25 @@ +-- Create a user (or more) +CREATE OR REPLACE USER nathan@'%' IDENTIFIED BY 'password'; +-- CREATE USER 'aLeaf'@'%' IDENTIFIED BY "aLeaf"; + +-- Role admin, only they have permission to add others to their role +CREATE OR REPLACE ROLE admin WITH ADMIN nathan@'%'; +GRANT ALL ON *.* TO admin WITH GRANT OPTION; + +-- GRANT ALL PRIVILEGES ON *.* TO 'aLeaf'@'%'; + +-- GRANT ALL PRIVILEGES ON *.* TO 'nathan'@'%' WITH GRANT OPTION; -- Priv, all of the belo +-- GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON *.* TO 'username'@'localhost'; +-- GRANT USAGE ON *.* TO 'nathan'@'%'; -- Allows usage of the tables I guess (default on create?) + +FLUSH PRIVILEGES; + +-- Remove root, to prevent root login +DROP USER root, root@localhost + +-- Create tables, and insert data into them +-- USE ecomdb; -- This is setup by default mariadb compose + +-- CREATE TABLE products (id mediumint(8) unsigned NOT NULL auto_increment,Name varchar(255) default NULL,Price varchar(255) default NULL, ImageUrl varchar(255) default NULL,PRIMARY KEY (id)) AUTO_INCREMENT=1; + +-- INSERT INTO products (Name,Price,ImageUrl) VALUES ("Laptop","100","c-1.png"),("Drone","200","c-2.png"),("VR","300","c-3.png"),("Tablet","50","c-5.png"),("Watch","90","c-6.png"),("Phone Covers","20","c-7.png"),("Phone","80","c-8.png"),("Laptop","150","c-4.png"); diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ab853f7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,54 @@ +# sudo docker compose down && sudo docker compose build --no-cache && sudo docker compose up -d --force-recreate +services: + nginx: + build: ./nginx + #image: nginx:1.27.1 #nginx:latest + container_name: aLeaf-nginx + #ports: + # - 84:80 + restart: always + volumes: + - ./php/www:/var/www/html/ + # This will overwrite default.conf with the one on the container, BUT "COPY" in dockerfile makes it ours by default + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + + php: + build: ./php + #image: php:8.3-fpm + container_name: aLeaf-php + expose: + - 9000 + volumes: + - ./php/www:/var/www/html/ + + db: + #build: ./db + image: mariadb:10.7 + container_name: aLeaf-mariadb + volumes: + #- ./db/mysql:/var/lib/mysql # If sharing from windows host, not gonna work. Needs to be on unixFS + - /home/nathan/docker_vol/aleaf_mariadb:/var/lib/mysql + # bind-mount any sql files that should be run while initializing + # Can omit create database as done via environment + - ./db/schema.sql:/docker-entrypoint-initdb.d/schema.sql + expose: + - 3306 + environment: + MYSQL_ROOT_PASSWORD: mariadb + MYSQL_DATABASE: ecomdb + + adminer: + container_name: aLeaf-adminer + image: adminer + restart: always + #ports: + # - "4141:4141" + # - "8080:8080" + environment: + ADMINER_DEFAULT_SERVER: aLeaf-mariadb + +# docker network create -d bridge proxy # Shared with the NPM instance +networks: + default: + external: true + name: proxy diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 0000000..9f194c0 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx:1.27.1 +COPY ./default.conf /etc/nginx/conf.d/default.conf diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..dd67bfd --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,30 @@ +server { + listen 80 default_server; + + # server_name localhost; + root /var/www/html/basic; + index index.php index.html; + + error_log /var/log/nginx/error.log; + access_log /var/log/nginx/access.log; + + sendfile off; + + client_max_body_size 100m; + + location / { + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_pass php:9000; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + } + + #location ~ /.ht { + # deny all; + #} +} diff --git a/php/Dockerfile b/php/Dockerfile new file mode 100644 index 0000000..f6e06a4 --- /dev/null +++ b/php/Dockerfile @@ -0,0 +1,30 @@ +FROM php:8.3-fpm + +RUN apt-get update && apt-get install -y --no-install-recommends \ + libzip-dev \ + wget \ + git \ + unzip + +RUN docker-php-ext-install zip pdo pdo_mysql mysqli +RUN docker-php-ext-enable mysqli + +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer + +RUN composer global require leafs/cli -W + +RUN ln -s /root/.composer/vendor/bin/leaf /usr/local/bin/leaf + +# If you have a custom PHP ini file you can uncomment this line +# COPY ./php.ini /usr/local/etc/php/php.ini + +RUN apt-get purge -y g++ \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /tmp/* + +WORKDIR /var/www + +# RUN chown -R www-data:www-data /var/www + +CMD ["php-fpm"] diff --git a/php/php.ini b/php/php.ini new file mode 100644 index 0000000..27ede03 --- /dev/null +++ b/php/php.ini @@ -0,0 +1 @@ +# If using a custom php.ini throw it here (after the container has run, then restart) \ No newline at end of file diff --git a/php/www/basic/index.php b/php/www/basic/index.php new file mode 100644 index 0000000..98df9f0 --- /dev/null +++ b/php/www/basic/index.php @@ -0,0 +1,4 @@ + +