Deploy to Production Server with Git using PHP

1. Create a deployment script

$commands = array(
    'echo $PWD',
    'whoami',
    'git reset --hard HEAD',
    'git pull',
    'git status',
    'git submodule sync',
    'git submodule update',
    'git submodule status',
);
$output = '';
foreach($commands AS $command){
    $result = exec($command);
    $output .= "{$command}
";
    $output .= htmlentities(trim($result)) . "\n";
}
echo $output;

2. On production server, generate a new SSH key

sudo -u apache ssh-keygen -t rsa

In case the server is not allowed you to generate key for apache, you can create the key using another user and then copy it to apache home folder.

ssh-keygen -t rsa
mv ~username/.ssh ~apache/
chown apache.apache ~apache/.ssh

3. Copy the new SSH key

cat ~/.ssh/id_rsa.pub

4. Go to https://github.com/settings/keys
Click “New SSH Key”

5. Enter Title and paste the SSH key you copied in the previous step. The Title can be anything you want.

6. Go to GitHub repository > Settings > Webhooks > Add web hook > Enter the deployment script url in the Payload URL field. Leave everything else as default.

7. On the production server, go to the site folder and run git clone.

git clone [email protected]:USERNAME/REPO.git .

8. Push the branch to github

9. If doesn’t work, go to /etc/passwd and change apache from /sbin/nologin to /bin/bash, login to apache, git fetch once, then switch back to /sbin/nologin in /etc/passwd

MySQL Commands

Create Database

CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;

If failed, use this instead:

CREATE DATABASE mydatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

Create User

CREATE USER '[USERNAME]'@'localhost' IDENTIFIED BY '[PASSWORD]';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `[DATABASE]`.* TO '[USERNAME]'@'localhost';
CREATE USER '[USERNAME]'@'%' IDENTIFIED BY '[PASSWORD]';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `[DATABASE]`.* TO '[USERNAME]'@'%';

Capturing screenshots on macOS is very slow

Need to do both things below to fix it.

Disable Finder Extensions
1. Go into System Preferences > Extensions
2. In the left sidebar, choose “Finder”
3 Disable everything there include Google Drive Extension

Disable Show Floating Thumbnail
1. Press CMD + SHIFT + 5
2. Click Options
3. Uncheck Show Floating Thumbnail

Change severity list in Mantis

Add the below line into config_inc.php to change the options in the severity list.
$g_severity_enum_string = ’10:feature,30:text,40:tweak,50:minor,60:major,70:crash,80:block’;

Or remove the severity field completely by adding the below array into config_inc.php.
$g_bug_report_page_fields = array(
‘additional_info’,
‘attachments’,
‘category_id’,
‘due_date’,
‘handler’,
‘os’,
‘os_version’,
‘platform’,
‘priority’,
‘product_build’,
‘product_version’,
‘reproducibility’,
// ‘severity’,
‘steps_to_reproduce’,
‘tags’,
‘target_version’,
‘view_state’,
);

Refer to the config_defaults_inc.php file for the details.

Reference:
https://mantisbt.org/forums/viewtopic.php?t=1193

Copy MySQL row with new id

CREATE TEMPORARY TABLE tmp SELECT * from my_table WHERE …;
ALTER TABLE tmp drop pk_id; # drop autoincrement field
INSERT INTO my_table SELECT 0,tmp.* FROM tmp;
DROP TEMPORARY TABLE tmp;

Reference: https://stackoverflow.com/questions/11331573/copy-row-but-with-new-id/11331672#11331672

[proxy_fcgi:error] [pid 3659] (70007)The timeout specified has expired: [client :39524] AH01075: Error dispatching request to : (polling)

Problem:
[proxy_fcgi:error] [pid 3659] (70007)The timeout specified has expired: [client :39524] AH01075: Error dispatching request to : (polling)

Solution:
vim /etc/httpd/conf/httpd.conf
Timeout 600

systemctl reload httpd

Reference: https://stackoverflow.com/questions/46594731/php-apache-error-dispatching-request