Articles with tag - php

Install LAMP in CentOS 7

Posted on 3 years ago by Ping Cheng


LAMP is a term that stands for Linux, Apache, MySQL and PHP. LAMP provides the basic service for the web hosting. Most website application like WordPress requires those services. This guide will list the command you need to use for LAMP installation in CentOS 7. All commands should be run in the Terminal unless specific required


Step 1 - Install Apache Service

Apache is a service that runs under Linux system to provide web service through HTTP. To install Apache, we use this command to install:

sudo yum install httpd

After installation finish, use this command to start the Apache:

sudo systemctl start httpd.service

Now your Apache service is running. To check if it is running, accessing http://localhost or http://[IP address] by Firefox. If Apache is working, Firefox would display a page with "Testing 123..." If you would like to start Apache on boot, please input this command:



[ Read More ]

Using .env files to configure app

Posted on 3 years ago by Ping Cheng

Using a .env file to configure PHP application has many advantages, especially if you are using Git to manage your project.

Why using env

Some information is never suitable to be stored in your code such as your database connection details. These information is sensitive and may vary in different location, like your development site and production site. Therefore, a separate file should contain all of this information and not to be included in the git tracking list.


To using env, you can use the package phpdotenv from vlucas by composer

composer require vlucas/phpdotenv

After the installation finished, create a file called .env and in root of your project. Open the .env with your preferred editor, you can typed down your own information using below format

DB_PASS=                        # for empty value


[ Read More ]

Upload file to Amazon S3 via PHP

Posted on 2 years ago by Ping Cheng

Before all steps, I assume you are met these prerequisite:

  • Using .env file (link)
  • Using Composer
  • Amazon access key id and secret ready
  1. Install Amazon SDK via Composer
composer require aws/aws-sdk-php
  1. Adding these information to your .env environment file
AWS_ACCESS_KEY_ID=*your key*
AWS_SECRET_ACCESS_KEY=*your secret access*
AWS_REGION=*your s3 bucket region*
AWS_BUCKET=*your bucket name*
  1. Upload the file to bucket

$file = $_FILES['filename'];

$provider = \Aws\Credentials\CredentialProvider::env(); // load the credentials info from the env file
$region = getenv('AWS_REGION'); // setup the region
$bucket = getenv('AWS_BUCKET');  // setup the bucket name

// create a new s3 instance
$s3 = new \Aws\S3\S3Client([
    'version' => 'latest',
    'region' => $region,
    'credentials' => $provider
$random_filename = md5(time()); // create 


[ Read More ]

Hand crafted with by Ping Cheng