Build a real website from scratch Part 1: Setup Dev Environment

Recently I started to learn PHP, and one of the best ways to learn is to practice. So I planned to build a real website using PHP, and write down the steps.

First we need setup the development environment.

CentOS 7:

Download the ISO image and copy it to USB stick.

$ wget http://mirror.vcu.edu/pub/gnu_linux/centos/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso
$ diskutil list
$ diskutil unmountDisk /dev/disk<#id>
$ dd if=CentOS-7-x86_64-Minimal-1511.iso of=/dev/rdisk<#id> bs=1m

After installation, let’s make sure the time is correctly set, otherwise we may see strange issues later.

# sudo yum install -y ntp
# sudo systemctl enable ntpd
# sudo systemctl start ntpd
# date

LAMP

Next we need to setup the Apache web server,  MySQL database and PHP module. There are lots of good tutorials on this topic, for example howtoforge. Bascially we need following steps to install Apache web server.

# sudo yum install httpd
# sudo systemctl start httpd.service
# sudo systemctl enable httpd.service

// if you have firewall setup.
# sudo firewall-cmd --zone=public --add-service=http
# sudo firewall-cmd --zone=public --list-services

Followed by MySQL server and PHP module.

# sudo yum -y install mariadb-server mariadb
# sudo systemctl start mariadb.service
# sudo systemctl enable mariadb.service
# sudo mysql_secure_installation
# sudo yum -y install php
# sudo systemctl restart httpd.service

Add php file and visit it from http://<ip>/info.php to verify installation succeeded.

# sudo echo -e "<?php\n phpinfo(); \n?>" > /var/www/html/info.php

Git

Now let’s install the version control tool git.

# sudo yum -y install git
# git config --global user.name "You Name"
# git config --global core.editor "emacs"

There are different choices for where to host the repository, for example Github or Visual Studio Online,  are both free if you only have one or two repository. For Visual Studio Online, sign in using your Microsoft ID, create your project, get the repository URL. Let’s clone that project to existing folder /var/www.

# sudo chmod -R 777 /var/www
# ln -s /var/www ~/www
# git clone https://{name}.visualstudio.com/_git/idphotoweb temp
# mv temp/.git ~/www/.git
# rm -rf temp

Now let’s check in the info.php file.

# cd ~/www
# git add html/info.php
# git commit -m "first checkin"
# git push origin master

Go back to visual studio online and verify info.php is there, and now we finish the basic development environment setup.

Leave a Reply