The other day I worked on putting together a PHP CMS from scratch, and I learned a little bit about how to set up my environment for running the application locally. So for anyone who is looking for a bit of a reference, below is more information outlining the steps for setting up the environment.
Mac Installation
- The web server (Apache) involved with PHP applications is built-in with a Mac
httpd -v
(on command line to see what version of apache is installed on machine)- ps aux | grep httpd (to find out if apache is running on machine)
- Apache commands:
sudo apachectl start
sudo apachectl stop
sudo apachectl restart
- Create Sites folder within same area as Desktop folder
- navigate cd /etc/apache2/users
sudo atom username.conf
sudo chmod 644 username.conf
sudo apachectl restart
Enable PHP
php -v
(returns version of php)- cd /etc/apache2
- sudo atom httpd.conf (opens config file, search for php, remove # before LoadModule for php to enable php5)
phpinfo()
helpful method that tells you all the configurations for the version of php you’re using- Database (MySQL 5.x)
- download from https://dev.mysql.com/
downloads/ which mysql
(command to find location of mysql)
Additional Info
echo
is used to print text- For comments, // and # are used for single line
How PHP Communicates with the Browser
The browser sends a request to server (Apache). Apache finds the file, processes it if it requires processing (sometimes it might need to go back and forth between the database), then it assembles the html and ships it back to the browser.