WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
Â
LVPHP.org
1. ïŹ
How to use open source PHP to build a website and contribute/learn.
By : Joshua Copeland Twitter : @PsyCodeDotOrg
2. Building a site for the user group
ïŹ This is a group project! Lets build something cool overtime.
ïŹ The code will always remain open source and ready for anyone to
send pull requests to add features or fix bugs or security holes.
ïŹ A basic roadmap of features will be kept on the github wiki.
ïŹ Starting simple, from aenglander/starter-app github project.
ïŹ I forked his repo and soon will list it under the github lv-php organization.
ïŹ We encourage other speakers to incorporate their topic of discussion into
the project. Ex. Symfony Components, ORMs, Security, JS/JQuery, Sockets, etc.
ïŹ Video links to talks, slides, docs, etc. will be held centrally in this project if
the speaker used this project for their topics usage example.
3. How did you create the website?
ïŹ Bought the domain name lvphp.org
ïŹ Created the hosting account to house the new site
ïŹ Pointed the DNS to my main webserver
ïŹ Waited for DNS to propagate
ïŹ Loaded lvphp.org in my browser
ïŹ This showed my directory index listed.
ïŹ Blank or not found error from your browser usually means DNS
isnât fully propagated.
You may want to edit your hosts file on your machine and hard code
the IP of your hosting account to start seeing your site immediately.
4. The domain and host is setup, now what?
We now officially have a public facing website ready for PHP code.
Now that our site is live, you can go in many directions. If youâre new
to coding and just want a blog, you might want to try Wordpress. If
you have experience with PHP and want to build a custom site with a
robust framework, you may want to try Symfony, Laravel, Yii, Zend2,
Silex, or CakePHP. Research First, examples, etc.
If youâre new to PHP but want to build something simple without the
use of a MVC framework then fork our github example or look for an
example close to what you want to build and start from there.
https://github.com/aenglander/starter-app
5. Using the PHP starter-app code for our site
ïŹ Sign up for a github account
ïŹ Navigate to the project
ïŹ Click the fork button
ïŹ On your fork page, copy the âHTTPS clone urlâ
ïŹ Install git on your development machine
ïŹ Run âgit clone https://github.com/copiedForkUrlâ
ïŹ A project folder should now exist with the starter code
6. Now start coding and debugging!
ïŹ Spoiler alert : most of your time programming will be spent
debugging so learn how to inspect variables and read code.
ïŹ Xdebug (Use IDEs like PHPStorm or NetBeans to step through code)
ïŹ Use var_dump, print_r, echo, or implementing __toString on objects, to
help dump info to the screen or log to a file via file_put_contents
ïŹ PHP.net is your friend, read documentation on what the function does
and pitfalls to watch out for because PHP (as well as other loosely typed
languages) are riddled with things you must know otherwise assuming
creates bugs. Ex: What does empty(â0â) return? True or False?
ïŹ http://php.net/manual/en/types.comparisons.php
ïŹ When you have issues with your code, now at least you can try figure
out what is going and if still stumped, ask the right questions.
7. Development Environment
ïŹ I highly recommend using a virtual machine for your
development boxes so things are reproducible without having
to take your whole day reconfiguring stuff on your native box.
ïŹ Use vagrant/puppet/virutalbox to stand up a VM
ïŹ Use VirtualBox/VMWare/HyperVisor to just standup an ISO (image) of your
development machine with all the extensions pre-installed.
ïŹ (AKA. Create an image after you configure everything)
ïŹ You can use your native machine if your system is slow (with
VM on) but not recommended. XAMPP might work.
ïŹ Check out my other talk on L.A.M.P. setups for more info on this topic.
8. Production Environment
ïŹ Use capistrano (+ webistrano), chef, phing (+ phingistrano),
phpUnderConrtol, git, or just some hand written scripts for deploying your
code to the remote server.
ïŹ If the code blows up on live, think of how youâre going to rollback the code.
These tools aid in that process, may not be as easy when you have
handwritten scripts or if using git to push to it.
ïŹ Do not commit your production credentials to your VCS! You should have
some settings file with development credentials committed that you can
overwrite on the production server once deployed, you can put those
settings in a separate private repo.
ïŹ Use the same puppet files that you use in development on your server to
automatically provision (setup) your server with all the dependencies the
server needs installed. This gives you the peace of mind that if it works on
your box, itâs going work on the live one.
ïŹ In the beginning we will be just using ftp to push the code live. Later it will
be much more powerful to use ssh so you can run bash commands also.
9. The Programmerâs Development Cycle
Research
Code
Test
Debug
One goal was to create a
topic picker and not
write SQL to allow for
other DBs in the future. I
also wanted to build a
voting system on those
topics picked. I took the
starter-app and ran
âcomposer initâ to add a
dependency on doctrine
ORM for models and the
symfony http foundation
for the request and
response object.