Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

Latest commit

 

History

History
197 lines (136 loc) · 6.28 KB

File metadata and controls

197 lines (136 loc) · 6.28 KB

Project Setup: PHP (macOS)

Documentation > Project setup > PHP

Table of Contents

  1. Configure a simple web server with PHP and SSL
  2. Start project
  3. Important Locations

Stack Requirement

Install and configure the following services

1. Configuring a simple web server with PHP and SSL

The majority of tools are installed via the Homebrew tool. We will refer the Homebrew root directory with <HOMEBREW_[package]>, which can be retrieved via the command brew --prefix [package]

Step 1. Build a structure

  1. At the root of your project, add a config directory (e.g. config/pleaz). This will be used to store all important files for the services.

  2. Add the docker config files

touch config/pleaz/macos/{.env,docker-compose.yml}
  1. Create the directory for the NGINX server block.

Replace <DOMAIN_NAME> by your domain name

mkdir -p config/pleaz/macos/services/nginx/<DOMAIN_NAME>/includes
touch config/pleaz/macos/services/nginx/<DOMAIN_NAME>/{server.conf,includes/sites.conf}

The structure should look like this:

config/
└── pleaz/
    └── macos/
        ├── .env
      	├── docker-compose.yml
        └── nginx/
            └── <DOMAIN_NAME>/
                ├── server.conf
                └── includes/
                    └── sites.conf

Step 2. Configure Docker environment file

1. Configure the environment

Edit the file config/pleaz/macos/.env and replace all content by:

COMPOSE_PROJECT_NAME="Name of your project"
DOMAIN_URL="Your domain URL without http(s)"
DATABASE_IMAGE="Docker image used"

Variables must be completed

Example:

  • My project is myproject
  • My Domain URL is myproject.test
  • My Docker image database is mysql:5.7

It will look like:

COMPOSE_PROJECT_NAME=myproject
DOMAIN_URL=myproject.test
DATABASE_IMAGE=mysql:5.7

2. Configure services containers

Edit the file config/pleaz/macos/docker-compose.yml and replace all content by: docker-compose.php.yml


Step 3. Park your project into the global configuration of NGINX

For easier maintenance, the point of entry of projects in the configuration of NGINX has been centralized.

The web root directory of the NGINX by default is /usr/local/var/www. We are going to create a symbolic link from our project to this directory.

ln -s <ABSOLUTE_PATH_PROJECT_DIRECTORY> /usr/local/var/www/<DOMAIN_NAME>

Example:

  • My project is /Users/johndoe/Sites/myproject
  • My Domain Name is myproject.test
ln -s /Users/johndoe/Sites/myproject /usr/local/var/www/myproject.test

Step 4. Server configuration

  1. Edit the server configuration file config/pleaz/macos/services/nginx/<DOMAIN_NAME>/server.conf and replace all content by: server.conf

    • Replace <PHP_VERSION> by your version [7.3|7.4|<MAJOR.MINOR>]
    • Replace <DOMAIN_NAME> by your domain name
    • Replace <RELATIVE_PATH_SOURCE> by your relative path of your source code (example: src/store)
  2. Edit the sites configuration file config/pleaz/macos/services/nginx/<DOMAIN_NAME>includes/sites.conf and replace all content by: sites.conf

    • Modify the upstream fastcgi_backend variable with the correct PHP version used (e.g. fastcgi_backend<PHP_VERSION>). See upstream variable NGINX - Configuration
  3. Park your project in the NGINX servers directory via a symlink.

    • Replace <DOMAIN_NAME> by your domain name
ln -s <PROJET_ROOT>/config/pleaz/macos/services/nginx/<DOMAIN_NAME> $(brew --prefix nginx)/servers/

example:

  • PHP version is 7.3.
  • The project is located in /Users/johndoe/Sites/myproject
  • The Domain Name is myproject.test
  1. Configure the server.conf
  2. Edit the fastcgi backend in the sites.conf (Replace fastcgi_backend by fastcgi_backend7.3)
sed -i "" "s/fastcgi_backend/fastcgi_backend7.3/" config/pleaz/macos/services/nginx/<DOMAIN_NAME>/includes/sites.conf
  1. Park the project
ln -s /Users/johndoe/Sites/myproject/config/pleaz/macos/services/nginx/myproject.test $(brew --prefix nginx)/servers/

Step 5. Create locally trusted SSL Certificates with mkcert

Please see instruction here: SSL certificates


2. Start project

(macOS)

You can either use the native command or the Pleaz CLI.

$ cd config/pleaz/macos

## Start docker services
$ docker-compose up -d

## Stop docker services
$ docker-compose down

## Native services
sudo brew services start nginx
sudo brew services start dnsmasq
sudo brew services start mailhog
sudo brew services start php@<PHP_VERSION>

## Pleaz CLI
pleaz service:start nginx
pleaz service:start dnsmasq
pleaz service:start mailhog
pleaz service:start php <PHP_VERSION>

3. Important locations

  • Document Project Root in -> /usr/local/var/www/
  • Locally trusted SSL Certificates in -> <HOMEBREW_[nginx]>/certs/ssl/
  • Server Block directory -> <HOMEBREW_[nginx]>/servers
  • pleaz Configuration directory -> <PROJET_ROOT>/config/pleaz