How to Install PHP 7.x on CentOS 7

Step 1: Setup the Webtatic YUM repo

Precompiled PHP 7.x binaries are available for CentOS 7 from the WebtaticIUS, or Remi’s RPM repositories.

Below are instructions on installing PHP 7.x using the Webtatic YUM repo.

Setup the Webtatic YUM repo:

sudo rpm -Uvh
sudo rpm -Uvh

Step 2: Install PHP 7.1 and necessary extensions

Install PHP 7.1 and some of the most commonly used extensions:

sudo yum install -y mod_php71w php71w-cli php71w-common php71w-gd php71w-mbstring php71w-mcrypt php71w-mysqlnd php71w-xml

Note: The above packages are for general purpose use and may not suit your specific requirements. You should confirm the packages to be installed referring to the Webtatic PHP 7.1 introduction page.

Alternatively, if you want to install PHP 7.0, you should refer to Webtatic PHP 7.0 introduction page.

Step 3: configure PHP 7.x

After the installation, the PHP 7.x configuration file will be saved as /etc/php.ini. If necessary, you can use the vi text editor to modify it:

sudo cp /etc/php.ini /etc/php.ini.bak
sudo vi /etc/php.ini

Remember to restart your web server after modifying the /etc/php.ini file.

For Apache:

sudo systemctl restart httpd.service

For Nginx:

sudo systemctl restart nginx.service php-fpm.service

That’s it. Thanks for reading.


Update WP

  1. Get the latest WordPress zip (or tar.gz) file.
  2. Unpack the zip file that you downloaded.
  3. Deactivate plugins.
  4. Delete the old wp-includes and wp-admin directories on your web host (through your FTP or shell access).
  5. Using FTP or your shell access, upload the new wp-includes and wp-admin directories to your web host, in place of the previously deleted directories.
  6. Upload the individual files from the new wp-content folder to your existing wp-content folder, overwriting existing files. Do NOT delete your existing wp-content folder. Do NOT delete any files or folders in your existing wp-content directory (except for the one being overwritten by new files).
  7. Upload all new loose files from the root directory of the new version to your existing wordpress root directory.

Reset MySQL Root Password on CentOS 7

1. Stop mysql:
systemctl stop mysqld

2. Set the mySQL environment option 
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. Start mysql usig the options you just set
systemctl start mysqld

4. Login as root
mysql -u root

5. Update the root user password with these mysql commands
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword')
    -> WHERE User = 'root' AND Host = 'localhost';
mysql> quit

6. Stop mysql
systemctl stop mysqld

7. Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS

8. Start mysql normally:
systemctl start mysqld

Try to login using your new password:
7. mysql -u root -p

RHCSA Exam EX200 Cheat Sheet Part 2

Here’s the RHCSA EX200 cheat sheet part 2. Enjoy:

Software Management

To search a package

yum search package-name

To display info of a package

yum info package-name

To install a package

yum install package-name

To remove a package

yum remove package-name

To list a group of available software

yum grouplist

To install a software group

yum groupinstall "group name"

To remove a software group

yum groupremove "group name"

yum repo config is under /etc/yum.repos.d/

To install a rpm package

rpm -i package-name

To check if the package is previously installed

rpm -qa | grep package-name

To remove a rpm package (no need a full name)

rpm -e package-name

To upgrade a package /w status

rpm -Uvh package-name

To list for the documentation of an installed pacakge

rpm -qd | grep package-name (no need a full name)

To list the config file of an installed package

rpm -qc package name (no need a full name)

To display the info of an installed package

rpm -qi package-name

To display kernel number and release version

uname -r

To install a new kernal

yum install kernel

File System

To refresh the system with new partition

partprobe or partx -a /dev/xxx

To create filesystem

mkfs.ext4 /dev/sdb1

To run a filesystem check

fsck /frv/sdb1

To mount a filesystem:
First create a new directory

mkdir /directory
mount -t ext4 /dev/sdb1 /directory

To unmount

umount /directory

To add a swap space on a new partition

mkswap -L NEWSWAP /dev/sdb2
swapon -L NEWSWAP

Then, add an entry on fstab

LABEL=NEWSWAP swap swap defaults 0 0

To setup a user quota
1. Edit fstab,
2. Add usrquota beside defaults
3. mount the partition:

mount -o remount /home

4. Create a userquote file:

quotacheck -cum /home

5. Create username

quota: edquota -u username

6. set a quota:

setquota -u username 30000 35000 0 0 /home

7. Turn on the quota:

quotaon /home

To copy user quota settings

edquota -up username1 username2

To setup a group quota
1. Edit fstab, add grpquota
2. Create a group quota file:

quotacheck -cgm /sales

3. Set a quota:

setquota -g grpname 30000 35000 0 0 /sales

4. Turn on the quota:

quotaon /sales

To view quota usage:

edquota -g sales

To view quota statistic

repquota -ga (for group)
repquota -a (for users)

To create a dump file

dd if=dev/zero of=filename bs=1024 count=25000 (~25MB)

To view an inode

ls -li filename

To create a hard link (cannot cross disk device)

ln filename Desktop/filename-link

To create a symbolic link (can cross disk device)

ln -s /full-path/filename /full-path/filename-link

