mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-12 00:33:58 +02:00
Merge branch 'gh-pages' of https://github.com/codeguy/php-the-right-way into gh-pages
Conflicts: _includes/language-highlights.md
This commit is contained in:
@@ -10,12 +10,32 @@ There are already a lot of PHP libraries that are compatible with Composer, read
|
||||
|
||||
### How to Install Composer
|
||||
|
||||
You can install Composer locally (in your current working directory) or globally (e.g. /usr/local/bin). Let's assume you want to install Composer locally. From your project's root directory:
|
||||
You can install Composer locally (in your current working directory; though this is no longer recommended) or globally (e.g. /usr/local/bin). Let's assume you want to install Composer locally. From your project's root directory:
|
||||
|
||||
> curl -s http://getcomposer.org/installer | php
|
||||
|
||||
This will download `composer.phar` (a PHP binary archive). You can run this with `php` to manage your project dependencies. <strong>Please Note:</strong> If you pipe downloaded code directly into an interpreter, please read the code online first to confirm it is safe.
|
||||
|
||||
### How to Install Composer (manually)
|
||||
|
||||
Manually installing composer is an advanced technique; however, there are various reasons why a developer might prefer this method vs. using the interactive installation routine. The interactive installation checks your PHP installation to ensure that:
|
||||
|
||||
- a sufficient version of PHP is being used
|
||||
- `.phar` files can be executed correctly
|
||||
- certain directory permissions are sufficient
|
||||
- certain problematic extensions are not loaded
|
||||
- certain `php.ini` settings are set
|
||||
|
||||
Since a manual installation performs none of these checks, you have to decide whether the trade-off is worth it for you. As such, below is how to obtain Composer manually:
|
||||
|
||||
> curl -s http://getcomposer.org/composer.phar -o $HOME/local/bin/composer ; chmod +x $HOME/local/bin/composer
|
||||
|
||||
`$HOME/local/bin` (or a directory of your choice) should be in your `$PATH` environment variable. This will result in a `composer` command being available.
|
||||
|
||||
When you come across documentation that states to run Composer as `php composer.phar install`, you can substitute that with:
|
||||
|
||||
> composer install
|
||||
|
||||
### How to Define and Install Dependencies
|
||||
|
||||
First, create a `composer.json` file in the same directory as `composer.phar`. Here's an example that lists [Twig][2] as a project dependency.
|
||||
|
39
_includes/getting-started.md
Normal file
39
_includes/getting-started.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Getting Started
|
||||
|
||||
## Use the Current Stable Version (5.4)
|
||||
|
||||
If you are just getting started with PHP make sure to start with the current stable release of [PHP 5.4][php-release]. PHP has made great strides adding powerful [new features](#language_highlights) over the last few years. Don't let the minor version number difference between 5.2 and 5.4 fool you, it represents _major_ improvements.
|
||||
|
||||
## Built-in web server
|
||||
|
||||
You can start learning PHP without the hassle of installing and configuring a full-fledged web server (PHP 5.4 required). To start the server, run the following from your terminal in your project's web root:
|
||||
|
||||
> php -S localhost:8000
|
||||
|
||||
* [Learn about the built-in, command line web server][cli-server]
|
||||
|
||||
[php-release]: http://www.php.net/downloads.php
|
||||
[cli-server]: http://www.php.net/manual/en/features.commandline.webserver.php
|
||||
|
||||
## Mac Setup
|
||||
|
||||
OS X comes prepackaged with PHP. As of Mountain Lion, it is _not_ the current stable version of PHP, though. You can get the PHP executable through a number of Mac [package managers][mac-package-managers] or [compile it yourself][mac-compile] (if compiling, be sure to have Xcode installed, or Apple's substitute ["Command Line Tools for Xcode" downloadable from Apple's Mac Developer Center][apple-developer]). For a complete Apache, MySQL, and PHP installation check out [MAMP2][mamp-downloads].
|
||||
|
||||
[mac-package-managers]: http://www.php.net/manual/en/install.macosx.packages.php
|
||||
[mac-compile]: http://www.php.net/manual/en/install.macosx.compile.php
|
||||
[xcode-gcc-substitution]: https://github.com/kennethreitz/osx-gcc-installer
|
||||
[apple-developer]: https://developer.apple.com/downloads
|
||||
[mamp-downloads]: http://www.mamp.info/en/downloads/index.html
|
||||
|
||||
## Windows Setup
|
||||
|
||||
You can install PHP on windows from an install executable found on the official [PHP Downloads][php-downloads] page. For a complete Apache, MySQL, and PHP installation check out [WAMP][wamp-installer].
|
||||
|
||||
* [Read more about the official PHP Windows Installer][windows-installer]
|
||||
|
||||
[php-downloads]: http://www.php.net/downloads.php
|
||||
[windows-installer]: http://www.php.net/manual/en/install.windows.installer.msi.php
|
||||
[wamp-installer]: http://www.wampserver.com/
|
||||
|
||||
|
||||
[Back to Top](#top){.top}
|
@@ -72,16 +72,9 @@ To run our script, above, from the command line:
|
||||
Hello, world
|
||||
{% endhighlight %}
|
||||
|
||||
### Built-in, command line web server
|
||||
|
||||
Starting with PHP 5.4, you can develop locally on a PHP-enabled web server without the hassle of installing and configuring a full-fledged web server. To start the server, from your web root:
|
||||
|
||||
{% highlight bash %}
|
||||
> php -S localhost:8000
|
||||
{% endhighlight %}
|
||||
|
||||
* [Learn about running PHP from the command line][php-cli]
|
||||
* [Learn about the built-in, command line web server][cli-server]
|
||||
* [Learn about setting up Windows to run PHP from the command line][php-cli-windows]
|
||||
|
||||
[Back to Top](#top){.top}
|
||||
|
||||
@@ -98,5 +91,5 @@ Starting with PHP 5.4, you can develop locally on a PHP-enabled web server witho
|
||||
[cli-options]: http://www.php.net/manual/en/features.commandline.options.php
|
||||
[argc]: http://php.net/manual/en/reserved.variables.argc.php
|
||||
[argv]: http://php.net/manual/en/reserved.variables.argv.php
|
||||
[cli-server]: http://www.php.net/manual/en/features.commandline.webserver.php
|
||||
[php-cli]: http://php.net/manual/en/features.commandline.php
|
||||
[php-cli-windows]: http://www.php.net/manual/en/install.windows.commandline.php
|
||||
|
29
_includes/servers-and-deployment.md
Normal file
29
_includes/servers-and-deployment.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Servers and Deployment
|
||||
|
||||
PHP applications can be deployed and run on production web servers in a number of ways.
|
||||
|
||||
## Platform as a Service (PaaS)
|
||||
|
||||
In recent years cloud platforms have become popular ways of deploying, hosting, and scaling PHP applications. These can be a great if you're learning PHP and don't have experience or interest in server admin work, too. You can find a list of [PHP PaaS "Platform as a Service" providers](#php_paas_providers) in our [resources section](#resources).
|
||||
|
||||
## Virtual or Dedicated Servers
|
||||
|
||||
If you are comfortable with systems administration, or are interested in learning it, virtual or dedicated servers give you complete control of your application's production environment.
|
||||
|
||||
### nginx and PHP-FPM
|
||||
|
||||
PHP, via PHP's built-in FastCGI Process Manager (FPM), pairs really nicely with [nginx](http://nginx.org), which is a lightweight, high-performance web server. It uses less memory than Apache and can better handle more concurrent requests. This is especially important on virtual servers that don't have much memory to spare. If you are working to put a new PHP app on its own server in production today, choose nginx and PHP-FPM.
|
||||
|
||||
* [Read more on nginx](http://nginx.org)
|
||||
* [Read more on PHP-FPM](http://php.net/manual/en/install.fpm.php)
|
||||
* [Read more on setting up nginx and PHP-FPM securely](https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/)
|
||||
|
||||
### Apache and PHP
|
||||
|
||||
PHP and Apache have a long history together. Apache is wildly configurable and allows sites to control their configurations dynamically, via `.htaccess` files, on a per-directory basis. This has made it a popular choice for shared servers and an easy setup for PHP frameworks and open source apps like WordPress. Unfortunately, Apache uses more resources than nginx and cannot handle as many visitors at the same time. If you are on your own virtual/dedicated server and do not need the configurability of Apache, choose nginx and PHP-FPM.
|
||||
|
||||
## Shared Servers
|
||||
|
||||
PHP has shared servers to thank for its popularity. It is hard to find a host without PHP installed, but be sure it's the latest version. Shared servers allow you and other developers to deploy websites to a single machine. The upside to this is that it has become a cheap commodity. The downside is that you never know what kind of a ruckus your neighboring tenants are going to create; loading down the server or opening up security holes are the main concerns. If your project's budget can afford to avoid shared servers you should.
|
||||
|
||||
[Back to Top](#top){.top}
|
@@ -28,8 +28,17 @@
|
||||
</head>
|
||||
<body>
|
||||
<nav class="site-navigation">
|
||||
<div class="build-date">Last Updated: {{ site.time }}</div>
|
||||
<ul>
|
||||
<li><a href="#site-header">Welcome</a></li>
|
||||
<li><a href="#getting_started">Getting Started</a>
|
||||
<ul>
|
||||
<li><a href="#use_the_current_stable_version_54">Use the Current Stable Version (5.4)</a></li>
|
||||
<li><a href="#builtin_web_server">Built-in Web Server</a></li>
|
||||
<li><a href="#mac_setup">Mac Setup</a></li>
|
||||
<li><a href="#windows_setup">Windows Setup</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#code_style_guide">Code Style Guide</a></li>
|
||||
<li><a href="#language_highlights">Language Highlights</a>
|
||||
<ul>
|
||||
@@ -54,6 +63,13 @@
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#testing">Testing</a></li>
|
||||
<li><a href="#servers_and_deployment">Servers and Deployment</a>
|
||||
<ul>
|
||||
<li><a href="#platform_as_a_service_paas">Platform as a Service (PaaS)</a></li>
|
||||
<li><a href="#virtual_or_dedicated_servers">Virtual or Dedicated Servers</a></li>
|
||||
<li><a href="#shared_servers">Shared Servers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><a href="#libraries_and_frameworks">Libraries and Frameworks</a></li>
|
||||
<li><a href="#resources">Resources</a></li>
|
||||
</ul>
|
||||
|
@@ -5,6 +5,9 @@ layout: default
|
||||
{% capture welcome_content %}{% include welcome.md %}{% endcapture %}
|
||||
{{ welcome_content|markdownify }}
|
||||
|
||||
{% capture getting_started_content %}{% include getting-started.md %}{% endcapture %}
|
||||
{{ getting_started_content|markdownify }}
|
||||
|
||||
{% capture codestyleguide_content %}{% include code-style-guide.md %}{% endcapture %}
|
||||
{{ codestyleguide_content|markdownify }}
|
||||
|
||||
@@ -23,6 +26,9 @@ layout: default
|
||||
{% capture testing_content %}{% include testing.md %}{% endcapture %}
|
||||
{{ testing_content|markdownify }}
|
||||
|
||||
{% capture servers_and_deployment_content %}{% include servers-and-deployment.md %}{% endcapture %}
|
||||
{{ servers_and_deployment_content|markdownify }}
|
||||
|
||||
{% capture frameworks_content %}{% include libraries-and-frameworks.md %}{% endcapture %}
|
||||
{{ frameworks_content|markdownify }}
|
||||
|
||||
|
@@ -261,6 +261,7 @@ select{min-width:30%;}
|
||||
.site-title{margin-bottom:0px !important;font-family:'Alfa Slab One';font-size:80px;line-height:100px !important;}.site-title a{text-decoration:none;}
|
||||
.site-slogan{font-weight:normal;}
|
||||
.site-navigation{background:#EEE;-webkit-box-shadow:inset rgba(0, 0, 0, 0.07) 0 0 40px;-moz-box-shadow:inset rgba(0, 0, 0, 0.07) 0 0 40px;box-shadow:inset rgba(0, 0, 0, 0.07) 0 0 40px;padding-top:20px !important;padding-right:20px !important;padding-bottom:20px !important;padding-left:20px !important;position:fixed;top:0;bottom:0;overflow:auto;width:240px;}
|
||||
.build-date{margin-bottom:20px !important;color:#AAA;font-family:Helvetica,Arial,sans-serif;font-size:11px;}
|
||||
.site-navigation ul{margin-top:0px !important;margin-right:0px !important;margin-bottom:0px !important;margin-left:0px !important;padding-top:0px !important;padding-right:0px !important;padding-bottom:0px !important;padding-left:0px !important;list-style:none;margin:0;padding:0;font-size:16px;}
|
||||
.site-navigation>ul>li{margin-bottom:20px !important;}
|
||||
.site-navigation a{text-decoration:underline;}.site-navigation a:hover{text-decoration:none;}
|
||||
|
@@ -8,6 +8,12 @@
|
||||
overflow: auto;
|
||||
width: 240px;
|
||||
}
|
||||
.build-date{
|
||||
.mbs;
|
||||
color: #AAA;
|
||||
font-family: Helvetica, Arial, sans-serif;
|
||||
font-size: 11px;
|
||||
}
|
||||
.site-navigation ul{
|
||||
.man;
|
||||
.pan;
|
||||
|
Reference in New Issue
Block a user