What are the best practices for structuring database tables to store permissions for user groups in PHP applications?

When storing permissions for user groups in PHP applications, it is best practice to create a separate table for permissions and user groups, and then create a many-to-many relationship between users and groups. This allows for flexibility in assigning and managing permissions for different user groups. Additionally, using a role-based access control system can simplify permission management and ensure security.

CREATE TABLE permissions (
    id INT PRIMARY KEY,
    name VARCHAR(50) NOT NULL
);

CREATE TABLE user_groups (
    id INT PRIMARY KEY,
    name VARCHAR(50) NOT NULL
);

CREATE TABLE user_group_permissions (
    user_group_id INT,
    permission_id INT,
    FOREIGN KEY (user_group_id) REFERENCES user_groups(id),
    FOREIGN KEY (permission_id) REFERENCES permissions(id),
    PRIMARY KEY (user_group_id, permission_id)
);