To setup an ACL
1. Edit fstab,
2. Add acl beside defaults
To view acl:

getfacl /directory

to set acl:

setfacl -m u:username:x /home/directory/

to remove acl:

setfacl -x u:username: /home/directory/


PV(/dev/sda) –> VG –> LV –> directory

Create PV change system ID to LVM (8e) under fdisk

pvcreate /dev/sdb1

To check PV: pvs or pvdisplay

create VG vgcreate vg-name /dev/sdb1 /dev/sdb2

To check VG: vgs or vgdisplay

create LV lvcreate -L 800M -n lv-name vg-name

To check LV: lvs or lvdisplay

create filesystem mkfs.ext4 /dev/vg-name/lv-name

Increase size

resize LV lvresize -L 900M /dev/vg-name/lv-name
resize filesystem resize2fs /dev/vg-name/lv-name

Shrink size
1. unmount the volume first
2. run filecheck fsck -f /dev/vg-name/lv-name

resize filesystem resize2fs /dev/vg-name/lv-name 800M
resize LV lvresize -L 800M /dev/vg-name/lv-name

1. Create a directory for snapshot
2. Create a snapshot of 100M on LV

lvcreate -L 100M -s -n lvmsnapshot /dev/vg-name/lv-name

3. mount the snapshot to retrieve file

mount -t ext4 /dev/vg-name/lvmsnapshot /directoy

delete snapshot:

lvmremove /dev/vg-name/lvmsnapshot

GUI tool for LVM

yum install system-config-lvm

RHCSA Exam EX200 Cheat Sheet Part 1

Below is the cheat sheet that my friend has kindly shared. Enjoy!

Cheat Sheet Part 1

File Compression

To compress files using tarball into tgz format

tar -czvf name.tar files

To view files in tarball file

tar -tf filename

To decompress a tarball

tar -xzvf filename


To edit sudo config


Input & Output redirection

Output to a file, >> will append while > will overwritten

hostname >> file.txt

Input to a command then redirect the output on another file

In this example, send spelling.txt to spell command and redirect the output on mispelled.txt

spell < spelling.txt > mispelled.txt

Output the error to a file, 2> represent redirecting the errors

ls me.txt 2> output.txt

^ means the line will need to being with the word root

grep '^root" /etc/passwd

-n = print line number,

grep -n '[aA]pple' file.txt

grep the line does ends with /sbin/nologin

grep '/sbin/nologin$' /etc/passwd

grep the lines without the text nologin

grep -v '/sbin/nologin$' /etc/passwd

alter a file using search and replace

sed 's/speling/spelling/' spelling.txt > corrected.txt

User/Group management

GUI Tool


Add user account

useradd -c "full name" username

Add user account /w C Shell

useradd -s /bin/tcsh username

Add user account under a specify folder

useradd -c "full name" -d /home/accounting/username username

Add user name + group assignment

useradd -G groupname username

Add user /w password

useradd -p password username

Change user id

usermod -u UID username

Change user name

usermod -l newname oldname

Remove user account along with user’s directory and mailbox file

userdel -r username

Remove user’s directory

rm -rf /home/username

Modify user’s info

usermod -c "full name" username

Password change

passwd username

Password lock

passwd -l username

Password unlock

passwd -u username

Set password age for 90 days

chage -M 90 username

Set password never expire

chage -M -1 username

Set password to expire on specify date

chage -E 2012-01-01 username

Set warning 2 days prior to password expiration

chage -W 2 username

List password policy

chage -l username

Add a group

groupadd groupname

Add user to a group

usermod -G groupname username

Make the group assignment effective without logout

newgrp groupname

Change UID

usermod -u UID username

List user’s belong group


Change group name

groupmod -n newname oldname

Change group ID

groupmod -g 1000 groupname

Show user’s ID

id username

Assign a user as group administrator

gpasswd -A username groupname

Assign a user to a group by adminstrator

gpasswd -a username groupname

Remove a group

groupdel groupname


Modify file / folder permission

chmod o+W file (o for others, add write permission)
chmod 600 file (remove all permission group and other)
chmod ugo+rwx (add rwx permissiom to user. group and other)
chmod ugo-rwx (remove rwx)
chmod g+s file

Change ownership

chown username filename (change user ownship)
chown username:groupname file (change user/grp ownership)
chgrp groupname file (change group ownership)
chown -R username directory change ownership recusively on directory)

Change immutable bit, make the file read only even root

chattr +i filename (+i for add, -i for remove)
list immutable bit
lsattr filename

Change directory permission for user collaboration

chmond 2070 directory(2 means group will have the ownership of file)


Assign ip address to an interface (won’t survive after a reboot)

ifconfig eth1 x.x.x.x netmask x.x.x.x

Shut/bring up an interface

ifdown/ifup eth1

To view routing table

ip route

To add default route

route add default gw x.x.x.x dev eth1

To view ip details

ip addr show
ip -s link

To get ip address from dhcp

dhclient eth1


To list rule

iptables -L

To flush the rules

iptables -F

To save the changes

service iptables save

To add a rule (accept a traffic of tcp port 21)

iptables -I INPUT -p tcp --dport 21 -j ACCEPT

To remove a rule

iptables -D INPUT -p tcp --dport 21 -j ACCEPT


um install system-config-firewall