You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: manuscript/converted/chapter1.txt
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@
9
9
If you are getting started with PHP, start with the current stable release of [PHP 7.0][php-release]. PHP 7.0 is very
10
10
new, and adds many amazing [new features](#language_highlights) over the older 5.x versions. The engine has been largely re-written, and PHP is now even quicker than older versions.
11
11
12
-
Most commonly in the near future you will find PHP 5.x being used, and the latest 5.x version is 5.6. This is not a bad option, but you should try to upgrade to the latest stable quickly. Upgrading is really quite easy, as there are not many [backwards compatibility breaks][php70-bc]. If you are not sure which version a function or feature is in, you can check the PHP documentation on the [php.net][php-docs] website.
12
+
Most commonly in the near future you will find PHP 5.x being used, and the latest 5.x version is 5.6. This is not a bad option, but you should try to upgrade to the latest stable quickly - PHP 5.6 [will not receive security updates beyond 2018](http://php.net/supported-versions.php). Upgrading is really quite easy, as there are not many [backwards compatibility breaks][php70-bc]. If you are not sure which version a function or feature is in, you can check the PHP documentation on the [php.net][php-docs] website.
13
13
14
14
[php-release]: http://php.net/downloads.php
15
15
[php-docs]: http://php.net/manual/
@@ -36,7 +36,7 @@ To start the server, run the following command from your terminal in your projec
36
36
## Mac Setup {#mac_setup_title}
37
37
38
38
OS X comes prepackaged with PHP but it is normally a little behind the latest stable. Mavericks has 5.4.17,
39
-
Yosemite has 5.5.9 and El Capitan has 5.5.29, but with PHP 7.0 out that is often not good enough.
39
+
Yosemite 5.5.9, El Capitan 5.5.29 and Sierra 5.6.24, but with PHP 7.0 out that is often not good enough.
40
40
41
41
There are multiple ways to install PHP on OS X.
42
42
@@ -56,15 +56,15 @@ command-line, X11 or Aqua based open-source software on the OS X operating
56
56
system.
57
57
58
58
MacPorts supports pre-compiled binaries, so you don't need to recompile every
59
-
dependencies from the source tarball files, it saves your life if you don't
59
+
dependency from the source tarball files, it saves your life if you don't
60
60
have any package installed on your system.
61
61
62
62
At this point, you can install `php54`, `php55`, `php56` or `php70` using the `port install` command, for example:
63
63
64
64
sudo port install php56
65
65
sudo port install php70
66
66
67
-
And you can run `select` command to switch your active php:
67
+
And you can run `select` command to switch your active PHP:
68
68
69
69
sudo port select --set php php70
70
70
@@ -76,7 +76,7 @@ applications/projects require different versions of PHP, and you are not using v
76
76
### Install PHP via Liip's binary installer
77
77
78
78
Another popular option is [php-osx.liip.ch] which provides one liner installation methods for versions 5.3 through 7.0.
79
-
It doesn't overwrite the php binaries installed by Apple, but installs everything in a separate location (/usr/local/php5).
79
+
It doesn't overwrite the PHP binaries installed by Apple, but installs everything in a separate location (/usr/local/php5).
80
80
81
81
### Compile from Source
82
82
@@ -108,13 +108,13 @@ you and tie them all together, but ease of setup comes with a trade-off of flexi
108
108
109
109
You can download the binaries from [windows.php.net/download][php-downloads]. After the extraction of PHP, it is recommended to set the [PATH][windows-path] to the root of your PHP folder (where php.exe is located) so you can execute PHP from anywhere.
110
110
111
-
For learning and local development you can use the built in webserver with PHP 5.4+ so you don't need to worry about
111
+
For learning and local development, you can use the built in webserver with PHP 5.4+ so you don't need to worry about
112
112
configuring it. If you would like an "all-in-one" which includes a full-blown webserver and MySQL too then tools such
113
113
as the [Web Platform Installer][wpi], [XAMPP][xampp], [EasyPHP][easyphp], [OpenServer][openserver] and [WAMP][wamp] will
114
114
help get a Windows development environment up and running fast. That said, these tools will be a little different from
115
115
production so be careful of environment differences if you are working on Windows and deploying to Linux.
116
116
117
-
If you need to run your production system on Windows then IIS7 will give you the most stable and best performance. You
117
+
If you need to run your production system on Windows, then IIS7 will give you the most stable and best performance. You
118
118
can use [phpmanager][phpmanager] (a GUI plugin for IIS7) to make configuring and managing PHP simple. IIS7 comes with
119
119
FastCGI built in and ready to go, you just need to configure PHP as a handler. For support and additional resources
120
120
there is a [dedicated area on iis.net][php-iis] for PHP.
Copy file name to clipboardExpand all lines: manuscript/converted/chapter10.txt
+13-5Lines changed: 13 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -23,12 +23,17 @@ methods to protect yourself against them. This is a must read for the security-c
23
23
Eventually everyone builds a PHP application that relies on user login. Usernames and passwords are stored in a
24
24
database and later used to authenticate users upon login.
25
25
26
-
It is important that you properly [_hash_][3] passwords before storing them. Password hashing is an irreversible, one
27
-
way function performed against the user's password. This produces a fixed-length string that cannot be feasibly
26
+
It is important that you properly [_hash_][3] passwords before storing them. Password hashing is an irreversible,
27
+
one-way function performed against the user's password. This produces a fixed-length string that cannot be feasibly
28
28
reversed. This means you can compare a hash against another to determine if they both came from the same source string,
29
29
but you cannot determine the original string. If passwords are not hashed and your database is accessed by an
30
-
unauthorized third-party, all user accounts are now compromised. Some users may (unfortunately) use the same password
31
-
for other services. Therefore, it is important to take security seriously.
30
+
unauthorized third-party, all user accounts are now compromised.
31
+
32
+
Passwords should also be individually [_salted_][5] by adding a random string to each password before hashing. This prevents dictionary attacks and the use of "rainbow tables" (a reverse list of crytographic hashes for common passwords.)
33
+
34
+
Hashing and salting are vital as often users use the same password for multiple services and password quality can be poor.
35
+
36
+
Fortunately, nowadays PHP makes this easy.
32
37
33
38
**Hashing passwords with `password_hash`**
34
39
@@ -54,17 +59,20 @@ if (password_verify('bad-password', $passwordHash)) {
54
59
}
55
60
~~~~~~~~
56
61
62
+
`password_hash()` takes care of password salting for you. The salt is stored, along with the algorithm and "cost", as part of the hash. `password_verify()` extracts this to determine how to check the password, so you don't need a separate database field to store your salts.
57
63
58
64
* [Learn about `password_hash()`] [1]
59
65
* [`password_compat` for PHP >= 5.3.7 && < 5.5] [2]
60
66
* [Learn about hashing in regards to cryptography] [3]
that, even if the script is accessed directly, it will not be output as plain text.
148
156
- Information in configuration files should be protected accordingly, either through encryption or group/user file
149
157
system permissions.
150
-
- It is a good idea to ensure that you do not commit configuration files containing sensitive information eg passwords or API tokens to source control.
158
+
- It is a good idea to ensure that you do not commit configuration files containing sensitive information e.g. passwords or API tokens to source control.
PHP has shared servers to thank for its popularity. It is hard to find a host without PHP installed, but be sure it's
68
75
the latest version. Shared servers allow you and other developers to deploy websites to a single machine. The upside to
69
76
this is that it has become a cheap commodity. The downside is that you never know what kind of a ruckus your
70
77
neighboring tenants are going to create; loading down the server or opening up security holes are the main concerns. If
71
-
your project's budget can afford to avoid shared servers you should.
78
+
your project's budget can afford to avoid shared servers, you should.
72
79
73
80
To make sure your shared servers are offering the latest versions of PHP, check out [PHP Versions](http://phpversions.info/shared-hosting/).
74
81
@@ -90,40 +97,46 @@ Among the tasks you might want to automate are:
90
97
* Deployment
91
98
92
99
93
-
### Build Automation Tools
100
+
### Deployment Tools
94
101
95
-
Build tools can be described as a collection of scripts that handle common tasks of software deployment. The build tool
96
-
is not a part of your software, it acts on your software from 'outside'.
102
+
Deployment tools can be described as a collection of scripts that handle common tasks of software deployment. The deployment tool is not a part of your software, it acts on your software from 'outside'.
97
103
98
-
There are many open source tools available to help you with build automation, some are written in PHP others aren't.
99
-
This shouldn't hold you back from using them, if they're better suited for the specific job. Here are a few examples:
104
+
There are many open source tools available to help you with build automation and deployment, some are written in PHP others aren't. This shouldn't hold you back from using them, if they're better suited for the specific job. Here are a few examples:
100
105
101
-
[Phing] is the easiest way to get started with automated deployment in the PHP world. With Phing you can control your
102
-
packaging, deployment or testing process from within a simple XML build file. Phing (which is based on [Apache Ant])
103
-
provides a rich set of tasks usually needed to install or update a web app and can be extended with additional custom
104
-
tasks, written in PHP.
106
+
[Phing] can control your packaging, deployment or testing process from within a XML build file. Phing (which is based on [Apache Ant]) provides a rich set of tasks usually needed to install or update a web application and can be extended with additional custom tasks, written in PHP. It's a solid and robust tool and has been around for a long time, however the tool could be perceived as a bit old fashioned because of the way it deals with configuration (XML files).
105
107
106
-
[Capistrano] is a system for *intermediate-to-advanced programmers* to execute commands in a structured, repeatable way
107
-
on one or more remote machines. It is pre-configured for deploying Ruby on Rails applications, however people are **successfully deploying PHP systems** with it. Successful use of Capistrano depends on a working knowledge of Ruby and
108
-
Rake.
108
+
[Capistrano] is a system for *intermediate-to-advanced programmers* to execute commands in a structured, repeatable way on one or more remote machines. It is pre-configured for deploying Ruby on Rails applications, however you can successfully deploying PHP systems with it. Successful use of Capistrano depends on a working knowledge of Ruby and Rake. Dave Gardner's blog post [PHP Deployment with Capistrano][phpdeploy_capistrano] is a good starting point for PHP developers interested in Capistrano.
109
109
110
-
Dave Gardner's blog post [PHP Deployment with Capistrano][phpdeploy_capistrano] is a good starting point for PHP
111
-
developers interested in Capistrano.
110
+
[Rocketeer] gets its inspiration and philosophy from the Laravel framework. Its goal is to be fast, elegant and ease to use with smart defaults. It features multiple servers, multiple stages, atomic deploys and deployment can be performed in parallel. Everything in the tool can be hot swapped or extended, and everything is written in PHP.
112
111
113
-
[Chef] is more than a deployment framework, it is a very powerful Ruby based system integration framework that doesn't
114
-
just deploy your app but can build your whole server environment or virtual boxes.
112
+
[Deployer] is a deployment tool written in PHP, it's simple and functional. Runs tasks in parallel, atomic deployment, keeps consistency between servers. Recipes of common tasks for Symfony, Laravel, Zend Framework and Yii. Younes Rafie's article [Easy Deployment of PHP Applications with Deployer][phpdeploy_deployer] is a great tutorial for deploying your application with the tool.
115
113
116
-
[Deployer] is a deployment tool written in PHP, it's simple and functional. Runs tasks in parallel, atomic deployment, keeps consistency between servers. Recipes of common tasks for Symfony, Laravel, Zend Framework and Yii.
114
+
[Magallanes] another tool written in PHP with simple configuration done in YAML files. It has support for multiple servers and environments, atomic deployment, and have some built in tasks that you can leverage for common tools and frameworks.
117
115
118
-
#### Chef resources for PHP developers:
116
+
#### Further reading:
119
117
120
-
* [Three part blog series about deploying a LAMP application with Chef, Vagrant, and EC2][chef_vagrant_and_ec2]
121
-
* [Chef Cookbook which installs and configures PHP and the PEAR package management system][Chef_cookbook]
122
-
* [Chef video tutorial series][Chef_tutorial]
118
+
* [Automate your project with Apache Ant][apache_ant_tutorial]
119
+
* [Expert PHP Deployments][expert_php_deployments] - free book on deployment with Capistrano, Phing and Vagrant.
120
+
* [Deploying PHP Applications][deploying_php_applications] - paid book on best practices and tools for PHP deployment.
121
+
122
+
### Server Provisioning
123
+
124
+
Managing and configuring servers can be a daunting task when faced with many servers. There are tools for dealing with this so you can automate your infrastructure to make sure you have the right servers and that they're configured properly. They often integrate with the larger cloud hosting providers (Amazon Web Services, Heroku, DigitalOcean, etc) for managing instances, which makes scaling an application a lot easier.
125
+
126
+
[Ansible] is a tool that manages your infrastructure through YAML files. It's simple to get started with and can manage complex and large scale applications. There is an API for managing cloud instances and it can manage them through a dynamic inventory using certain tools.
127
+
128
+
[Puppet] is a tool that has its own language and file types for managing servers and configurations. It can be used in a master/client setup or it can be used in a "master-less" mode. In the master/client mode the clients will poll the central master(s) for new configuration on set intervals and update itself if necessary. In the master-less mode you can push changes to your nodes.
129
+
130
+
[Chef] is a powerful Ruby based system integration framework that you can build your whole server environment or virtual boxes with. It integrates well with Amazon Web Services through their service called OpsWorks.
123
131
124
132
#### Further reading:
125
133
126
-
* [Automate your project with Apache Ant][apache_ant_tutorial]
134
+
* [An Ansible Tutorial][an_ansible_tutorial]
135
+
* [Ansible for DevOps][ansible_for_devops] - paid book on everything Ansible
136
+
* [Ansible for AWS][ansible_for_aws] - paid book on integrating Ansible and Amazon Web Services
137
+
* [Three part blog series about deploying a LAMP application with Chef, Vagrant, and EC2][chef_vagrant_and_ec2]
138
+
* [Chef Cookbook which installs and configures PHP and the PEAR package management system][Chef_cookbook]
0 commit comments