Handle error of file_get_contents()

$content = @file_get_contents(...)
if ($content === false) {

Step 1. Download http://curl.haxx.se/ca/cacert.pem and save it to /Applications/AMPPS/extra/etc/openssl/certs/cacert.pem

Step 2. Add the below lines into php.ini


Solution 1
1. Use verbose mode to see the error

ssh -v xxx.xxx.xxx.xxx

2. Delete the corresponding row in ~/.ssh/known_hosts

Reference: https://stackoverflow.com/questions/18551556/permission-denied-publickey-when-ssh-access-to-amazon-ec2-instance

Solution 2
1. Detach the volume
2. Create a temporary ec2 instance and attach the volume into it
3. Login to the temporary ec2 instance
4. Check the device code


5. Mount the volume (/dev/xvdg)

mkdir mount_point
mount /dev/xvdg1 mount_point

6. Change the ssh config.
7. Attach the volume back to the original ec2 instance
8. Delete the temporary ec2 instance
9. Delete the corresponding row in ~/.ssh/known_hosts and try again


1. Generate cert

openssl req -x509 -out www.my-helper.test.crt -keyout www.my-helper.test.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=www.my-helper.test' -extensions EXT -config <( \
printf "[dn]\nCN=www.my-helper.test\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:www.my-helper.test\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")

2. Add the certificate to Keychain Access

sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain www.my-helper.test.crt

3. Update Apache config

SSLEngine on
SSLCertificateFile /Applications/AMPPS/www/my-helper.test/certs/www.my-helper.test.crt
SSLCertificateKeyFile /Applications/AMPPS/www/my-helper.test/certs/www.my-helper.test.key


Create Amazon EC2 Instance
1. Login to AWS Management Console
2. Select Amazon EC2
3. Click "Instances" from the left menu
4. Click "launch Instance"

Create Elastic IPs
1. Login to AWS Management Console
2. Click "Elastic IPs" from the left menu
3. Click "Allocate New Address"
4. Select "EC2" and click "Yes, Allocate"

Assign Elastic IP to an Instance
1. Right click an IP and select "Associate"
2. Select an instance and click "Yes, Associate"

First Time Connect
1. Download PuttyGen
2. Click "Load" and select the .pem file
3. Click "Save private key"
4. Open putty
5. From the left menu, select Connection > SSH > Auth
6. Click "Browse" and select the ppk file created in step 3
7. Connect to your instance with the username "ec2-user"

Change Password

sudo passwd root

Create user

adduser myhelper
passwd myhelper

Add user to sudoers

myhelper  ALL=(ALL)       ALL

Configure sshd

vim /etc/ssh/sshd_config
PasswordAuthentication yes
AllowUsers myhelper
/etc/init.d/sshd restart

Change timezone

ln -sf /usr/share/zoneinfo/Hongkong /etc/localtime
(or use tzselect)

Install Apache, MySQL, PHP, FTP

yum install httpd24 mod24_ssl mysql57-server php71 php71-mysqlnd php71-common php71-gd php71-mbstring php71-mcrypt php71-devel php71-xml vsftpd

chkconfig httpd on
chkconfig mysqld on
chkconfig vsftpd on

Create virtual host directory

mkdir -p /var/www/vhosts/myhelper.com/subdomains
mkdir -p /var/www/vhosts/myhelper.com/htdocs
mkdir -p /var/www/vhosts/myhelper.com/logs
chown -R myhelper.myhelper /var/www/vhosts/myhelper.com

Configure PHP

vim /etc/php.ini
max_input_vars = 50000

Configure Apache

vim /etc/httpd/conf/httpd.conf
KeepAlive off
Include /etc/httpd/conf/extra/httpd-vhosts.conf
<IfModule prefork.c>
StartServers            30
MinSpareServers         30
MaxSpareServers         45
ServerLimit             4000
MaxRequestWorkers       4000
MaxConnectionsPerChild  4000

vim /etc/php.ini
upload_max_filesize = 5M
post_max_size = 8M
memory_limit = 256M

mkdir /etc/httpd/conf/extra
vim /etc/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
	DocumentRoot "/var/www/vhosts/my-helper/htdocs"
	ServerName my-helper.com
	ServerAlias www.my-helper.com
	<Directory "/var/www/vhosts/my-helper/htdocs">
		Options Indexes FollowSymLinks
		AllowOverride All
		Order allow,deny
		Allow from all
	ErrorLog "/var/www/vhosts/my-helper/logs/error.log"
	#CustomLog "/var/www/vhosts/my-helper/logs/access.log" common

/etc/init.d/httpd restart

Configure Vsftpd

vim /etc/vsftpd/vsftpd.conf
pasv_address={your public ip address}
vim /etc/vsftpd/user_list

mkdir /etc/vsftpd/userconfig
vim /etc/vsftpd/userconfig/myhelper

/etc/init.d/vsftpd restart

Update sysctl.conf

vim /etc/sysctl.conf

sysctl -p

Update Security Group
1. Login to AWS Management Console
2. Click "Security Groups" from the left menu
3. Select your security group
4. Add TCP port 20-21, 80, 21024-21048

InnoDB: Unable to lock ./ibdata1

InnoDB: Unable to lock ./ibdata1

cd /var/lib/mysql/
mv ibdata1 ibdata1.bak
cp -a ibdata1.bak ibdata1

mv ibdata1 ibdata1.bak
cp -a ibdata1.bak ibdata

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(202,0)

Choose "Hardware-assisted virtualisation" when create image from snapshot

Problem: Insufficient permission for adding an object to repository database

git config core.sharedRepository group

cd /path/to/repo.git
chgrp -R groupname .
chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +


Stop /var/log/cron to be rotated

1. vim /etc/logrotate.d/syslog
2. Comment the line /var/log/cron

Set shortcut to create new file in finder

1. Open Automator and create a Service;
2. Set the input to no input, and the application to Finder.app;
3. Drag and Drop the Run AppleScript workflow element onto the grey space;
4. Put the contents of this AppleScript in the textbox;
5. Save the workflow with a reasonable name (like New File);
6. Go to Settings -> Keyboard -> Shortcuts -> Services and assign a shortcut to it.

set file_name to "untitled"
set file_ext to ".txt"
set is_desktop to false

-- get folder path and if we are in desktop (no folder opened)
    tell application "Finder"
        set this_folder to (folder of the front Finder window) as alias
    end tell
on error
    -- no open folder windows
    set this_folder to path to desktop folder as alias
    set is_desktop to true
end try

-- get the new file name (do not override an already existing file)
tell application "System Events"
    set file_list to get the name of every disk item of this_folder
end tell
set new_file to file_name & file_ext
set x to 1
    if new_file is in file_list then
        set new_file to file_name & " " & x & file_ext
        set x to x + 1
        exit repeat
    end if
end repeat

-- create and select the new file
tell application "Finder"

    set the_file to make new file at folder this_folder with properties {name:new_file}
    if is_desktop is false then
        reveal the_file
        select window of desktop
        set selection to the_file
        delay 0.1
    end if
end tell

-- press enter (rename)
tell application "System Events"
    tell process "Finder"
        keystroke return
    end tell
end tell

Reference: https://apple.stackexchange.com/questions/129699/create-a-new-txt-file-in-finder-keyboard-shortcut

Flag Counter