├── .editorconfig ├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── README.md ├── generate └── test.php ├── .gitignore ├── .travis.yml ├── 404.md ├── CNAME ├── LICENSE ├── README.md ├── _config.yaml ├── _install ├── README.md ├── alpine │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── arch │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── centos │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── debian │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── development.md ├── fedora │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── freebsd │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── linux-build.md ├── mac │ ├── apache.md │ ├── lighttpd.md │ ├── mamp.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ ├── postgresql.md │ └── xampp.md ├── rhel │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── ubuntu │ ├── apache.md │ ├── lighttpd.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── openlitespeed.md │ ├── php.md │ └── postgresql.md ├── windows-build.md └── windows │ ├── apache.md │ ├── composer.md │ ├── easyphp.md │ ├── mamp.md │ ├── mariadb.md │ ├── mongodb.md │ ├── mysql.md │ ├── nginx.md │ ├── php.md │ ├── postgresql.md │ ├── wpnxm.md │ └── xampp.md ├── c ├── README.md ├── arrays.md ├── basics.md ├── binary-files.md ├── coding-style.md ├── editors.md ├── files.md ├── functions.md ├── intro.md ├── operators.md ├── php-extensions.md ├── see-also.md ├── strings.md ├── structs.md └── variables.md ├── docker ├── README.md ├── alpine.md ├── build.md ├── certbot.md ├── composer.md ├── intro.md ├── permissions.md ├── php-extensions.md ├── recipes.md └── usage.md ├── faq ├── README.md ├── db │ ├── README.md │ ├── files.md │ ├── mongodb-vs-mysql.md │ ├── mysql-functions.md │ ├── mysqli-or-pdo.md │ └── orm.md ├── interop │ ├── README.md │ └── editor-ide.md ├── intro │ ├── README.md │ ├── books.md │ ├── core-vs-vanilla.md │ ├── dollar-sign.md │ ├── hosting.md │ ├── php7.md │ ├── what-is-php.md │ └── why-php.md └── misc │ ├── README.md │ ├── browser-detection.md │ ├── certification.md │ ├── crawling.md │ ├── desktop-applications.md │ ├── email.md │ ├── face-detection.md │ ├── get-vs-post.md │ ├── headers-already-sent.md │ ├── how-to-google.md │ ├── increase-file-upload-size.md │ ├── ip.md │ ├── isp.md │ ├── packages.md │ ├── pretty-urls.md │ ├── professions.md │ ├── projects.md │ ├── scraping.md │ ├── screenshot.md │ ├── single-vs-double-quotes.md │ ├── sms.md │ ├── structure.md │ ├── templating.md │ ├── undefined-variable-index-notice.md │ ├── variables.md │ ├── warning-include-require-failed-stream.md │ └── wildcard-subdomains.md ├── interop ├── README.md ├── assets.md ├── atom.md ├── benchmarks.md ├── git.md ├── intro.md ├── make.md ├── nopaste.md └── vagrant.md ├── js ├── README.md ├── debugging.md └── intro.md ├── linux ├── README.md └── alpine.md ├── misc ├── README.md ├── api │ ├── README.md │ ├── intro.md │ ├── rest.md │ └── soap.md ├── async.md ├── deployment.md ├── ecommerce │ ├── README.md │ ├── intro.md │ ├── magento │ │ ├── README.md │ │ └── about-magento.md │ └── shopware │ │ ├── README.md │ │ └── about-shopware.md ├── frameworks │ ├── README.md │ ├── cakephp.md │ ├── codeigniter.md │ ├── create-your-own-framework.md │ ├── frameworks.md │ ├── laravel.md │ ├── symfony.md │ ├── yii.md │ └── zendframework.md ├── licenses.md ├── packages │ ├── README.md │ ├── cms.md │ ├── composer.md │ ├── excel.md │ ├── image-libraries.md │ ├── packages.md │ ├── pagination.md │ ├── payment-gateways.md │ └── pdf.md ├── quality │ ├── README.md │ ├── bdd.md │ ├── code-quality.md │ ├── debugging.md │ └── testing.md └── versions.md ├── php ├── README.md ├── appendices │ ├── README.md │ ├── best-practices.md │ ├── coding-style.md │ ├── criticism.md │ └── evolution.md ├── community │ ├── README.md │ ├── conferences.md │ ├── elephpant.md │ ├── groups.md │ └── podcasts.md ├── ext │ ├── README.md │ ├── date-time.md │ ├── db │ │ ├── README.md │ │ ├── database-vs-filesystem.md │ │ ├── intro.md │ │ └── pdo.md │ ├── intro.md │ ├── phar.md │ ├── regex.md │ └── sessions │ │ ├── README.md │ │ └── intro.md ├── intro │ ├── README.md │ ├── basics.md │ ├── editors.md │ ├── installation.md │ └── start.md ├── ref │ ├── README.md │ ├── constants.md │ ├── control-structures.md │ ├── cookies.md │ ├── errors.md │ ├── exceptions.md │ ├── functions.md │ ├── generators.md │ ├── namespaces.md │ ├── oop │ │ ├── README.md │ │ ├── abstract-classes.md │ │ ├── anti-patterns.md │ │ ├── autoloading.md │ │ ├── design-patterns │ │ │ ├── README.md │ │ │ ├── abstract-factory.md │ │ │ ├── adapter.md │ │ │ ├── bridge.md │ │ │ ├── builder.md │ │ │ ├── chain-of-responsibility.md │ │ │ ├── command.md │ │ │ ├── composite.md │ │ │ ├── decorator.md │ │ │ ├── dependency-injection.md │ │ │ ├── facade.md │ │ │ ├── flyweight.md │ │ │ ├── interpreter.md │ │ │ ├── intro.md │ │ │ ├── iterator.md │ │ │ ├── lazy-loading.md │ │ │ ├── mediator.md │ │ │ ├── memento.md │ │ │ ├── mock-object.md │ │ │ ├── null-object.md │ │ │ ├── object-pool.md │ │ │ ├── observer.md │ │ │ ├── prototype.md │ │ │ ├── proxy.md │ │ │ ├── servant.md │ │ │ ├── singleton.md │ │ │ ├── state.md │ │ │ ├── strategy.md │ │ │ ├── template-method.md │ │ │ ├── type-tunnel.md │ │ │ └── visitor.md │ │ ├── dic.md │ │ ├── intro.md │ │ ├── iterators.md │ │ └── solid.md │ ├── operators.md │ ├── overview.md │ ├── predefined-variables.md │ ├── references.md │ ├── sessions.md │ ├── types │ │ ├── README.md │ │ └── arrays.md │ └── variables.md └── sapi │ ├── README.md │ ├── apache.md │ ├── cgi.md │ ├── cli.md │ ├── embed.md │ ├── fpm.md │ ├── litespeed.md │ └── phpdbg.md ├── security ├── README.md ├── code-protection.md ├── configuration.md ├── cryptography.md ├── intro.md ├── passwords.md ├── sql-injection.md ├── ssl.md └── uploading.md └── tips ├── README.md ├── arrays ├── 01-json-force-object.md └── README.md ├── composer ├── 01-performance.md └── README.md ├── datetime ├── 01-copyright-year.md ├── 02-datetime.md ├── 03-easter.md └── README.md ├── oop ├── 01-visibility.md └── README.md ├── strings ├── 01-emails.md └── README.md ├── style ├── 01-ifs.md └── README.md └── unicorns ├── 01-comments.md ├── 02-dir.md ├── 03-haystack-needle.md ├── 04-ternary-operator.md └── README.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | 3 | root = true 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | tab_width = 4 14 | 15 | [*.yml] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [.github/generate] 20 | indent_style = space 21 | indent_size = 4 22 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of conduct 2 | 3 | This project is part of the [PHP.earth](https://php.earth) group which follows a 4 | [code of conduct](https://conduct.php.earth) to guarantee a welcoming, safe, 5 | inclusive, and harassment-free environment for anyone. 6 | -------------------------------------------------------------------------------- /.github/README.md: -------------------------------------------------------------------------------- 1 | # PHP.earth documentation 2 | 3 | [![Build Status](https://travis-ci.org/phpearth/docs.svg?branch=master)](https://travis-ci.org/phpearth/docs) 4 | 5 |
6 | 7 |
8 | 9 | These files are available online at [PHP.earth](https://docs.php.earth). 10 | 11 | ## Contributing and license 12 | 13 | We are always looking forward to see your contribution to these knowledge resources 14 | as well. 15 | 16 | If you feel that there is something missing and should be pointed out, or you've 17 | just found a typo, don't hesitate to open an issue or send a pull request. The 18 | [contributing document](https://github.com/phpearth/docs/blob/master/.github/CONTRIBUTING.md) 19 | contains more information about contributing. 20 | 21 | This work is [licensed](https://github.com/phpearth/docs/blob/master/LICENSE) 22 | under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) 23 | license. Code snippets in examples are published under the CC0 1.0 Universal 24 | (CC0 1.0). 25 | 26 | Big thanks to all the [authors and contributors](https://php.earth/contributors). 27 | 28 | ## Building PDF and FAQ HTML 29 | 30 | The [generate](https://github.com/phpearth/docs/blob/master/.github/generate) 31 | script generates PDF and HTML from the Markdown sources: 32 | 33 | ```bash 34 | .github/generate 35 | ``` 36 | -------------------------------------------------------------------------------- /.github/generate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | |\"\>)/i', '${1}'.'https://docs.php.earth'.'${2}">', $content); 54 | file_put_contents($docsDir.'/.github/faq.html', $content, LOCK_EX); 55 | 56 | /** 57 | * Generate php-earth.pdf file 58 | */ 59 | $files = implode(' ', getFiles('README.md')); 60 | 61 | echo $pdfOutput = shell_exec(' 62 | docker run -it \ 63 | -v '.$docsDir.':/opt/docs \ 64 | --name php-earth-pandoc \ 65 | phpearth/pandoc pandoc \ 66 | --verbose \ 67 | --toc \ 68 | --toc-depth=1 \ 69 | --pdf-engine=xelatex \ 70 | --top-level-division=default \ 71 | -M documentclass=report \ 72 | -M title="PHP.earth documentation" \ 73 | -M author="PHP.earth" \ 74 | -M date="Generated on `date +%Y-%m-%d`" \ 75 | -M mainfont="Lato" \ 76 | -M geometry="margin=1in" \ 77 | '.$files.' \ 78 | -o /opt/docs/.github/php-earth.pdf 79 | '); 80 | 81 | echo "php-earth.pdf created\n"; 82 | 83 | $exitCode = shell_exec('docker inspect -f {{.State.ExitCode}} php-earth-pandoc'); 84 | 85 | if (strpos($pdfOutput, '[WARNING]') !== false) { 86 | $exitCode = 2; 87 | } 88 | 89 | shell_exec('docker rm php-earth-pandoc'); 90 | 91 | exit($exitCode); 92 | -------------------------------------------------------------------------------- /.github/test.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | hasChildren() && !in_array($file->getFilename(), $exclude)) { 24 | return true; 25 | } 26 | return ($file->isFile() && !in_array($file->getFilename(), $exclude)); 27 | }; 28 | 29 | $innerIterator = new \RecursiveDirectoryIterator( 30 | $docsDir, 31 | \RecursiveDirectoryIterator::SKIP_DOTS 32 | ); 33 | 34 | $iterator = new \RecursiveIteratorIterator( 35 | new \RecursiveCallbackFilterIterator($innerIterator, $filter) 36 | ); 37 | 38 | foreach ($iterator as $pathName => $fileInfo) { 39 | $content = file_get_contents($pathName); 40 | 41 | // Internal links 42 | preg_match_all('/\[.+\]\(((?!http)\/.+)(\).*)/i', $content, $matches); 43 | foreach ($matches[1] as $file) { 44 | $item = preg_replace('~[\\\/]~', DIRECTORY_SEPARATOR, $docsDir.$file); 45 | if (!file_exists($item)) { 46 | if (substr($item, -1) === DIRECTORY_SEPARATOR) { 47 | $then = substr($item, 0, -1) . '.md'; 48 | if (!file_exists($then)) { 49 | $exitCode = 2; 50 | echo '[WARNING] Missing link in '.$pathName.': '.$file.PHP_EOL; 51 | } 52 | } 53 | } 54 | } 55 | 56 | // External links 57 | preg_match_all('/\[.+\]\((https?\:\/\/.+)(\s|\))/iU', $content, $matches); 58 | foreach ($matches[1] as $url) { 59 | /*$code = getHttpResponseCode($url); 60 | if ($code != '200') { 61 | $exitCode = 2; 62 | echo '[WARNING] '.$code.' error in '.$pathName.': '.$url.PHP_EOL; 63 | } 64 | */ 65 | } 66 | } 67 | 68 | exit($exitCode); 69 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .github/php-earth.pdf 2 | .github/faq.html 3 | /_site 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | language: php 4 | 5 | php: 6 | - '7.2' 7 | 8 | services: 9 | - docker 10 | 11 | script: 12 | - .github/test.php 13 | - .github/generate 14 | -------------------------------------------------------------------------------- /404.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: 404 3 | permalink: /404.html 4 | --- 5 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | docs.php.earth 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PHP.earth documentation 2 | 3 | This is a living repository of courses, articles, and frequently asked questions 4 | about PHP and development. 5 | 6 | The following chapters will point out relevant topics to learn PHP and full stack 7 | development. Further resources to study particular topic in more details can be 8 | found in the `See also` sections. 9 | 10 | ## [Vanilla PHP](/php) 11 | 12 | Course containing everything you need to get up and running from first steps to 13 | modern and advanced PHP usage. 14 | 15 | ## [Security](/security) 16 | 17 | Web application and PHP security chapter. 18 | 19 | ## [Miscellaneous](/misc) 20 | 21 | Various topics to learn more about PHP and development. From PHP frameworks, 22 | testing, code quality, APIs and more. 23 | 24 | ## [Interoperability](/interop) 25 | 26 | To successfully work with PHP, there are many libraries and tools available. 27 | This chapter explains some of the recommended interoperability things required 28 | for building web applications with PHP. 29 | 30 | ## [Docker for PHP developers](/docker) 31 | 32 | Docker provides a way to run applications isolated in containers. 33 | 34 | ## [JavaScript for PHP developers](/js) 35 | 36 | Going into full stack development with JavaScript articles, frequently asked 37 | questions, and tips customized for PHP developers. To successfully develop 38 | applications here are some recommended development libraries and resources you 39 | will like and can enrich experience. 40 | 41 | ## [Linux](/linux) 42 | 43 | PHP.earth Linux repositories. 44 | 45 | ## [PHP tips](/tips) 46 | 47 | Simple and stand alone PHP tips and tricks. 48 | 49 | ## [C for PHP developers](/c) 50 | 51 | PHP and its extensions are written in C programming language. This course 52 | includes an introduction to C. After this course you'll be more confident in 53 | your knowledge of C programming and will be able to create C programs and PHP 54 | extensions. 55 | 56 | ## [Frequently asked PHP questions](/faq) 57 | 58 | Qualified and unbiased answers to the most frequently asked questions about PHP. 59 | 60 | ## How to learn? 61 | 62 | Learning is a very important part of every developer to stay current. Everyone 63 | has their own preferences and approaches for learning. Key to success is to keep 64 | learning throughout your entire career. 65 | 66 | Learning tips: Make dedicated time for learning, take small steps, study each 67 | topic in details. Even if it may seem that you will not need particular topic 68 | now, it might be useful later on in some project of yours. 69 | 70 | You will be able to recall where to look further again in the future when you 71 | will need to solve similar development problem. 72 | 73 | Writing blog posts or articles as you learn something new is also advised for 74 | multiple reasons: sharing the knowledge with others and to strengthen your 75 | knowledge on the particular topic. 76 | -------------------------------------------------------------------------------- /_config.yaml: -------------------------------------------------------------------------------- 1 | remote_theme: phpearth/github-pages-theme 2 | permalink: pretty 3 | repository: phpearth/docs 4 | title: PHP.earth 5 | defaults: 6 | - scope: 7 | path: "" 8 | values: 9 | image: https://assets.php.earth/content/phpearth-large.png 10 | 11 | plugins: 12 | - jekyll-sitemap 13 | -------------------------------------------------------------------------------- /_install/README.md: -------------------------------------------------------------------------------- 1 | # PHP installation 2 | 3 | These files are available via the [PHP.earth installation wizard](https://php.earth/install). 4 | -------------------------------------------------------------------------------- /_install/alpine/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | 3 | ```bash 4 | apk add --no-cache apache2 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/alpine/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | 3 | ```bash 4 | apk add --no-cache lighttpd 5 | ``` 6 | 7 | ### Configure Lighttpd 8 | 9 | After successful installation, create a new site specific configuration file. For 10 | example, `/etc/lighttpd/localhost.conf`. This file can reside in any location, 11 | but we'll use this `/etc/lighttpd` for this example. 12 | 13 | ```apacheconf 14 | # /etc/lighttpd/localhost.conf 15 | 16 | # Site public root folder 17 | server.document-root = "/var/www/app/public" 18 | 19 | # Server port 20 | server.port = 80 21 | 22 | # Assigning file mimetypes 23 | mimetype.assign = ( 24 | ".html" => "text/html", 25 | ".txt" => "text/plain", 26 | ".jpg" => "image/jpeg", 27 | ".png" => "image/png" 28 | ) 29 | 30 | # Index file 31 | index-file.names = ( "index.html" ) 32 | ``` 33 | 34 | Test your configuration file: 35 | 36 | ```bash 37 | lighttpd -t -f /etc/lighttpd/localhost.conf 38 | ``` 39 | 40 | And start webserver: 41 | 42 | ```bash 43 | lighttpd -D -f /etc/lighttpd/localhost.conf 44 | ``` 45 | -------------------------------------------------------------------------------- /_install/alpine/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | 3 | ```bash 4 | apk add --no-cache mariadb 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/alpine/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDb 2 | 3 | ```bash 4 | apk add --no-cache mongodb 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/alpine/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | 3 | ```bash 4 | apk add --no-cache mysql 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/alpine/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | 3 | ```bash 4 | apk add --no-cache nginx 5 | ``` 6 | 7 | ### PHP FPM 8 | 9 | To run PHP via Nginx, you should use the PHP FPM SAPI. To install it, run: 10 | 11 | ```bash 12 | apk add --no-cache php7-fpm 13 | ``` 14 | 15 | ### Configure nginx 16 | 17 | After successfully installing, create a configuration file for your site: 18 | 19 | ```nginx 20 | # /etc/nginx/conf.d/default.conf 21 | server { 22 | server_name example.com; 23 | root /var/www/app/public; 24 | 25 | location / { 26 | # try to serve file directly, fallback to index.php 27 | try_files $uri /index.php$is_args$args; 28 | } 29 | 30 | location ~ ^/index\.php(/|$) { 31 | fastcgi_pass unix:/run/php/php-fpm.sock; 32 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 33 | include fastcgi_params; 34 | # When you are using symlinks to link the document root to the 35 | # current version of your application, you should pass the real 36 | # application path instead of the path to the symlink to PHP 37 | # FPM. 38 | # Otherwise, PHP's OPcache may not properly detect changes to 39 | # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 40 | # for more information). 41 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 42 | fastcgi_param DOCUMENT_ROOT $realpath_root; 43 | # Prevents URIs that include the front controller. This will 404: 44 | # http://domain.tld/index.php/some-path 45 | # Remove the internal directive to allow URIs like this 46 | #internal; 47 | } 48 | 49 | # return 404 for all other php files not matching the front controller 50 | # this prevents access to other php files you don't want to be accessible. 51 | location ~ \.php$ { 52 | return 404; 53 | } 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /_install/alpine/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | 3 | ```bash 4 | echo '@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories 5 | apk add --no-cache litespeed@testing 6 | ``` 7 | -------------------------------------------------------------------------------- /_install/alpine/php.md: -------------------------------------------------------------------------------- 1 | ## Install PHP on Alpine Linux 2 | 3 | First, let's install PHP. Alpine Linux official repositories contain slightly 4 | outdated PHP versions. You can install PHP on Alpine Linux using `apk` tool: 5 | 6 | ```bash 7 | apk add --no-cache php7 8 | ``` 9 | 10 | ### 3rd party repository 11 | 12 | PHP.earth Alpine repository provides the latest PHP versions. 13 | 14 | Adding PHP.earth repository to your Alpine: 15 | 16 | ```bash 17 | apk add --no-cache wget ca-certificates \ 18 | && wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub \ 19 | && echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories 20 | ``` 21 | 22 | PHP.earth PHP packages are prefixed with `php7.2`, `php7.1` and `php7.0`. 23 | Installing latest PHP is as simple as: 24 | 25 | ```bash 26 | apk add --no-cache php7.2 27 | ``` 28 | -------------------------------------------------------------------------------- /_install/alpine/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | 3 | ```bash 4 | apk add --no-cache postgresql 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/arch/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | 3 | ```bash 4 | pacman -S apache 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/arch/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | 3 | ```bash 4 | pacman -S lighttpd 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/arch/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | 3 | ```bash 4 | pacman -S mysql 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/arch/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | 3 | ```bash 4 | pacman -S mongodb 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/arch/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/arch/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | 3 | ```bash 4 | pacman -S nginx 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/arch/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | -------------------------------------------------------------------------------- /_install/arch/php.md: -------------------------------------------------------------------------------- 1 | # Install PHP on Arch Linux 2 | 3 | To install latest PHP on Arch Linux, run: 4 | 5 | ```bash 6 | pacman -S php 7 | ``` 8 | 9 | * [More info in the Arch Linux wiki](https://wiki.archlinux.org/index.php/PHP) 10 | -------------------------------------------------------------------------------- /_install/arch/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | 3 | ```bash 4 | pacman -S postgresql 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/centos/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | 3 | ```bash 4 | sudo yum -y install httpd 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/centos/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | 3 | ```bash 4 | yum -y install epel-release 5 | rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 6 | yum update 7 | yum -y install lighttpd 8 | ``` 9 | -------------------------------------------------------------------------------- /_install/centos/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | 3 | ```bash 4 | sudo yum install mariadb-server 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/centos/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | -------------------------------------------------------------------------------- /_install/centos/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/centos/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | 3 | ```bash 4 | sudo yum -y install nginx 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/centos/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | -------------------------------------------------------------------------------- /_install/centos/php.md: -------------------------------------------------------------------------------- 1 | # Install PHP on CentOS 2 | 3 | Official PHP packages on CentOS Linux distribution are slightly behind the 4 | current latest PHP stable versions. To get latest stable PHP, use 5 | [Remi's RPM repository](https://rpms.remirepo.net/wizard/): 6 | 7 | ```bash 8 | yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 9 | yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm 10 | yum install yum-utils 11 | yum-config-manager --enable remi-php72 12 | yum update 13 | yum install php 14 | ``` 15 | -------------------------------------------------------------------------------- /_install/centos/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | -------------------------------------------------------------------------------- /_install/debian/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | 3 | ```bash 4 | sudo apt-get install apache2 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/debian/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | 3 | ```bash 4 | sudo apt-get install lighttpd 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/debian/mariadb.md: -------------------------------------------------------------------------------- 1 | ## MariaDB 2 | 3 | ```bash 4 | 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/debian/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Intall MongoDB 2 | -------------------------------------------------------------------------------- /_install/debian/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | 3 | ```bash 4 | sudo apt-get install mysql-server 5 | ``` 6 | 7 | ```bash 8 | sudo mysql_secure_installation 9 | ``` 10 | -------------------------------------------------------------------------------- /_install/debian/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | 3 | ```bash 4 | sudo apt-get install nginx 5 | ``` 6 | 7 | To successfully run PHP using Nginx, you should use the PHP FPM SAPI. 8 | 9 | ```bash 10 | sudo apt-get install php7.2-fpm 11 | ``` 12 | 13 | ### Configure Nginx 14 | 15 | ```nginx 16 | # /etc/nginx/conf.d/default.conf 17 | server { 18 | server_name example.com; 19 | root /var/www/app/public; 20 | 21 | location / { 22 | # try to serve file directly, fallback to index.php 23 | try_files $uri /index.php$is_args$args; 24 | } 25 | 26 | location ~ ^/index\.php(/|$) { 27 | fastcgi_pass unix:/run/php/php-fpm.sock; 28 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 29 | include fastcgi_params; 30 | # When you are using symlinks to link the document root to the 31 | # current version of your application, you should pass the real 32 | # application path instead of the path to the symlink to PHP 33 | # FPM. 34 | # Otherwise, PHP's OPcache may not properly detect changes to 35 | # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 36 | # for more information). 37 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 38 | fastcgi_param DOCUMENT_ROOT $realpath_root; 39 | # Prevents URIs that include the front controller. This will 404: 40 | # http://domain.tld/index.php/some-path 41 | # Remove the internal directive to allow URIs like this 42 | #internal; 43 | } 44 | 45 | # return 404 for all other php files not matching the front controller 46 | # this prevents access to other php files you don't want to be accessible. 47 | location ~ \.php$ { 48 | return 404; 49 | } 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /_install/debian/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | 3 | ```bash 4 | wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debain_repo.sh | bash 5 | sudo apt-get install openlitespeed 6 | ``` 7 | -------------------------------------------------------------------------------- /_install/debian/php.md: -------------------------------------------------------------------------------- 1 | # Installing PHP on Debian 2 | 3 | To install the latest, stable PHP on Debian Stretch (Debian 9) or Jessie (Debian 8), 4 | you should look into Ondřej Surý's Debian packages at [deb.sury.org](https://deb.sury.org/). 5 | 6 | Here are a quick and simple instructions to get up and running fast: 7 | 8 | ```bash 9 | sudo apt-get install apt-transport-https lsb-release ca-certificates 10 | sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg 11 | echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list 12 | sudo apt-get update 13 | sudo apt-get install php7.2-cli 14 | ``` 15 | -------------------------------------------------------------------------------- /_install/debian/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | 3 | ```bash 4 | sudo apt-get install postgresql postgresql-client 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/development.md: -------------------------------------------------------------------------------- 1 | ## Development on localhost using built-in web server 2 | 3 | If you're developing PHP applications on your local workstation, PHP also has a 4 | useful built-in web server for localhost development. It is not intended to be used 5 | for production environments. 6 | 7 | Inside your project folder you can run it from the command line using PHP CLI 8 | SAPI: 9 | 10 | ```bash 11 | php -S localhost:8000 12 | ``` 13 | 14 | Visit `http://localhost:8000/` in your browser to access it. 15 | 16 | 17 | -------------------------------------------------------------------------------- /_install/fedora/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | 3 | ```bash 4 | sudo dnf install httpd 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/fedora/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | 3 | ```bash 4 | sudo dnf install lighttpd 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/fedora/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Instal MariaDB 2 | 3 | ```bash 4 | dnf install mariadb mariadb-server 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/fedora/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | 3 | ```bash 4 | dnf install mongodb mongodb-server 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/fedora/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/fedora/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | 3 | ```bash 4 | sudo dnf install nginx 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/fedora/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | -------------------------------------------------------------------------------- /_install/fedora/php.md: -------------------------------------------------------------------------------- 1 | # PHP on Fedora 2 | 3 | For Fedora Linux use the [Remi's RPM repository](https://rpms.remirepo.net/wizard/): 4 | 5 | ```bash 6 | dnf install http://rpms.remirepo.net/fedora/remi-release-26.rpm 7 | dnf config-manager --set-enabled remi-php72 8 | dnf update 9 | dnf install php 10 | ``` 11 | -------------------------------------------------------------------------------- /_install/fedora/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | 3 | ```bash 4 | sudo dnf install postgresql-server postgresql-contrib 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/freebsd/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | -------------------------------------------------------------------------------- /_install/freebsd/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd server 2 | -------------------------------------------------------------------------------- /_install/freebsd/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | -------------------------------------------------------------------------------- /_install/freebsd/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | -------------------------------------------------------------------------------- /_install/freebsd/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/freebsd/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | -------------------------------------------------------------------------------- /_install/freebsd/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | -------------------------------------------------------------------------------- /_install/freebsd/php.md: -------------------------------------------------------------------------------- 1 | # Installing PHP on FreeBSD 2 | 3 | ```bash 4 | sudo pkg install php71 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/freebsd/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | -------------------------------------------------------------------------------- /_install/linux-build.md: -------------------------------------------------------------------------------- 1 | ## Building PHP from source 2 | 3 | Building PHP from source includes 3 main steps: 4 | 5 | * `./configure` - this step creates so called Makefiles required to compile PHP 6 | source code based on the given configure options (`--with-foo`, `--enable-bar`, 7 | etc). 8 | * `make` - this step starts the actual compilation of the C files. 9 | * `make install` - this step copies built files to system folders. 10 | 11 | To build PHP from source code you will need the following prerequisites first: 12 | 13 | * autoconf 14 | * gcc 15 | * g++ 16 | * make 17 | * rc2 18 | 19 | First let's get the PHP sources. You have multiple options here. You can download 20 | prepaired archive from the php.net downloads section or you can download source 21 | code from the Git repository. Difference between the two options is that the 22 | prepared downloads come with the `configure` script. 23 | 24 | PHP from the Git repository requires to create a `configure` script before 25 | proceeding. In the root folder there is a `buildconf` script which does that: 26 | 27 | ```bash 28 | ./buildconf 29 | ``` 30 | 31 | After that you can start with configuring your build with the `configure` script. 32 | 33 | ```bash 34 | cd /usr/src/php 35 | ./configure 36 | make 37 | make install 38 | ``` 39 | 40 | ### See also 41 | 42 | * [PHP Internals](http://www.phpinternalsbook.com) 43 | -------------------------------------------------------------------------------- /_install/mac/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | -------------------------------------------------------------------------------- /_install/mac/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | -------------------------------------------------------------------------------- /_install/mac/mamp.md: -------------------------------------------------------------------------------- 1 | ## Install MAMP 2 | 3 | Download and install MAMP from the official [website](https://www.mamp.info/en/). 4 | -------------------------------------------------------------------------------- /_install/mac/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | 3 | ```bash 4 | brew install mariadb 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/mac/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | -------------------------------------------------------------------------------- /_install/mac/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/mac/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | -------------------------------------------------------------------------------- /_install/mac/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | -------------------------------------------------------------------------------- /_install/mac/php.md: -------------------------------------------------------------------------------- 1 | # Install PHP on macOS 2 | 3 | By default, macOS includes a slightly outdated PHP. To install and use the latest 4 | PHP on macOS, you can use one of the following solutions: 5 | 6 | * [Homebrew PHP repository](https://github.com/Homebrew/homebrew-php) for 7 | [Homebrew](https://brew.sh/) package manager. 8 | * [Liip's PHP binary package](https://php-osx.liip.ch/). 9 | * [MacPorts](https://www.macports.org/) - Package management system provided by 10 | an open source community initiative. 11 | 12 | ## All-in-one stacks 13 | 14 | The following stacks include PHP, webserver, database, and additional tools 15 | for developing PHP applications on your workstation: 16 | 17 | * [AMMPS](http://www.ampps.com/) 18 | * [MAMP](https://www.mamp.info/en/downloads/) 19 | * [XAMPP](https://www.apachefriends.org/index.html) 20 | * [Zend Server](http://www.zend.com/en/products/zend_server) 21 | -------------------------------------------------------------------------------- /_install/mac/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | -------------------------------------------------------------------------------- /_install/mac/xampp.md: -------------------------------------------------------------------------------- 1 | ## Install XAMPP 2 | 3 | Download and install XAMPP from the official [website](https://www.apachefriends.org/index.html). 4 | -------------------------------------------------------------------------------- /_install/rhel/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | -------------------------------------------------------------------------------- /_install/rhel/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | -------------------------------------------------------------------------------- /_install/rhel/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | -------------------------------------------------------------------------------- /_install/rhel/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | -------------------------------------------------------------------------------- /_install/rhel/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/rhel/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | -------------------------------------------------------------------------------- /_install/rhel/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | -------------------------------------------------------------------------------- /_install/rhel/php.md: -------------------------------------------------------------------------------- 1 | # Install PHP on Redhat 2 | 3 | Official PHP packages on RedHat Enterprise Linux distribution are slightly behind 4 | the current latest PHP stable versions. To get latest stable PHP, use 5 | [Remi's RPM repository](https://rpms.remirepo.net/wizard/): 6 | 7 | ```bash 8 | yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 9 | yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm 10 | yum install yum-utils 11 | subscription-manager repos --enable=rhel-7-server-optional-rpms 12 | yum-config-manager --enable remi-php72 13 | yum update 14 | yum install php 15 | ``` 16 | -------------------------------------------------------------------------------- /_install/rhel/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | -------------------------------------------------------------------------------- /_install/ubuntu/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | 3 | ```bash 4 | sudo apt-get install apache2 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/ubuntu/lighttpd.md: -------------------------------------------------------------------------------- 1 | ## Install Lighttpd 2 | 3 | ```bash 4 | sudo apt-get install lighttpd 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/ubuntu/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | -------------------------------------------------------------------------------- /_install/ubuntu/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | -------------------------------------------------------------------------------- /_install/ubuntu/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | 3 | ```bash 4 | sudo apt-get install mysql-server 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/ubuntu/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | 3 | ```bash 4 | sudo apt-get install nginx 5 | ``` 6 | 7 | To successfully run PHP using Nginx, you should use the PHP FPM SAPI. 8 | 9 | ```bash 10 | sudo apt-get install php7.2-fpm 11 | ``` 12 | 13 | ### Configure Nginx 14 | 15 | ```nginx 16 | # /etc/nginx/conf.d/default.conf 17 | server { 18 | server_name example.com; 19 | root /var/www/app/public; 20 | 21 | location / { 22 | # try to serve file directly, fallback to index.php 23 | try_files $uri /index.php$is_args$args; 24 | } 25 | 26 | location ~ ^/index\.php(/|$) { 27 | fastcgi_pass unix:/run/php/php-fpm.sock; 28 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 29 | include fastcgi_params; 30 | # When you are using symlinks to link the document root to the 31 | # current version of your application, you should pass the real 32 | # application path instead of the path to the symlink to PHP 33 | # FPM. 34 | # Otherwise, PHP's OPcache may not properly detect changes to 35 | # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126 36 | # for more information). 37 | fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; 38 | fastcgi_param DOCUMENT_ROOT $realpath_root; 39 | # Prevents URIs that include the front controller. This will 404: 40 | # http://domain.tld/index.php/some-path 41 | # Remove the internal directive to allow URIs like this 42 | #internal; 43 | } 44 | 45 | # return 404 for all other php files not matching the front controller 46 | # this prevents access to other php files you don't want to be accessible. 47 | location ~ \.php$ { 48 | return 404; 49 | } 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /_install/ubuntu/openlitespeed.md: -------------------------------------------------------------------------------- 1 | ## Install OpenLiteSpeed 2 | 3 | ```bash 4 | wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debain_repo.sh | bash 5 | sudo apt-get install openlitespeed 6 | ``` 7 | -------------------------------------------------------------------------------- /_install/ubuntu/php.md: -------------------------------------------------------------------------------- 1 | ## Installing PHP on Ubuntu 2 | 3 | Official package on Ubuntu is usually recommeended but there is a better way to 4 | get the latest stable PHP using [Ondřej Surý](https://launchpad.net/~ondrej/+archive/ubuntu/php) 5 | PHP packages: 6 | 7 | ```bash 8 | sudo add-apt-repository ppa:ondrej/php 9 | sudo apt-get update 10 | sudo apt-get install php7.2 11 | ``` 12 | -------------------------------------------------------------------------------- /_install/ubuntu/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | 3 | ```bash 4 | sudo apt-get install postgresql postgresql-contrib 5 | ``` 6 | -------------------------------------------------------------------------------- /_install/windows-build.md: -------------------------------------------------------------------------------- 1 | ## Build and compile PHP 2 | 3 | To build and compile PHP on Windows systems, follow the tutorial on the 4 | [PHP wiki](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2). 5 | -------------------------------------------------------------------------------- /_install/windows/apache.md: -------------------------------------------------------------------------------- 1 | ## Install Apache HTTP server 2 | -------------------------------------------------------------------------------- /_install/windows/composer.md: -------------------------------------------------------------------------------- 1 | ## Install Composer 2 | 3 | [Composer](https://getcomposer.org) is a de-facto standard manager for installing 4 | libraries, frameworks, and similar packages for your PHP applications. You will 5 | need to have it as well sooner or later if you haven't used it before. 6 | 7 | Go to the [download page](https://getcomposer.org/doc/00-intro.md#installation-windows) 8 | and download the `Composer-Setup.exe` installer. 9 | 10 | The Composer Setup options provide to install it without additional uninstaller 11 | for development purposes of Composer itself. At this stage you don't need to 12 | select the *Developer mode*: 13 | 14 | ![Composer checking CLI](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/cli-check.png "Composer checking CLI") 15 | 16 | The installer will check some PHP settings for you: 17 | 18 | ![Composer checking PHP settings](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/php-check.png "Composer checking PHP settings") 19 | 20 | First check is to see if PHP can be run from the command line interface (CLI): 21 | 22 | ![Composer checking CLI](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/cli-check.png "Composer checking CLI") 23 | 24 | In case you're using proxy to connect to internet, enter it here: 25 | 26 | ![Composer proxy](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/proxy.png "Composer proxy") 27 | 28 | After Composer is installed, you will need to close any command line windows or 29 | open a new one so you can fully use it. 30 | 31 | ![Composer info](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/info.png "Composer info") 32 | 33 | Click **Next**. 34 | 35 | Composer should now be fully installed on your Windows system: 36 | 37 | ![Composer completing](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/completing.png "Composer completing") 38 | 39 | To check if installation is successful, open the command line and run the 40 | `composer about` or just composer to see if the command produceces any output: 41 | 42 | ![Composer CMD](https://raw.githubusercontent.com/phpearth/assets/master/images/docs/install/win/composer/composer-cmd.png "Composer CMD") 43 | -------------------------------------------------------------------------------- /_install/windows/easyphp.md: -------------------------------------------------------------------------------- 1 | ## Install EasyPHP 2 | 3 | Download and install EasyPHP from the official [website](http://www.easyphp.org/). 4 | -------------------------------------------------------------------------------- /_install/windows/mamp.md: -------------------------------------------------------------------------------- 1 | ## Install MAMP 2 | 3 | Download and install MAMP from the official [website](https://www.mamp.info/en/). 4 | -------------------------------------------------------------------------------- /_install/windows/mariadb.md: -------------------------------------------------------------------------------- 1 | ## Install MariaDB 2 | 3 | Download and run the MariaDB package or installer from the [official website](https://downloads.mariadb.org/) 4 | -------------------------------------------------------------------------------- /_install/windows/mongodb.md: -------------------------------------------------------------------------------- 1 | ## Install MongoDB 2 | -------------------------------------------------------------------------------- /_install/windows/mysql.md: -------------------------------------------------------------------------------- 1 | ## Install MySQL 2 | -------------------------------------------------------------------------------- /_install/windows/nginx.md: -------------------------------------------------------------------------------- 1 | ## Install nginx 2 | -------------------------------------------------------------------------------- /_install/windows/php.md: -------------------------------------------------------------------------------- 1 | On Windows there are multiple ways to install the latest, stable PHP. This guide 2 | will cover the most useful ways to get up and running fast. 3 | 4 | ## Official Windows binaries 5 | 6 | PHP.net maintains Windows binaries available for download at 7 | [windows.php.net](http://windows.php.net). This is what you want to get a simple 8 | and working latest PHP installation on Windows. 9 | 10 | ## Packages 11 | 12 | * [Chocolatey](https://chocolatey.org/packages/php) 13 | -------------------------------------------------------------------------------- /_install/windows/postgresql.md: -------------------------------------------------------------------------------- 1 | ## Install PostgreSQL 2 | 3 | Download PostgreSQL from the [official website](https://www.postgresql.org/download/windows/). 4 | -------------------------------------------------------------------------------- /_install/windows/wpnxm.md: -------------------------------------------------------------------------------- 1 | ## Install WPN-XM 2 | 3 | Download the WPN-XM stack from the official [website](https://wpn-xm.org). 4 | -------------------------------------------------------------------------------- /c/README.md: -------------------------------------------------------------------------------- 1 | # C programming language for PHP developers 2 | 3 | This is an introduction into C programming language dedicated for PHP developers. 4 | After this course you'll be more confident in your knowledge of C programming 5 | language and will be able to create C programs. You will be able to understand 6 | many portions of the C code used in the 7 | [PHP source code](https://github.com/php/php-src). 8 | 9 | ## [Introduction](intro.md) 10 | 11 | Start with a quick introduction into C programming language. 12 | 13 | ## [Editors and IDEs](editors.md) 14 | 15 | ## [C programming basics](basics.md) 16 | 17 | ## [Variables, constants, and types](variables.md) 18 | 19 | ## [Operators, tests, and user input](operators.md) 20 | 21 | ## [Functions and arguments](functions.md) 22 | 23 | ## [Arrays, loops, and break](arrays.md) 24 | 25 | ## [Strings, chars, and pointers](strings.md) 26 | 27 | ## [Structs, enums, header files, and scope](structs.md) 28 | 29 | ## [File-handling](files.md) 30 | 31 | ## [Binary files and memory allocation](binary-files.md) 32 | 33 | ## [PHP extensions](php-extensions.md) 34 | 35 | ## [Coding style](coding-style.md) 36 | 37 | ## [See also](see-also.md) 38 | -------------------------------------------------------------------------------- /c/arrays.md: -------------------------------------------------------------------------------- 1 | # Arrays, loops, and break 2 | 3 | Array can be imagined as a container with a fixed number of elements, where each 4 | element is indexed from `0` incrementally: 5 | 6 | | Array element | `H` | `e` | `l` | `l` | `o` | 7 | | Array index | 0 | 1 | 2 | 3 | 4 | 8 | 9 | Let's check a code example: 10 | 11 | ```c 12 | #include 13 | 14 | char *strings[5]; 15 | 16 | int main() { 17 | int i; 18 | 19 | strings[0] = "H"; 20 | strings[1] = "e"; 21 | strings[2] = "l"; 22 | strings[3] = "l"; 23 | strings[4] = "o"; 24 | 25 | for (i = 0; i < 5; i++) { 26 | printf("%s\n", strings[i]); 27 | } 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /c/binary-files.md: -------------------------------------------------------------------------------- 1 | # Binary files and memory allocation 2 | -------------------------------------------------------------------------------- /c/coding-style.md: -------------------------------------------------------------------------------- 1 | # Coding style 2 | 3 | C doesn't have standards or official guidelines when it comes to code writing 4 | style. Having such freedom is many times useful and also important, however 5 | collaborating on a project with different developers will soon require a set of 6 | coding style guidelines. Important to understand here is that no matter which 7 | coding style you pick, define it well and stick to it when adding new code. 8 | Reading code with consistent coding style matters. 9 | 10 | Here are top coding styles you should consider adopting instead of reinventing 11 | your own. 12 | 13 | * [LLVM coding standards](http://llvm.org/docs/CodingStandards.html) 14 | * [Google C++ coding style](https://google.github.io/styleguide/cppguide.html) 15 | * [Chromium coding style](http://www.chromium.org/developers/coding-style) 16 | * [Mozilla coding style](https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Coding_Style) 17 | * [WebKit coding style](https://webkit.org/code-style-guidelines/) 18 | 19 | ## Useful tools 20 | 21 | ### Clang-Format 22 | 23 | Clang-Format is a very useful formatting tool to quickly format your C code to 24 | a predefined coding style. 25 | 26 | Main tool is `clang-format`. You initially create a YAML file called `.clang-format` 27 | in your project root directory with definitions how formatting should be done. 28 | 29 | Read documentation about Clang-Format on the official page. This tutorial only 30 | serves as a guideline on which tools you should use. 31 | 32 | * [Clang-Format documentation](https://clang.llvm.org/docs/ClangFormat.html) 33 | 34 | ### EditorConfig 35 | 36 | One part is formating existing code. Another part is formating code as you code. 37 | Many editors and IDEs will have predefined coding standards already available, 38 | and for more there is Editorconfig, a project where you can set coding style per 39 | project basis. The file `.editorconfig` with INI syntax includes definitions for 40 | files and which coding standards should be used. Most of today's editors and 41 | IDEs support EditorConfig via plugins or have support already built in. 42 | 43 | * [EditorConfig.org](http://editorconfig.org/) 44 | -------------------------------------------------------------------------------- /c/editors.md: -------------------------------------------------------------------------------- 1 | # C editors and IDEs 2 | 3 | You can write C programs in practically any text editor or IDE. Using a text editor 4 | instead of an IDE is advised at the beginning so you can fully understand the 5 | compilation process and all the magic happening behind. In this course you can 6 | use any editor you prefer. 7 | 8 | ## Editors 9 | 10 | Some editor examples: 11 | 12 | * [Atom editor](https://atom.io/) 13 | * [Visual Studio Code](https://code.visualstudio.com) 14 | 15 | ## IDEs 16 | 17 | Some IDE examples: 18 | 19 | * [CLion](https://www.jetbrains.com/clion/) 20 | * [CodeLite](https://codelite.org/) 21 | * [Netbeans](https://netbeans.org/) 22 | 23 | Difference between editor and IDE is in their functionalities. IDEs provide more 24 | functionality compared to editors, such as code refactoring, building and compiling 25 | projects, and similar. In editors you will many times need to use tools from the 26 | command line. 27 | -------------------------------------------------------------------------------- /c/files.md: -------------------------------------------------------------------------------- 1 | # File-handling 2 | -------------------------------------------------------------------------------- /c/functions.md: -------------------------------------------------------------------------------- 1 | # Functions and arguments 2 | 3 | Functions are essential part of C programs and it can contain hundreds and thousands 4 | of functions. They let you divide your code in smaller pieces so the program is 5 | more readable and maintainable. 6 | 7 | ```c 8 | #include 9 | 10 | void sayHello(void) { 11 | printf("Hello\n"); 12 | } 13 | 14 | int main(void) { 15 | sayHello(); 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /c/intro.md: -------------------------------------------------------------------------------- 1 | # Introduction to C programming 2 | 3 | ## Why should you know C programming language? 4 | 5 | * Many other programming languages are written in C; 6 | * Many modern languages are influenced by C; 7 | * PHP language and PHP extensions are written in C; 8 | * C helps you think like a computer; 9 | * Many software development tools are written in C and C++; 10 | 11 | ## What is C? 12 | 13 | C is a fundamental general purpose, widely used, compiled programming language 14 | designed by Dennis Ritchie at Bell Labs. It can be compiled to a number of 15 | platforms. It includes small number of keywords and provides large number of 16 | mathematical operators. It can be learned very quickly however to dive in more 17 | depth and to fully understand it, a lot of programming practice is required. 18 | 19 | ## C vs C++ 20 | 21 | A common ambiguity when starting with C programming is whether to start directly 22 | with C or maybe start with C++ or even something else, like objective C. 23 | 24 | At the time of this writing, when first encountering the C waters it is probably 25 | better for many to start with C instead of C++. 26 | 27 | C is also simpler to grasp, includes less core syntax features, and knowing it 28 | will help you further understand C++ in case you will want to dive deeper. 29 | 30 | According to the C++ creator, Bjarne Stroustrup, C and C++ should be a single 31 | language with C being a subset of C++. However, due to the evolution history 32 | they are now two different languages. 33 | 34 | C++ can run C code but manytimes a lot of refactoring is needed. 35 | 36 | Few key differences between C and C++: 37 | 38 | * C++ has matrices. If you want to create a matrix in C, you'll need to create 39 | a bunch of arrays. 40 | * C++ offers also object oriented paradigm. 41 | * C++ offers simpler, a more human approach to software development, where C is 42 | by many considered closer to hardware and operates on a lower level. More 43 | expertise and thinking like computer is needed with C language. 44 | 45 | C language has started before the C++ and now has a huge *install base* and a 46 | lot of that software could be rewritten in C++ for reasons of making it more 47 | modern, attractive to new comers and extendable with features, that C++ is 48 | offering. However, when putting time, cost, and historic evolution into the 49 | perspective, many project maintainers will not migrate to a language like C++ 50 | for a long time, probably never. Therefore, knowing the C language is inevitable. 51 | When starting a new project, thinking of C++ and other options is definitely the 52 | way to go. 53 | -------------------------------------------------------------------------------- /c/operators.md: -------------------------------------------------------------------------------- 1 | # Operators, tests, and user input 2 | -------------------------------------------------------------------------------- /c/php-extensions.md: -------------------------------------------------------------------------------- 1 | # PHP extensions 2 | -------------------------------------------------------------------------------- /c/see-also.md: -------------------------------------------------------------------------------- 1 | # See also 2 | 3 | C programming language for PHP developers was a very short but powerful 4 | introduction into C programming language. For becoming more *dangerous* in C, 5 | here are some more resources for you to check: 6 | 7 | ## Free books 8 | 9 | * [Free C programming language books](https://github.com/EbookFoundation/free-programming-books/blob/master/free-programming-books.md#c) 10 | 11 | ## Paid books 12 | 13 | * C Programming Language, *by Brian W. Kernighan and Dennis M. Ritchie* 14 | 15 | ## Useful resources 16 | 17 | * http://blog.llvm.org/2011/05/what-every-c-programmer-should-know.html 18 | * https://www.slideshare.net/olvemaudal/deep-c/ 19 | -------------------------------------------------------------------------------- /c/strings.md: -------------------------------------------------------------------------------- 1 | # Strings, chars, and pointers 2 | -------------------------------------------------------------------------------- /c/structs.md: -------------------------------------------------------------------------------- 1 | # Structs, enums, header files, and scope 2 | -------------------------------------------------------------------------------- /c/variables.md: -------------------------------------------------------------------------------- 1 | # Variables, constants, and types 2 | 3 | ## Variables 4 | 5 | Variable is used to store some value in your program. 6 | 7 | ```c 8 | #include 9 | 10 | int main() { 11 | int foo = 12; 12 | int bar = 56; 13 | int sum; 14 | sum = foo + bar; 15 | printf("%d + %d = %d\n", foo, bar, sum); 16 | return 0; 17 | } 18 | ``` 19 | -------------------------------------------------------------------------------- /docker/README.md: -------------------------------------------------------------------------------- 1 | # Docker for PHP developers 2 | 3 | * [Docker introduction](intro.md) 4 | * [PHP Composer with Docker development](composer.md) 5 | * [Certbot](certbot.md) 6 | * [PHP extensions](php-extensions.md) 7 | * [Permissions](permissions.md) 8 | * [Usage](usage.md) 9 | * [Building images](build.md) 10 | * [Alpine Linux](alpine.md) 11 | * [Docker recipes](recipes.md) 12 | -------------------------------------------------------------------------------- /docker/alpine.md: -------------------------------------------------------------------------------- 1 | # Alpine Linux 2 | 3 | Alpine images are frequently used with Docker because they provide a very small 4 | final Docker image size. This has an advantage when pulling base images from 5 | Docker registry, and when pushing them to the registry or production. 6 | 7 | Alpine Linux provides `apk` tool for managing packages. 8 | 9 | * [Alpine Linux package management](https://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management) 10 | 11 | ## Alpine PHP packages 12 | 13 | Alpine already offers a very good [PHP packages](https://pkgs.alpinelinux.org/packages?name=php7*) 14 | in their official repository. 15 | 16 | In Docker, you can install the PHP very easily with `apk`: 17 | 18 | ```Dockerfile 19 | FROM alpine:3.7 20 | 21 | RUN apk add --no-cache php7 22 | ``` 23 | 24 | Keep in mind that there is a separate repository for each PHP extension. For example, 25 | if you'll need `session` extension, you'll need to add the `php7-session` package: 26 | 27 | ```Dockerfile 28 | FROM alpine:3.7 29 | 30 | RUN apk add --no-cache php7 php7-session 31 | ``` 32 | 33 | ## PHP.earth Alpine repository 34 | 35 | PHP.earth Docker images provide a custom Alpine repository located at 36 | [https://repos.php.earth](https://repos.php.earth) to provide the latest PHP 37 | versions and most customizations required for the elegant PHP development with 38 | Docker. 39 | 40 | The PHP.earth Alpine repository can be used in the following way: 41 | 42 | Add the PHP.earth repository to your Dockerfile: 43 | 44 | ```Dockerfile 45 | FROM alpine:3.7 46 | 47 | ADD https://repos.php.earth/alpine/phpearth.rsa.pub /etc/apk/keys/phpearth.rsa.pub 48 | RUN echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories \ 49 | && apk add --no-cache php7.2 50 | ``` 51 | 52 | Going line by line: 53 | 54 | 1. First line made the PHP.earth 3rd party repository trusted, and is similar to 55 | this: 56 | 57 | ```bash 58 | wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub 59 | ``` 60 | 61 | 2. Then you can register the repository on APK, by adding a new line with 62 | repository link in `/etc/apk/repositories`: 63 | 64 | ```bash 65 | echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories 66 | ``` 67 | 68 | 3. To install PHP: 69 | 70 | ```bash 71 | apk add --no-cache php7.2 72 | ``` 73 | 74 | ### PHP.earth packages 75 | 76 | PHP.earth Alpine Linux repository includes the following packages: 77 | 78 | * PHP 7.2 79 | * PHP 7.1 80 | * PHP 7.0 81 | * OpenLiteSpeed 82 | * Composer 83 | * PHPUnit 84 | * Some most commonly used PECL extensions 85 | 86 | PHP packages in PHP.earth repository are prefixed with `php7.2`, `php7.1`, and 87 | `php7.0`. 88 | 89 | ```bash 90 | apk search --no-cache php7.2 91 | ``` 92 | 93 | For more information about what is included in the PHP.earth Alpine repository, 94 | visit [repos.php.earth](https://repos.php.earth). 95 | -------------------------------------------------------------------------------- /docker/build.md: -------------------------------------------------------------------------------- 1 | # Building Images 2 | 3 | Images are automatically build on [Docker Hub](https://hub.docker.com/r/phpearth/php/). 4 | 5 | Docker Cloud and therefore Docker Hub also provides 6 | [overriding and customization](https://docs.docker.com/docker-cloud/builds/advanced/) 7 | of various commands when building images automatically. 8 | 9 | There are some hooks defined in the `docker/hooks` folder of these images: 10 | 11 | * `hooks/build` - executed when building image 12 | * `hooks/post_push` - executed after building image, used to push additional tags 13 | to Docker Hub. 14 | 15 | ## Labels 16 | 17 | [Labels](https://docs.docker.com/engine/userguide/labels-custom-metadata/) are 18 | neat way to expose additional metadata about particular Docker object. We use 19 | [Label Schema](http://label-schema.org/) when defining image labels: 20 | 21 | * `build-date` - Date and time of the build. Defined as 22 | `org.label-schema.build-date=$BUILD_DATE`, where `$BUILD_DATE` is set dynamically 23 | via above `hooks/build` script 24 | * `vcs-url` - Repository location on GitHub. Defined as 25 | `org.label-schema.vcs-url="https://github.com/phpearth/docker-php.git"` 26 | * `vcs-ref` - Reference to commit in Git repository 27 | * `schema-version` - Version of the Label Schema in use. 28 | * `vendor` - Vendor name of the image creators. 29 | * `name` 30 | * `description` 31 | * `url` 32 | -------------------------------------------------------------------------------- /docker/permissions.md: -------------------------------------------------------------------------------- 1 | # Permissions 2 | 3 | Linux users and groups might seem a bit difficult to set up properly at the 4 | beginning on Docker and the host system. 5 | 6 | This guide will show some best practices how to deal with users, groups and 7 | permissions when mounting volumes and adding folders from the host to Docker 8 | images. 9 | 10 | ## What is the main issue? 11 | 12 | User from a host is a different one compared to a user within a Docker container. 13 | These two users have also different id. 14 | 15 | You can get a user id by running the `id` command: 16 | 17 | See that which process runs as which user: 18 | 19 | ```bash 20 | ps aux 21 | ``` 22 | 23 | Check the id of specific user, for example, user `www-data`: 24 | 25 | ```bash 26 | id www-data # will be "33" in Ubuntu containers/servers 27 | ``` 28 | 29 | ## Solutions 30 | 31 | ### usermod 32 | 33 | `usermod` command modifies a user account. 34 | 35 | * [usermod](http://man7.org/linux/man-pages/man8/usermod.8.html) 36 | 37 | ### chown 38 | 39 | ```bash 40 | chown -R 33 application/ 41 | ``` 42 | 43 | ### setfacl 44 | 45 | * [setfacl](http://man7.org/linux/man-pages/man1/setfacl.1.html) 46 | 47 | ### gosu 48 | 49 | * [gosu](https://github.com/tianon/gosu) 50 | 51 | ## See also 52 | 53 | Recommended read and video tutorials: 54 | 55 | * [Docker & File Permissions](https://shippingdocker.com/docker-in-development/docker-file-permissions/) 56 | * [Servers for Hackers: Linux Permissions](https://serversforhackers.com/video/linux-permissions) 57 | * [Servers for Hackers: Linux ACL](https://serversforhackers.com/video/linux-acls) 58 | * [Symfony: Setting up or Fixing File Permissions](http://symfony.com/doc/current/setup/file_permissions.html) 59 | -------------------------------------------------------------------------------- /docker/recipes.md: -------------------------------------------------------------------------------- 1 | # Docker recipes 2 | 3 | Here are shown some common examples for using these Docker PHP images. 4 | -------------------------------------------------------------------------------- /docker/usage.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | For using these images you'll usually want to create a `Dockerfile` or go further 4 | and use Docker Compose to simplify usage of multiple containers for your application. 5 | 6 | ## Dockerfile 7 | 8 | Create a `Dockerfile` for your setup: 9 | 10 | ### Alpine Nginx 11 | 12 | For images that use Alpine Linux as a base, you can create a simple Nginx container 13 | with PHP FPM in the following way: 14 | 15 | ```Dockerfile 16 | FROM phpearth/php:7.1-nginx 17 | ``` 18 | 19 | ### Alpine OpenLiteSpeed 20 | 21 | ```Dockerfile 22 | FROM phpearth/php:7.1-litespeed 23 | ``` 24 | 25 | ### PHP CLI script 26 | 27 | To run a CLI PHP script: 28 | 29 | ```bash 30 | docker run -it --rm --name my-cli-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp phpearth/php php script.php 31 | ``` 32 | 33 | ### PHP 7.2 34 | 35 | To use PHP 7.2 images just prepend the tag name with `7.2`: 36 | 37 | * `phpearth/php:7.2` 38 | * `phpearth/php:7.2-nginx` 39 | * `phpearth/php:7.2-litespeed` 40 | * `phpearth/php:7.2-apache` 41 | * `phpearth/php:7.2-cgi` 42 | 43 | ## Install PHP extensions 44 | 45 | To install additional PHP extensions, you can use our packages from the PHP.earth 46 | Alpine repository: 47 | 48 | ```Dockerfile 49 | FROM phpearth/php:7.1-nginx 50 | 51 | RUN apk add --no-cache php7.1-libsodium php7.1-mcrypt php7.1-soap 52 | ``` 53 | 54 | ## Services 55 | 56 | Best practice with Docker is to use one process per container. However sometimes 57 | you want to package multiple services into a single container for various reasons: 58 | simpler deployment, simpler usage, and similar cases. 59 | 60 | To run multiple services in a single container there are multiple ways: 61 | 62 | * Supervisord 63 | 64 | A solid solution to run and customize services. It requires Python. 65 | 66 | * runit 67 | 68 | These images use runit because for smaller usage resources and image sizes. 69 | -------------------------------------------------------------------------------- /faq/db/README.md: -------------------------------------------------------------------------------- 1 | # FAQ databases 2 | 3 | * [Why are mysql_* functions removed and what to do?](mysql-functions.md) 4 | * [PDO vs. mysqli?](mysqli-or-pdo.md) 5 | * [How to store files in a database?](files.md) 6 | * [MongoDB vs. MySQL](mongodb-vs-mysql.md) 7 | * [What is ORM?](orm.md) 8 | -------------------------------------------------------------------------------- /faq/interop/README.md: -------------------------------------------------------------------------------- 1 | # FAQ interoperability 2 | 3 | * [Which editor and IDE to choose for writing PHP code?](editor-ide.md) 4 | -------------------------------------------------------------------------------- /faq/intro/README.md: -------------------------------------------------------------------------------- 1 | # FAQ - Introduction to PHP 2 | 3 | Introduction section of the frequently asked PHP questions. 4 | 5 | * [What is PHP? Where should I start?](what-is-php.md) 6 | * [Why choosing PHP?](why-php.md) 7 | * [Which books are recommended for learning PHP?](books.md) 8 | * [Which hosting service should I use for PHP, are there any free hosting providers?](hosting.md) 9 | * [Why does PHP use a dollar sign $ to prefix variables?](dollar-sign.md) 10 | * [PHP 7](php7.md) 11 | * [What is the difference between a core and vanilla developer?](core-vs-vanilla.md) 12 | -------------------------------------------------------------------------------- /faq/intro/core-vs-vanilla.md: -------------------------------------------------------------------------------- 1 | --- 2 | redirect_from: 3 | - general/difference-core-and-vanilla 4 | - faq/core-vs-vanilla 5 | --- 6 | 7 | # What is the difference between a core PHP and a vanilla/plain PHP? 8 | 9 | While developing, there's often a confusion between a `core PHP` developer and a 10 | `vanilla/plain PHP` developer. This article will explain a difference between these terms 11 | to avoid further confusion. 12 | 13 | ## Core PHP 14 | 15 | `Core PHP` describes the main engine of the PHP language itself and doesn't mean 16 | developing something with the PHP language directly. So a core PHP 17 | developer writes C code and extends the [PHP core](https://github.com/php/php-src) 18 | or develops [PHP extensions](http://php.net/manual/en/internals2.structure.php), 19 | which are written in C programming language. Often times, core PHP is referred to 20 | as `PHP internals` also. 21 | 22 | ## Vanilla or plain PHP 23 | 24 | A `vanilla PHP developer` or `plain PHP developer` is developing an application using the PHP language 25 | without any 3rd party libraries or frameworks. So the vanilla developer actually 26 | uses the language used in the name. 27 | 28 | ## Conclusion 29 | 30 | As long as you are writing PHP code, you are a `vanilla` or `plain` PHP developer. If you are 31 | however writing on the PHP core itself, you can be considered a `core` PHP developer. 32 | 33 | ## See also 34 | 35 | * [PHP Internals Book](http://www.phpinternalsbook.com/) 36 | * [PHP Internals](https://phpinternals.net) 37 | * [What is the difference between a developer and programmer?](/faq/misc/professions.md) 38 | -------------------------------------------------------------------------------- /faq/intro/dollar-sign.md: -------------------------------------------------------------------------------- 1 | # Why does PHP use a dollar sign $ to prefix variables? 2 | 3 | Rasmus Lerdorf, the father of the PHP language, explains the `$` sign as an 4 | ability to insert variables inside literal string values (interpolation), so 5 | that the variables are distinguished from the rest of the string. A dollar sign 6 | in front of variables in PHP is inspired by Perl which greatly influenced PHP 7 | during its early years. 8 | 9 | Many other [programming languages](https://en.wikipedia.org/wiki/Dollar_sign#Use_in_computer_software) 10 | also use a dollar sign in their syntax. This symbol is called 11 | "[sigil](https://en.wikipedia.org/wiki/Sigil_(computer_programming))" and 12 | simplifies interpolation. 13 | 14 | Names not prefixed by `$` are considered constants, functions, class names, etc. 15 | 16 | Sigil usage simplifies the variable interpolation into strings: 17 | 18 | ```php 19 | 35 | 36 | Example 37 | 38 | 39 |

Page title

40 |

After the two linebreaks HTTP response output is defined.

41 | ``` 42 | 43 | In above case first three lines are HTTP headers and after two line breaks output is defined. When PHP script receives the first 44 | output (html, output from `echo` function etc) it will also flush all collected headers so far in the script procedure. Afterwards 45 | it can send all the output it wants however adding other HTTP headers will be impossible from there on. 46 | 47 | 48 | ## Checklist of possible causes and how to fix it 49 | 50 | * Whitespace or other ouput before the starting `` tag. 51 | 52 | ```php 53 | ` sections prior to `id}"; 59 | ``` 60 | 61 | Variable interpolation with curly braces can also contain complex expressions within accessors. 62 | 63 | **Example:** 64 | 65 | ```php 66 | echo "Value is {$arr[max($min, $max)]}"; 67 | ``` 68 | 69 | ### [Heredoc](http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc) 70 | 71 | - Works like double quoted strings. 72 | 73 | - It starts with `<<<`. 74 | 75 | - After this operator, an identifier is provided, then a newline. The string itself follows, and then the same identifier again to close the quotation. 76 | 77 | - You don't need to escape quotes in this syntax. 78 | 79 | 80 | ### [Nowdoc](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc) (since PHP 5.3.0) 81 | 82 | - Works essentially like single quoted strings. 83 | 84 | - The difference is that not even **single quotes** or **backslashes** have to be escaped. 85 | 86 | - A nowdoc is identified with the same `<<<` sequence used for heredocs, but the identifier which follows is enclosed in single quotes, e.g. `<<<'EOT'`. **No parsing is done in nowdoc.** 87 | 88 | 89 | ### Credit 90 | 91 | - [Peter Ajtai](http://stackoverflow.com/users/186636/peter-ajtai) - [Stackoverflow Question](http://stackoverflow.com/a/3446286) 92 | -------------------------------------------------------------------------------- /faq/misc/sms.md: -------------------------------------------------------------------------------- 1 | # How to send SMS with PHP? 2 | 3 | Sending SMS (**S**hort **M**essage **S**ervice) with PHP application is done 4 | for multiple purposes. For example, many security enhancements are integrating 5 | multi-factor authentication system where you can additionally identify user by 6 | mobile device, retrieve forgotten passwords or similar. Other common usages 7 | are sending marketing messages, or notifing users about different events and 8 | similar. 9 | 10 | ## Sending SMS via gateway 11 | 12 | The diagram below explains a simplified SMS sending flow where PHP application 13 | communicates with a SMS gateway. Gateway converts and forwards received data to 14 | SMS center (SMSC). SMSC routes data to mobile device (end user). 15 | 16 | ![Sending SMS with PHP](https://assets.php.earth/docs/general/sms.png "Sending SMS with PHP") 17 | 18 | Most common and simple to integrate usage in PHP applications is using an SMS API. 19 | 20 | ## Sending SMS via email carriers 21 | 22 | Another, less common and less stable option to send SMS is using an email from 23 | particular carrier. SMS is sent by sending an email to certain address with 24 | predefined email data. 25 | 26 | ## See also 27 | 28 | * [gnokii](https://www.gnokii.org/) - Allows you to communicate with the phone. 29 | * [Kannel](http://www.kannel.org/) - Open Source WAP and SMS gateway. 30 | * [Nexmo](https://www.nexmo.com/) - API for sending text messages. 31 | * [PHP Classes](http://www.phpclasses.org/search.html?words=sms&go_search=1) - Several 32 | solutions to send SMS with PHP. 33 | * [SMS Gateway](https://en.wikipedia.org/wiki/SMS_gateway) 34 | * [SMS Gateway Android](https://smsgateway.me/) - Turn your Android phone into a 35 | SMS Gateway. 36 | * [PlaySMS](https://playsms.org) - Free and Open Source SMS Gateway written in 37 | PHP based on Gammu SMSD service. 38 | * [Twillio](https://www.twilio.com/) - API for sending text messages. 39 | * [List of free email to SMS carriers](http://www.emailtextmessages.com) 40 | * Tutorials: 41 | * [Envato Tuts+](http://code.tutsplus.com/tutorials/how-to-send-text-messages-with-php--net-17693) - How 42 | to Send Text Messages with PHP. 43 | * [SitePoint](http://www.sitepoint.com/implement-two-way-sms-with-php/) - Implement 44 | Two-way SMS with PHP. 45 | -------------------------------------------------------------------------------- /faq/misc/undefined-variable-index-notice.md: -------------------------------------------------------------------------------- 1 | # How to fix undefined variable/index notice? 2 | 3 | A common notice when working with PHP can be: 4 | 5 | ``` 6 | Notice: Undefined variable: my_var in C:\xampp\htdocs\index.php on line 14 7 | ``` 8 | 9 | or 10 | 11 | ``` 12 | Notice: Undefined index: my_index C:\xampp\htdocs\index.php on line 24 13 | ``` 14 | 15 | ## Why does this happen? 16 | 17 | You have some lines to set a variable or get posted data from a form like this: 18 | 19 | ```php 20 | $my_var = $_POST['myPostData']; 21 | ``` 22 | 23 | Now PHP does not have `$_POST['myPostData']` if there is no POST data being sent 24 | to the Page. This is when these errors come into play. 25 | 26 | ## How to fix "Undefined variable"? 27 | 28 | ```php 29 | $my_var = ""; // Or $my_var = 0; for numbers to make sure the Variable is initialised 30 | //now use isset() 31 | $my_var = isset($_POST['myPostData']) ? $_POST['myPostData'] : ""; 32 | //or empty() 33 | $my_var = !empty($_POST['myPostData']) ? $_POST['myPostData'] : ""; 34 | ``` 35 | 36 | ## How to fix "Undefined index"? 37 | 38 | ```php 39 | //again we have two options here 40 | //via array_key_exists() 41 | $my_var = array_key_exists('my_index', $my_array) ? $my_array['my_index'] : ""; 42 | //or via isset() 43 | $my_var = isset($my_array['my_index']) ? $my_array['my_index'] : ""; 44 | ``` 45 | 46 | Note that `array_key_exists()` returns `true` when array has the specified key ignoring its value 47 | while `isset()` returns `true` only if the specified key exists and is not `null`. 48 | 49 | ```php 50 | $my_array = []; 51 | $my_array['exists'] = null; 52 | var_dump(array_key_exists('exists', $my_array)); 53 | var_dump(isset($my_array['exists'])); 54 | ``` 55 | 56 | So, you should `array_key_exists()` only in situations which `null` values are relevant, 57 | otherwise use `isset()` because it is much faster than `array_key_exists()`. 58 | 59 | ### Output 60 | ``` 61 | bool(true) 62 | bool(false) 63 | ``` 64 | 65 | ## Null coalescing operator 66 | 67 | Since PHP 7 there is also the ?? (or Null Coalescing) Operator available: 68 | 69 | ```php 70 | $my_var = $_POST['myPostData'] ?? ""; 71 | ``` 72 | -------------------------------------------------------------------------------- /faq/misc/warning-include-require-failed-stream.md: -------------------------------------------------------------------------------- 1 | # How to fix failed to open stream warning? 2 | 3 | A common warning when working with PHP can be: 4 | 5 | ``` 6 | Warning: include(myinclude.php): failed to open stream: No such file or directory in myfile.php on line 1 7 | ``` 8 | 9 | ## Why does this happen? 10 | 11 | You have some lines to include a file like this: 12 | 13 | ```php 14 | include 'myinclude.php'; 15 | ``` 16 | 17 | while your folder tree view is like this: 18 | 19 | ``` 20 | /includes/myinclude.php 21 | 22 | index.php 23 | ``` 24 | 25 | Now PHP can not find the file myinclude.php because it is not in the same directory as the index.php. 26 | 27 | ## How to fix this? 28 | 29 | A basic fix for this is setting the appropriate directory. For this example: 30 | 31 | ```php 32 | include 'includes/myinclude.php'; 33 | ``` 34 | 35 | ## What if the included file is in a different subfolder then the including file? 36 | 37 | Sometimes we have a file tree view like this: 38 | 39 | ``` 40 | files/index.php 41 | 42 | includes/myinclude.php 43 | ``` 44 | 45 | in this case a simple 46 | 47 | ```php 48 | include '../includes/myinclude.php'; 49 | ``` 50 | would do the trick, however the best practice for this case is to use script dir centric paths: 51 | 52 | ```php 53 | include __DIR__.'/../includes/myinclude.php'; 54 | ``` 55 | -------------------------------------------------------------------------------- /faq/misc/wildcard-subdomains.md: -------------------------------------------------------------------------------- 1 | # How to manage wildcard subdomains in PHP? 2 | 3 | Wildcard subdomains are used for user specific sites, Deviantart, blogspot.com 4 | are good examples. Usually DNS handles the subdomains depending on A and CNAME 5 | records. 6 | 7 | Using `.htaccess` will give control on incoming traffic (URL translation). 8 | Below `.htaccess` code will redirect any subdomain to PHP page. 9 | 10 | ```apacheconf 11 | RewriteCond %{HTTP_HOST} !^www\.domain\.com 12 | RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC] 13 | RewriteRule ^/?$ /member.php?username=%1 [L] 14 | ``` 15 | 16 | `.htacces` code will forward incoming request to `member.php` with GET method. 17 | So anyone who types `joy.domain.com` will get content of 18 | `domain.com/member.php?username=joy`. By using SQL query you can verify if the 19 | username exists or not. 20 | 21 | ```php 22 | $sth = $dbh->prepare("SELECT * FROM user WHERE username=:username"); 23 | $sth->bindParam(':username', $username, PDO::PARAM_STR); 24 | $sth->execute(); 25 | $result = $sth->fetch(PDO::FETCH_ASSOC); 26 | if ($result) { 27 | // show user data 28 | } else { 29 | // show 404 page 30 | } 31 | ``` 32 | -------------------------------------------------------------------------------- /interop/README.md: -------------------------------------------------------------------------------- 1 | # Interoperability 2 | 3 | * [Atom editor for PHP developers](atom.md) 4 | * [What is GIT?](git.md) 5 | * [Which libraries and resources are recommended for use with PHP?](intro.md) 6 | * [Nopaste list and services to share and run code online](nopaste.md) 7 | * [Vagrant tutorial](vagrant.md) 8 | * [Web assets (images, JavaScript, CSS files)](assets.md) 9 | * [Performance benchmarks and load testing](benchmarks.md) 10 | * [Managing projects with Make and Makefiles](make.md) 11 | -------------------------------------------------------------------------------- /interop/assets.md: -------------------------------------------------------------------------------- 1 | # Web assets (images, JavaScript, CSS files) 2 | 3 | Assets are front end and static files such as CSS stylesheets, JavaScript files, 4 | images and similar. 5 | 6 | There are multiple approaches you can check out when working with these files in 7 | your PHP application. 8 | 9 | Handling these files usually includes installation from 3rd party location (GitHub), 10 | and copying the required files to your publicly accessible folder, such as `web`, 11 | `public_html` and similar. 12 | 13 | After installation you usually also want to minimize JavaScript and CSS files. 14 | 15 | For images maybe you need to create favicons for multiple devices from source 16 | logo of the website and similar. 17 | 18 | * [Assetic](https://github.com/kriswallsmith/assetic) 19 | * [Composer](https://getcomposer.org) 20 | * [Bower](https://bower.io/) 21 | * [BowerPHP](https://bowerphp.org/) 22 | * [Grunt](http://gruntjs.com/) 23 | * [NPM](http://npmjs.com/) and [Gulp](http://gulpjs.com/) 24 | * [Robo](http://robo.li/) 25 | * [Webpack](https://webpack.github.io/) 26 | 27 | Many developers also use approach of developing a project with two separate 28 | repositories - one for back end (PHP application) and one for front end. 29 | 30 | The API points in the back end part are connected with the front end. Maintaining 31 | and scaling to application requirements can be much easier. 32 | 33 | ## Content delivery network (CDN) 34 | 35 | High traffic and complex sites many times also create a separated CDN for serving 36 | these static files. This can improve the performance since the asset is downloaded 37 | only once from a separate location. 38 | 39 | For many open source front end libraries, many times using a publicly available 40 | CDNs is advices since it reduces the required number of requests and traffic for 41 | your application. 42 | 43 | ## See also 44 | 45 | * [Wikipedia: CDN](https://en.wikipedia.org/wiki/Content_delivery_network) 46 | * [Gulp: Refreshment for Your Frontend Assets](http://knpuniversity.com/screencast/gulp) 47 | * [Sitepoint: A PHP Front End Workflow without Node.js](https://www.sitepoint.com/look-ma-no-nodejs-a-php-front-end-workflow-without-node/) 48 | -------------------------------------------------------------------------------- /interop/benchmarks.md: -------------------------------------------------------------------------------- 1 | # Performance benchmarks and load testing 2 | 3 | Benchmarking your application is important to see how the application performs 4 | under heavier traffic and load. 5 | 6 | ## Apache HTTP server benchmarking tool 7 | 8 | Very common benchmarking tool you can use is [ab](https://httpd.apache.org/docs/2.4/programs/ab.html). 9 | 10 | ```bash 11 | ab -c 10 -n 1000 http://localhost/ 12 | ``` 13 | 14 | ### Authentication 15 | 16 | Stage and beta environments can be sometimes closed for public with HTTP authentication. 17 | To pass username and password: 18 | 19 | ```bash 20 | ab -c 10 -n 1000 -A username:password http://beta.example.org/ 21 | ``` 22 | 23 | ## Siege 24 | 25 | [Siege](https://www.joedog.org/siege-home/) is an HTTP load testing and 26 | benchmarking tool. Its source code is available on [GitHub](https://github.com/JoeDog/siege). 27 | 28 | ```bash 29 | siege -c 10 -r 100 -b -i http://localhost 30 | ``` 31 | 32 | ## JMeter 33 | 34 | [Apache JMeter](http://jmeter.apache.org/) is a more feature rich load tester. 35 | 36 | ## Gatling 37 | 38 | [Gatling](http://gatling.io) is a load tester with GUI. 39 | 40 | ## HTTP keep-alive 41 | 42 | [HTTP keep-alive](https://en.wikipedia.org/wiki/HTTP_persistent_connection) or 43 | HTTP persistent connections greatly improve performance. In performance testing 44 | you can enable them and get better results, however these vary from one testing 45 | software to another. Good practice is to disable them and get comparable results 46 | among the above tests. 47 | -------------------------------------------------------------------------------- /interop/intro.md: -------------------------------------------------------------------------------- 1 | # Which are recommended libraries and resources to use with PHP? 2 | 3 | To successfully develop applications here are some recommended development 4 | libraries and resources you will like and can enrich experience. 5 | 6 | * AJAX: 7 | * [Backbone.js](http://backbonejs.org/) - Structure to web applications that 8 | involve JavaScript and data. 9 | * [jQuery](http://jquery.com/) - Useful JavaScript library for easier AJAX, 10 | HTML document traversal and manipulation, event handling, animation etc. 11 | * File upload: 12 | * [Dropzone.js](http://www.dropzonejs.com/) - Drag'n'drop file uploads. 13 | * User interface: 14 | * [Semantic UI](http://semantic-ui.com/) - Framework that helps you create 15 | beautiful, responsive layouts using human-friendly HTML. 16 | -------------------------------------------------------------------------------- /js/README.md: -------------------------------------------------------------------------------- 1 | # JavaScript for PHP developers 2 | 3 | * [Introduction](intro.md) 4 | * [Debugging front end JavaScript](debugging.md) 5 | -------------------------------------------------------------------------------- /js/debugging.md: -------------------------------------------------------------------------------- 1 | # Debugging front end JavaScript 2 | 3 | ## console.log 4 | 5 | A simple and relatively effective way to debug your front end JavaScript code is 6 | to add the `console.log(var)` to parts where you want to check if the output 7 | matches the expected value. Similar technique as adding break points to your 8 | code. 9 | 10 | The `console.log` output is visible in the browser's console: 11 | 12 | For Google Chrome and Mozilla Firefox you can acceess the developer tools by 13 | pressing the `Control+Shift+I` (on Linux and Windows) or `Command+Option+I` (on 14 | Mac), and find the console tab. 15 | 16 | ## Chrome Developer Tools 17 | 18 | As a next a bit more advanced step, Chrome browser has by default integrated 19 | the developer tools to debug front end code more quickly and efficiently. 20 | 21 | ## Regular expressions 22 | 23 | To debug regular expressions on the fly, you can use the online free regex tool 24 | and debugger at [Regex 101](https://regex101.com). 25 | 26 | ## See alo 27 | 28 | * [Debugging JavaScript with Chrome DevTools](https://developers.google.com/web/tools/chrome-devtools/javascript/) 29 | -------------------------------------------------------------------------------- /js/intro.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | 3 | To successfully develop applications here are some recommended development 4 | libraries and resources you will like and can enrich experience. 5 | 6 | * JavaScript basics 7 | * [JavaScript.info](http://javascript.info) - modern JavaScript tutorial. 8 | * [Knp University](https://knpuniversity.com/screencast/javascript-es6) - JavaScript 9 | for PHP Geeks:ES6/ES2015 (New JavaScript) 10 | * [MDN: JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference) 11 | * AJAX: 12 | * [Backbone.js](http://backbonejs.org/) - Structure to web applications that 13 | involve JavaScript and data. 14 | * [jQuery](http://jquery.com/) - Useful JavaScript library for easier AJAX, 15 | HTML document traversal and manipulation, event handling, animation etc. 16 | * File upload: 17 | * [Dropzone.js](http://www.dropzonejs.com/) - Drag'n'drop file uploads. 18 | * User interface: 19 | * [Semantic UI](http://semantic-ui.com/) - Framework that helps you create 20 | beautiful, responsive layouts using human-friendly HTML. 21 | * [Awesome JavaScript](https://github.com/sorrycc/awesome-javascript) 22 | * [If we chose our JavaScript Framework like we chose our music…](https://www.sitepen.com/blog/2017/06/13/if-we-chose-our-javascript-framework-like-we-chose-our-music/) - 23 | JavaScript front end frameworks comparison by Sitepen 24 | -------------------------------------------------------------------------------- /linux/README.md: -------------------------------------------------------------------------------- 1 | # Linux 2 | 3 | ## [PHP.earth Alpine Linux repository](alpine.md) 4 | 5 | PHP.earth includes a repository for installing latest PHP packages 6 | and several PECL extensions on Alpine Linux. 7 | -------------------------------------------------------------------------------- /linux/alpine.md: -------------------------------------------------------------------------------- 1 | --- 2 | description: "Alpine repository with PHP 7.2, PHP 7.1, PHP 7.0, and additional packages for elegant PHP development experience" 3 | --- 4 | 5 | # PHP.earth Alpine Linux repository 6 | 7 | This repository includes packages with the latest PHP versions and some most 8 | commonly used PECL extensions for the elegant PHP development experience on 9 | [Alpine Linux](https://alpinelinux.org/). 10 | 11 | ## Quick usage 12 | 13 | On Alpine Linux add a PHP.earth repository and make it trusted: 14 | 15 | ```bash 16 | apk add --no-cache wget ca-certificates \ 17 | && wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub \ 18 | && echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories 19 | ``` 20 | 21 | PHP.earth packages are prefixed with `php7.2`, `php7.1`, and `php7.0`: 22 | 23 | ```bash 24 | apk search --no-cache php7.2* 25 | ``` 26 | 27 | ## Requirements 28 | 29 | * Alpine Linux `3.7` 30 | 31 | ## Detailed instructions 32 | 33 | ### Repository installation 34 | 35 | Let's go through repository installation step by step. Before adding the 36 | repository, add wget and common CA certificates PEM files in case they haven't 37 | been added yet. This will enable downloading files from the HTTPS locations. 38 | 39 | ```bash 40 | apk add --no-cache wget ca-certificates 41 | ``` 42 | 43 | Making the repository trusted is done by downloading the public key: 44 | 45 | ```bash 46 | wget -O /etc/apk/keys/phpearth.rsa.pub https://repos.php.earth/alpine/phpearth.rsa.pub 47 | ``` 48 | 49 | Last step is registering the repository on APK by appending a new line in 50 | `/etc/apk/repositories`: 51 | 52 | ```bash 53 | echo "https://repos.php.earth/alpine/v3.7" >> /etc/apk/repositories 54 | ``` 55 | 56 | ## Sources 57 | 58 | PHP.earth Alpine Linux repository is located on [GitHub](https://github.com/phpearth/alpine). 59 | -------------------------------------------------------------------------------- /misc/README.md: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | 3 | ## [PHP frameworks](/misc/frameworks) 4 | 5 | Using a framework can help speeding up and improving the application. Find out 6 | which framework to learn and how to create your custom framework. 7 | 8 | ## [PHP E-commerce systems](/misc/ecommerce) 9 | 10 | There are quite a lot of existing open source very good solutions for eCommerce 11 | purposes currently available in PHP. 12 | 13 | ## [Packages, libraries and managing dependencies](/misc/packages) 14 | 15 | PHP ecosystem of open source code from various resources. 16 | 17 | ## [API](/misc/api) 18 | 19 | Application programming interfaces 20 | 21 | ## [Code quality and testing](/misc/quality) 22 | 23 | How to test and write quality PHP code. 24 | 25 | ## [How to deploy PHP application](deployment.md) 26 | 27 | Get your application into production. 28 | 29 | ## [PHP versions usage](versions.md) 30 | 31 | Upgrade your PHP. 32 | 33 | ## [Open source licenses](licenses.md) 34 | 35 | What is a license and which license should you pick for your open source project. 36 | 37 | ## [Asynchronous PHP](async.md) 38 | 39 | Asynchronous programming in PHP. 40 | -------------------------------------------------------------------------------- /misc/api/README.md: -------------------------------------------------------------------------------- 1 | # API 2 | 3 | * [What is API?](intro.md) 4 | * [What is REST?](rest.md) 5 | * [What is SOAP?](soap.md) 6 | -------------------------------------------------------------------------------- /misc/api/intro.md: -------------------------------------------------------------------------------- 1 | # What is API? 2 | 3 | [API](https://en.wikipedia.org/wiki/Application_programming_interface), which 4 | stands for "Application programming interface", is a set of routines, 5 | protocols, and tools for building software applications. 6 | 7 | ## Useful tools 8 | 9 | * [Apiary](https://apiary.io) - API Design Stack built for developers. 10 | * [Swagger](http://swagger.io) - Swagger is a simple yet powerful 11 | representation of your RESTful API. 12 | 13 | ## Documenting 14 | 15 | * [ApiBlueprint](https://apiblueprint.org) - A powerful, high-level API 16 | description language for web APIs. 17 | 18 | ## See also 19 | 20 | Useful frameworks, libraries, and reading material for building APIs. 21 | 22 | * [API Platform](https://api-platform.com/) - API-first web framework on top of 23 | Symfony with JSON-LD, Schema.org and Hydra support. 24 | * [Apigility](https://github.com/zfcampus/zf-apigility-skeleton) - An API 25 | builder built with Zend Framework 2. 26 | * [DC4D](http://daycamp4developers.com/previous-meetings/building-apis-developers-will-love-and-use/) - 27 | Building APIs developers will love and use, free video tutorials about APIs. 28 | Registration required though. 29 | * [HAL](https://github.com/blongden/hal) - A HAL (Hypertext Application 30 | Language) builder library. 31 | * [Insomnia](https://insomnia.rest/) - Free REST API client. 32 | * [Negotiation](https://github.com/willdurand/Negotiation) - A content 33 | negotiation library. 34 | * [Undisturbed REST: A Guide to Designing the Perfect API](http://mulesoft.com/restbook) 35 | * [Lumen: The stunningly fast micro-framework by Laravel.](https://lumen.laravel.com/) 36 | * [Slim: Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.](http://www.slimframework.com/) 37 | * [API Security Checklist](https://github.com/shieldfy/API-Security-Checklist) - 38 | Checklist of the most important security countermeasures when designing, testing, and releasing your API. 39 | * [RapidAPI](https://rapidapi.com/) - API marketplace to find, test and connect 40 | to all sorts of APIs. 41 | -------------------------------------------------------------------------------- /misc/api/rest.md: -------------------------------------------------------------------------------- 1 | # What is REST? 2 | 3 | REST stands for "Representational State Transfer." It was claimed by 4 | [Roy Fielding](https://twitter.com/fielding) in his doctor dissertation in 5 | 2000. 6 | 7 | ## What is the difference between REST and RESTful? 8 | 9 | The term RESTful refers to web services implementing such a REST architecture. 10 | 11 | ## See also 12 | 13 | PHP libraries and resources to checkout. 14 | 15 | * [Bullet PHP](http://bulletphp.com/) - A micro framework for building REST 16 | APIs. 17 | * [Hateoas](https://github.com/willdurand/Hateoas) - PHP library to support 18 | implementing representations for HATEOAS REST web services. 19 | * [RESTful APIs, the big lie](http://mmikowski.github.io/the_lie/) - Technical 20 | critique which introduces some issues of REST and how JSON-Pure APIs could do 21 | better, with a [follow-up article](http://mmikowski.github.io/json-pure/). 22 | * [Restler](https://github.com/Luracast/Restler) - A lightweight framework to 23 | expose PHP methods as RESTful web APIs. 24 | * [Fusio](http://fusio-project.org) - Fusio is an open source API management 25 | platform which helps to build and manage REST APIs. 26 | * [Slim](http://www.slimframework.com) - Slim is a PHP micro framework that 27 | helps you quickly write simple yet powerful web applications and APIs. 28 | * [Api Platform](https://api-platform.com) - The ultimate PHP framework to 29 | build modern web APIs. 30 | -------------------------------------------------------------------------------- /misc/api/soap.md: -------------------------------------------------------------------------------- 1 | # What is SOAP and how to use it in PHP? 2 | 3 | [SOAP](https://en.wikipedia.org/wiki/SOAP) (Simple Object Access protocol) is a 4 | protocol specification for web services that exchange information in the form 5 | of an XML Information Set. 6 | 7 | ## See also 8 | 9 | Libraries and reading material to check out. 10 | 11 | * [NuSOAP](http://nusoap.sourceforge.net/) - SOAP Toolkit for PHP. 12 | * [PHP SOAP extension manual](http://php.net/manual/en/book.soap.php) 13 | * [Zend\\Soap](https://github.com/zendframework/zend-soap) - Standalone Zend 14 | SOAP component. 15 | -------------------------------------------------------------------------------- /misc/async.md: -------------------------------------------------------------------------------- 1 | # Asynchronous PHP 2 | 3 | ## What is the difference between synchronous and asynchronous programming? 4 | 5 | *Synchronous programming* is the most common and used way of writing and executing 6 | code. Code is executed statement by statement. Next statements don't get started 7 | until the previous statement is complete. 8 | 9 | In asynchronous programming statements can start to perform before other 10 | statements are completed. Total time is reduced by minimizing the time spent 11 | waiting for operations to complete. 12 | 13 | Main issue with asynchronous methodology is the dependency between the so called 14 | callbacks. 15 | 16 | ## Terminology 17 | 18 | To properly understand and have common grounds on this topic, some of the common 19 | terms will be explained below. 20 | 21 | * **Concurency** 22 | 23 | Concurency is ability of different program elements to be executed any order. 24 | 25 | * **Coroutine** 26 | 27 | Coroutines are program blocks (for example, functions), that can be suspened 28 | and resumed during the program execution. 29 | 30 | ## Asynchronous programming in PHP 31 | 32 | PHP doesn't provide any optimal means for asynchronous programming yet 33 | out-of-the-box. This can be solved using 3rd party PECL extensions or PHP 34 | libraries. 35 | 36 | ## Standards 37 | 38 | The [PHP Asynchronous Interoperability Group](https://github.com/async-interop) 39 | has been formed to propose standards to PHP-FIG one day. 40 | 41 | ## PHP libraries 42 | 43 | * [React PHP](https://reactphp.org/) 44 | 45 | ## PECL extensions 46 | 47 | * [Swoole](https://www.swoole.co.uk) 48 | 49 | ## See also 50 | 51 | Further resources to study the *asynchronous* topic in more details: 52 | 53 | * [PHP Roundtable: Asynchronous PHP](https://www.phproundtable.com/episode/asynchronous-php) 54 | * [elazar/asynchronous-php](https://github.com/elazar/asynchronous-php) - List 55 | of resources for asynchronous programming in PHP. 56 | * [The Magic Behind Async PHP](https://blog.kelunik.com/2017/11/06/magic-behind-async-php.html) 57 | -------------------------------------------------------------------------------- /misc/ecommerce/README.md: -------------------------------------------------------------------------------- 1 | # PHP E-commerce systems 2 | 3 | * [Which eCommerce application should I use or which framework to use for building eCommerce applications?](intro.md) 4 | * [ShopWare](shopware) 5 | * [Magento](magento) 6 | -------------------------------------------------------------------------------- /misc/ecommerce/intro.md: -------------------------------------------------------------------------------- 1 | # Which eCommerce application should I use or which framework to use for building eCommerce application? 2 | 3 | Same question as with frameworks, CMSes and similar open source solutions comes as well with which eCommerce PHP application to use. 4 | 5 | There are quite a lot of existing open source very good solutions for eCommerce purposes currently available in PHP. Choosing the right one 6 | for the project or a right PHP framework for eCommerce depends on your knowledge and project specifics. 7 | 8 | Some of popular eCommerce solutions: 9 | 10 | * [Magento](http://magento.com/) 11 | * [Magento @ PHP.earth](/misc/ecommerce/magento) 12 | * [ShopWare](http://shopware.com/) 13 | * [ShopWare @ PHP.earth](/misc/ecommerce/shopware) 14 | * [OpenCart](http://www.opencart.com/) 15 | * [Prestashop](http://www.prestashop.com/) 16 | * [Sylius](http://www.sylius.org/) 17 | * [Virtuemart](http://virtuemart.net/) 18 | * [ZenCart](http://www.zen-cart.com/) 19 | -------------------------------------------------------------------------------- /misc/ecommerce/magento/README.md: -------------------------------------------------------------------------------- 1 | # Magento 2 | 3 | Magento is an e-commerce system developed by Magento Inc. The development started 4 | in 2007 and is in active development. Magento 2 was released in November 2015. 5 | 6 | ## In this Section 7 | [About Magento](about-magento.md) 8 | -------------------------------------------------------------------------------- /misc/ecommerce/magento/about-magento.md: -------------------------------------------------------------------------------- 1 | # What is Magento? 2 | 3 | Magento is an e-commerce system developed by Magento Inc. The development started 4 | in 2007 and is in active development. Magento 2 was released in November 2015. 5 | 6 | ## Versions 7 | 8 | Magento has three different versions, two of which are paid and one of which is free of cost to use. 9 | 10 | ### Open Source Edition 11 | 12 | Magento Open Source is the free of charge version of the Magento e-commerce platform. 13 | The Open Source Edition can be added upon with paid or free plugin modules (self developed or provided by other developers). 14 | It provides a basic e-commerce system with all you need to operate. 15 | This version doesn't include Hosting. 16 | 17 | ### Magento Commerce Edition 18 | 19 | First released in April 2016, the Magento Commerce Edition is served as a "platform as a service". 20 | In Magento 2, the Commerce Edition has improved architecture and development tools. 21 | 22 | With tools like Magento Business Intelligence, a detailed analysis of your customers, products and promotions can 23 | help you to analyze where your shop needs some adjustments. 24 | 25 | ### Magento Commerce (On-Premises) Edition 26 | 27 | The Magento Commerce (On-Premises) Edition is a derivate of the Open Source Edition and comes with more features and 28 | functionalities then the Open Source Edition as well as technical support for the installation, usage, configuration and 29 | debugging of problems. 30 | 31 | This makes it especially useful for large companies with shops that have a high throughput of customers and orders per day. 32 | The Magento Commerce Edition is developed by the Magento team with the additions which are requested by the users and 33 | third parties. 34 | This version doesn't include Hosting. 35 | 36 | ## Plugins 37 | 38 | Magento has a plugin module system which offers the availability to add to or change Magento's standard behaviour. 39 | 40 | Plugins can be developed by yourself or by third party developers. 41 | 42 | ## Templates/Designs 43 | 44 | For the Frontend part, Magento uses a Model-View-Controller (MVC) Pattern as well as a Model-View-ViewModel (MVVM) Pattern 45 | and the JavaScript library Knockout.js. 46 | -------------------------------------------------------------------------------- /misc/ecommerce/shopware/README.md: -------------------------------------------------------------------------------- 1 | # ShopWare 2 | 3 | ShopWare is an e-commerce system developed by the German "ShopWare AG". The development started 4 | in 2004 and is in active development. 5 | 6 | ## In this Section 7 | [About ShopWare](about-shopware.md) 8 | -------------------------------------------------------------------------------- /misc/ecommerce/shopware/about-shopware.md: -------------------------------------------------------------------------------- 1 | # What is ShopWare? 2 | 3 | ShopWare is an e-commerce system developed by the German "ShopWare AG". The development started 4 | in 2004 and is in active development. 5 | 6 | ## Versions 7 | 8 | ShopWare offers different versions for subscription: 9 | 10 | ### Community Edition 11 | 12 | The community edition is open-source and free to use without any limitation. It has the same 13 | features as the paid versions and can be added upon with free and paid plugins from the community store. 14 | ShopWare doesn't offer any guarantee or maintenance for the community edition 15 | 16 | ### Professional Edition 17 | 18 | The professional edition offers a guarantee by ShopWare as well as support via the developers. It also adds 19 | the otherwise paid plugins "Storytelling" and "Digital Publishing" for emotional shopping. This version 20 | comes with an ERP-System. 21 | 22 | ### Professional Plus Edition 23 | 24 | The professional plus edition comes with all features of the professional edition plus all "premium plugins" 25 | made by the ShopWare developers which add a lot of features for the marketing of your shop. 26 | 27 | ### Enterprise Edition 28 | 29 | The enterprise edition supports high traffic as well as B2B features and a 24/7 developer support with the 30 | option of personal assistance. 31 | 32 | ## Plugins 33 | 34 | ShopWare offers a plugin system with which you can develop your own plugins to alter the shops behaviour 35 | and design as well as adding functionalities. 36 | 37 | Plugins can be developed on your own using PHP, ExtJS/JS/jQuery, Smarty and LESS. Plugins are also available 38 | for free or paid from the ShopWare community store. 39 | 40 | ## Templates/Designs 41 | 42 | For templating, ShopWare uses the templating engine Smarty and for the designing ShopWare uses LESS files, 43 | which are compiled into a minified form. 44 | -------------------------------------------------------------------------------- /misc/frameworks/README.md: -------------------------------------------------------------------------------- 1 | # PHP frameworks 2 | 3 | * [What is a PHP framework and which one should I learn and use?](frameworks.md) 4 | * [How to make your own PHP framework?](create-your-own-framework.md) 5 | * [Cake PHP](cakephp.md) 6 | * [CodeIgniter](codeigniter.md) 7 | * [Laravel](laravel.md) 8 | * [Symfony](symfony.md) 9 | * [Yii](yii.md) 10 | * [Zend Framework](zendframework.md) 11 | -------------------------------------------------------------------------------- /misc/frameworks/cakephp.md: -------------------------------------------------------------------------------- 1 | # CakePHP framework 2 | 3 | [CakePHP](http://cakephp.org/) is a MVC Rapid Development Framework for PHP. 4 | 5 | ## See also 6 | 7 | * [Awesome CakePHP](https://github.com/friendsofcake/awesome-cakephp) - A 8 | curated list of amazingly awesome CakePHP plugins, resources and shiny 9 | things. 10 | * [Friends of CakePHP](http://friendsofcake.com/) - Group of dedicated CakePHP 11 | developers working together to provide the CakePHP community with high 12 | caliber CakePHP plugins and resources. 13 | -------------------------------------------------------------------------------- /misc/frameworks/codeigniter.md: -------------------------------------------------------------------------------- 1 | # CodeIgniter framework 2 | 3 | [CodeIgniter](http://www.codeigniter.com/) is a powerful PHP framework with a 4 | very small footprint, built for developers who need a simple and elegant 5 | toolkit to create full-featured web applications. 6 | 7 | CodeIgniter has a lean MVC framework, with enough capabilities to improve 8 | productivity, while providing for third-party addons/plugins for additional 9 | functionality. 10 | 11 | ## See also 12 | 13 | * [Documentation](http://www.codeigniter.com/user_guide/) - CodeIgniter User Guide. 14 | * [Github](https://github.com/bcit-ci/CodeIgniter) - Codeigniter Repo 15 | * [Download](https://www.codeigniter.com/download)- Codeigniter Download Link 16 | * [Forum](http://forum.codeigniter.com/)-Support & Discuss 17 | -------------------------------------------------------------------------------- /misc/frameworks/create-your-own-framework.md: -------------------------------------------------------------------------------- 1 | # How to make your own PHP framework? 2 | 3 | Building your own framework can be useful for the following reasons: 4 | 5 | * You can learn a lot - advanced design patterns, concepts and software 6 | architecture. 7 | * You know exactly what certain parts of your code do without learning from the 8 | documentation of others. 9 | 10 | However, on the PHP market there are many very high quality open source 11 | frameworks that many projects and organizations use to build software faster 12 | and better. Picking an established open source framework has its benefits: 13 | 14 | * When working in a team, people that already know the open source framework 15 | used by a project can join the project faster. 16 | * Better quality and a lot of bugs that have been identified and fixed, that 17 | your custom framework hasn't been tested for in a many projects yet. 18 | 19 | ## What knowledge you will need to create a decent framework? 20 | 21 | For creating a framework you will have to know OOP, design patterns, ORM, 22 | authentication, MVC (model view controller) and other advanced concepts. 23 | 24 | ## See also 25 | 26 | Here are listed some useful resources and tutorials that can also help you 27 | create your own modern and quality PHP framework. 28 | 29 | * [Building your own framework on top of Symfony components](http://symfony.com/doc/current/create_framework/index.html) - 30 | Build a modern PHP framework on top of quality Symfony components. 31 | * [Frameworkless](https://medium.com/@mmeyer/frameworkless-or-how-i-use-php-bf0b119536ad) - 32 | Tutorial how to create custom framework with Composer and PHP packages and 33 | components. 34 | * [No Framework tutorial](https://github.com/PatrickLouys/no-framework-tutorial) 35 | * [PHP Frameworking](http://phpocean.com/tutorials/back-end/php-frameworking-introduction-part-1/9) - 36 | Introduction to frameworks and how to create your own framework. 37 | * [Modern PHP without framework](https://kevinsmith.io/modern-php-without-a-framework) 38 | -------------------------------------------------------------------------------- /misc/frameworks/laravel.md: -------------------------------------------------------------------------------- 1 | # Laravel framework 2 | 3 | [Laravel](http://laravel.com/) is popular and simple to use component based PHP 4 | framework. 5 | 6 | ## See also 7 | 8 | Some useful resources to check when learning and working with Laravel: 9 | 10 | * [Awesome Laravel](https://github.com/chiraggude/awesome-laravel) - A curated 11 | list of bookmarks, packages, tutorials, videos and other cool resources from 12 | the Laravel ecosystem. 13 | * [Laracasts](https://laracasts.com/) - Laravel video tutorials, free and paid. 14 | * [Laravel News](https://laravel-news.com/) 15 | -------------------------------------------------------------------------------- /misc/frameworks/symfony.md: -------------------------------------------------------------------------------- 1 | # Symfony framework 2 | 3 | [Symfony](http://symfony.com) is a set of reusable PHP components and a framework. 4 | 5 | Best way to get to know Symfony is to go through a 6 | [quick tour](http://symfony.com/doc/current/quick_tour/index.html) - four 7 | chapters, each 10 minutes long. After that, reading the 8 | [documentation](http://symfony.com/doc/current/index.html) is advised and is 9 | the best way to learn it thoroughly. 10 | 11 | Symfony uses bundles for applications and to extend and reuse functionality in 12 | them. A large and vibrant community that has evolved around Symfony provides 13 | bundles for almost anything. They can be found at 14 | [KpnBundles](http://knpbundles.com/). 15 | 16 | You can also get [certified](https://sensiolabs.com/en/symfony/certification.html) 17 | or meet the community at one of the [Symfony events](http://symfony.com/events/). 18 | 19 | ## See also 20 | 21 | Useful resources and tutorials when working with Symfony: 22 | 23 | * [Awesome Symfony](https://github.com/sitepoint/awesome-symfony) - A list of 24 | awesome Symfony bundles, utilities and resources. 25 | * [Knp University](http://knpuniversity.com/) - PHP and Symfony Tutorials (paid 26 | and free). 27 | * [Screenfony](http://www.screenfony.com/) - Symfony tutorials (paid). 28 | * [Symfony2cheatsheet](http://www.symfony2cheatsheet.com/) - Symfony 29 | cheatsheet. 30 | * [Working with Symfony 2 - Tuts+](http://code.tutsplus.com/series/working-with-symfony-2--cms-636) - 31 | A video course about building applications in Symfony. 32 | * [Symfony Tutorial](https://www.cloudways.com/blog/category/applications/symfony/) - 33 | Category for Symfony Tutorial. 34 | * [Symfony Finland](https://www.symfony.fi/) - PHP, Symfony and web development 35 | articles. 36 | -------------------------------------------------------------------------------- /misc/frameworks/yii.md: -------------------------------------------------------------------------------- 1 | # Yii framework 2 | 3 | [Yii](http://www.yiiframework.com/) is a high-performance PHP framework. 4 | 5 | ## Resources 6 | 7 | * [Documentation](http://www.yiiframework.com/doc/) 8 | 9 | ## See also 10 | 11 | * [Introduction to the Yii Framework](http://code.tutsplus.com/articles/introduction-to-the-yii-framework--cms-20948) 12 | * [How to Program With Yii2](http://code.tutsplus.com/series/how-to-program-with-yii2) 13 | * [Yii2 Developer Exchange](http://yii2x.com/) 14 | * [Yii Tutorials](https://www.cloudways.com/blog/category/applications/yii/) 15 | -------------------------------------------------------------------------------- /misc/frameworks/zendframework.md: -------------------------------------------------------------------------------- 1 | # Zend framework 2 | 3 | [Zend Framework](http://framework.zend.com/) - Enterprise and component based 4 | PHP Framework from Zend. 5 | 6 | ## See also 7 | 8 | * [Documentation](http://framework.zend.com/manual/current/en/index.html) - 9 | Zend Framework 2 programmer's reference guide. 10 | * [Zend Framework Certification](http://www.zend.com/en/services/certification/framework) 11 | -------------------------------------------------------------------------------- /misc/licenses.md: -------------------------------------------------------------------------------- 1 | # Open source licenses 2 | 3 | ## What is a license and why should you pick one for your project? 4 | 5 | When open sourcing your code project you should always pick an appropriate license 6 | for it. 7 | 8 | There are a lot of open source licenses available that fit a lot of use cases. 9 | 10 | * MIT License 11 | * [Creative Commons Attribution-ShareAlike 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/legalcode) 12 | 13 | ## See also 14 | 15 | * [Coding Horror blog post](http://blog.codinghorror.com/pick-a-license-any-license/) 16 | * [Choose a license](http://choosealicense.com/) 17 | * [The MIT License, Line by Line](https://writing.kemitchell.com/2016/09/21/MIT-License-Line-by-Line.html) 18 | * [TL;DR Legal](https://tldrlegal.com/) 19 | -------------------------------------------------------------------------------- /misc/packages/README.md: -------------------------------------------------------------------------------- 1 | # Packages, libraries and managing dependencies 2 | 3 | * [What is Composer?](composer.md) 4 | * [What is a CMS and which one should I use?](cms.md) 5 | * [How to work with Excel in PHP?](excel.md) 6 | * [Are there any image manipulation libraries in PHP? Which ones are good?](image-libraries.md) 7 | * [How to add pagination?](pagination.md) 8 | * [What is a payment gateway? How to integrate and use payment gateways in PHP?](payment-gateways.md) 9 | * [How to work with PDF files in PHP?](pdf.md) 10 | * [PHP packages](packages.md) 11 | -------------------------------------------------------------------------------- /misc/packages/image-libraries.md: -------------------------------------------------------------------------------- 1 | # Are there any image manipulation libraries in PHP? Which ones are good? 2 | 3 | Resources and image libraries: 4 | 5 | * [PHP's GD manual](http://php.net/manual/en/book.image.php) - PHP manual about image processing, generation and GD 6 | * [Imagine](https://github.com/avalanche123/Imagine) - PHP 5.3+ Object Oriented image manipulation library 7 | * [Image](https://github.com/Gregwar/Image) - PHP Image library 8 | -------------------------------------------------------------------------------- /misc/packages/pagination.md: -------------------------------------------------------------------------------- 1 | # How to add pagination? 2 | 3 | ## See also 4 | 5 | Some useful libraries and resources to check out: 6 | 7 | * [PagerFanta](https://github.com/whiteoctober/Pagerfanta) - Useful pagination library for PHP. 8 | * [KnpPaginatorBundle](https://github.com/KnpLabs/KnpPaginatorBundle) - Pagination bundle for Symfony2 9 | -------------------------------------------------------------------------------- /misc/packages/payment-gateways.md: -------------------------------------------------------------------------------- 1 | # What is payment gateway? How to integrate and use payment gateways in PHP? 2 | 3 | Payment gateways are e-commerce application service provider services that 4 | authorize credit card payments for e-businesses, online retailers, bricks and 5 | clicks, or traditional brick and mortar. 6 | 7 | Payment gateways link your website to your processing network and merchant account. 8 | In other words they facilitates the transfer of information between a website and 9 | the Front End Processor or acquiring bank. 10 | 11 | Resources and PHP libraries to check out: 12 | 13 | * [PHPLeague Omnipay](https://github.com/thephpleague/omnipay) - a framework 14 | agnostic, multi-gateway payment processing library for PHP 5.3+ 15 | * [TrustPay](https://www.trustpay.eu/) - an international payment gateway 16 | * [PayPal documentation](https://developer.paypal.com/docs/accept-payments/) - a 17 | documentation for processing payments through PayPal 18 | -------------------------------------------------------------------------------- /misc/packages/pdf.md: -------------------------------------------------------------------------------- 1 | # How to work with PDF files in PHP? 2 | 3 | In your application you will often need to create PDF files. For creating PDF files usage of [PHP's PDF functions](http://php.net/manual/en/book.pdf.php) is advised. 4 | 5 | Often this is not enough and you need extra functionalities on top of PHP PDF functions. PHP libraries and resources to check out: 6 | 7 | * [FPDF](http://www.fpdf.org/) - Open Source PHP class for generating PDF documents 8 | * [FPDI](http://www.setasign.com/products/fpdi/about/) - Collection of PHP classes to read pages from PDF 9 | * [PDF libraries on packagist](https://packagist.org/search/?q=pdf) - PDF libraries on packagist 10 | * [PHPPdf](https://github.com/psliwa/PHPPdf) - Pdf and graphic files generator library written in php 11 | * [TCPDF](http://www.tcpdf.org/) - Open Source PHP Class for generating PDF documents 12 | * [Dompdf](https://github.com/dompdf/dompdf) - Open Source HTML layout and rendering engine written in PHP 13 | -------------------------------------------------------------------------------- /misc/quality/README.md: -------------------------------------------------------------------------------- 1 | # Code quality and testing 2 | 3 | * [Writing quality code and code analysis](code-quality.md) 4 | * [How to test PHP code?](testing.md) 5 | * [Behavior driven development?](bdd.md) 6 | * [How to debug PHP code?](debugging.md) 7 | -------------------------------------------------------------------------------- /misc/quality/bdd.md: -------------------------------------------------------------------------------- 1 | # Behavior driven development 2 | 3 | Behavior driven development (BDD) is a software development process that evolved from 4 | TDD. It makes tests more natural by making English sentences that express certain 5 | behavior. It is an outside-in way of developing software, where you make examples 6 | of how the software should behave (feedback from stakeholders being either 7 | clients, your users or you) to achieve certain goals. 8 | 9 | ## StoryBDD 10 | 11 | There are two types of BDD - StoryBDD and SpecBDD. StoryBDD focuses on business 12 | and features. Here is a quick and simplified *example* of a login functionality 13 | based on [Behat](http://docs.behat.org) framework. By communicating with 14 | stackeholders, developers create login *scenario* (or an *example* in BDD): 15 | 16 | ```yaml 17 | Feature: Login 18 | I want to have access to certain page only if I provide 19 | correct username and secret password 20 | 21 | Scenario: Checking username and password 22 | Given I am on a login page "login" 23 | And I provide username "foo" 24 | And I provide password "bar" 25 | When I run "Login" 26 | Then I should see: 27 | """ 28 | Login is successful. 29 | """ 30 | ``` 31 | 32 | This ensures that developers understand how stackeholder want this functionality 33 | to work, and that stackeholders expect this functionality to be implemented like 34 | developers are planning to implement it. 35 | 36 | Instead of writing unit tests like with TDD, the scenario is also your test before 37 | writing the code. 38 | 39 | ## SpecBDD 40 | 41 | The second type of BDD is SpecBDD which focuses on technical behavior of code. 42 | Specifications describe how the certain code should behave. Instead of testing part 43 | of your code, you are describing that part of the code. 44 | 45 | ## See also 46 | 47 | Articles and tools you should check out: 48 | 49 | * Articles: 50 | * [BDD article on Wikipeida](http://en.wikipedia.org/wiki/Behavior-driven_development) 51 | * [Introducing BDD](http://dannorth.net/introducing-bdd/) - Article by Dan North 52 | * [What's in a story, by Dan North](http://dannorth.net/whats-in-a-story/) 53 | * PHP Tools: 54 | * [Codeception](http://codeception.com/) 55 | * [Behat](http://docs.behat.org/) - Behavior Driven Development Framework 56 | for PHP you should check out. 57 | * [Pho](https://github.com/danielstjules/pho) 58 | * [PHPSpec](http://www.phpspec.net/) 59 | * [Kahlan](https://kahlan.github.io/docs/) 60 | -------------------------------------------------------------------------------- /misc/quality/code-quality.md: -------------------------------------------------------------------------------- 1 | # Writing quality code and code analysis 2 | 3 | Beside writing tests, there are more factors that affect the quality of your 4 | code. Let's check some tools for PHP that can improve your code quality. 5 | 6 | ## PhpMetrics 7 | 8 | ![PhpMetrics](https://assets.php.earth/docs/quality/phpmetrics.png "PhpMetrics") 9 | 10 | [PhpMetrics][phpmetrics] is a very convenient static analysis tool for your 11 | code and your PHP projects. 12 | 13 | It can be installed with [Composer](https://getcomposer.org/) or by downloading [phar][phar]: 14 | 15 | ```bash 16 | composer global require 'halleck45/phpmetrics' 17 | phpmetrics --report-html=myreport.html /path/of/your/sources 18 | ``` 19 | 20 | PhpMetrics can even interact with [Jenkins][Jenkins] and [Sonar][sonar]. 21 | 22 | After running PhpMetrics from terminal you get an HTML file that looks 23 | something like this: 24 | 25 | ![PhpMetrics Report](https://assets.php.earth/docs/quality/phpmetrics_2.png "PhpMetrics Report") 26 | 27 | Some examples of PhpMetrics reports: 28 | 29 | * [CodeIgniter 3.0 PhpMetrics report](http://bl.ocks.org/petk/raw/c5b4da6935d9a8684248/) 30 | * [Symfony 2.6 PhpMetrics report](http://bl.ocks.org/petk/raw/d43726688595f112a419/) 31 | 32 | ## See also 33 | 34 | Other useful tools to check out: 35 | 36 | * [PHP Parser][phpparser] - This is a PHP 5.2 to PHP 7.1 parser written in PHP. Its purpose is to simplify static code analysis and manipulation. 37 | * [PHP QA tools][phpqatools] - List of PHP Quality Assurance tools 38 | * [Jenkins PHP][jenkinsphp] - Template for Jenkins Jobs for PHP Projects 39 | * [PHP Mess Detector][phpmd] - User friendly and easy to configure frontend for the raw metrics measured by [PHP Depend][phpdepend] 40 | * [PHPCheckStyle][phpcheckstyle] - open-source tool that helps PHP programmers adhere to certain coding conventions 41 | * [Qafoo Quality Analyzer](https://github.com/Qafoo/QualityAnalyzer) - Tool helping us to analyze software projects. 42 | * [SensioLabsInsight][SensioLabsInsight] - A quick way to run over 100 quality tests on your code (free version available). 43 | 44 | [phpparser]: https://github.com/nikic/PHP-Parser 45 | [phpmetrics]: http://phpmetrics.org 46 | [phar]: https://github.com/Halleck45/PhpMetrics/raw/master/build/phpmetrics.phar 47 | [jenkins]: http://jenkins-ci.org/ 48 | [sonar]: http://www.sonarqube.org 49 | [phpqatools]: http://phpqatools.org/ 50 | [jenkinsphp]: http://jenkins-php.org/ 51 | [phpmd]: http://phpmd.org/ 52 | [phpdepend]: http://pdepend.org/ 53 | [phpcheckstyle]: https://phpcheckstyle.github.io/ 54 | [SensioLabsInsight]: https://insight.sensiolabs.com/ 55 | -------------------------------------------------------------------------------- /misc/quality/testing.md: -------------------------------------------------------------------------------- 1 | # How to test PHP code? 2 | 3 | Testing code is an important part of development and should not be avoided. It 4 | adds extra time to development but it also improves code quality and saves you 5 | more time when you're adding new features, or refactoring your code without 6 | breaking something. 7 | 8 | You're testing your code already between the development itself without maybe 9 | realizing. When you add some part of code, you either check for the correct 10 | output or response in browser, database etc. However this way not all cases are 11 | considered and it is not repeatable and automated. Soon you need something more 12 | reliable and organized. 13 | 14 | In PHP there are available many testing tools and frameworks. Testing can be 15 | categorized based on the approach. 16 | 17 | ## Test driven development (aka TDD) 18 | 19 | TDD is a software development process in which you repeat very short 20 | development cycles in which you write code that passes or intentionally fails. 21 | 22 | ### Unit testing 23 | 24 | Probably the most used tool and de-facto standard for unit testing in PHP is 25 | the [PHPUnit](https://phpunit.de/) testing framework. It has an awesome manual 26 | so do read it and start using TDD. 27 | 28 | ### Functional testing 29 | 30 | By using tools you create automated tests, where application is actually used 31 | instead of just checking certain parts of code. 32 | 33 | * [Selenium](http://seleniumhq.com/) 34 | * [Mink](http://mink.behat.org/) 35 | * [Codeception](http://codeception.com/) 36 | 37 | ## Behavior driven development (aka BDD) 38 | 39 | Behavior driven development is a software development process that evolved from 40 | TDD. It makes unit tests more natural by making English sentences that express 41 | certain behavior. Read more about PHP focused BDD in the dedicated 42 | [chapter](/misc/quality/bdd.md). 43 | 44 | ## Testing spaghetti code 45 | 46 | What is spaghetti code? 47 | 48 | Spaghetti code is a term for complex unstructured code, which also has lots of 49 | goto statements, exceptions, threads and other unstructured branching 50 | constructs. 51 | 52 | What is Macaroni code? 53 | 54 | Languages all mixed up like mac and cheese. For example, SQL and PHP together. 55 | 56 | ## Why testing code if the application works ok and is in production? 57 | 58 | * Code can be bad and you want to assure it is working ok 59 | * Maybe there is repeating code in different parts of your application 60 | * When you copy/paste code you can break things. We are a human beings and we 61 | all make mistakes. Also bugs might get copied and pasted besides the code. 62 | 63 | ## See also 64 | 65 | * [PHPCI](https://www.phptesting.org/) - Free and open source continuous 66 | integration specifically designed for PHP. 67 | * [Wikipedia](http://en.wikipedia.org/wiki/Test-driven_development) 68 | -------------------------------------------------------------------------------- /php/README.md: -------------------------------------------------------------------------------- 1 | # Vanilla PHP 2 | 3 | PHP is a widely used, popular general-purpose scripting language that is 4 | especially suited to web development and writing command line scripts. 5 | 6 | In this course you will learn how to write PHP code and develop PHP applications. 7 | You will become more confident in your PHP development skills. 8 | 9 | ## [PHP introduction](/php/intro) 10 | 11 | Start with this chapter to get to know PHP, how to install it, which editor to 12 | use, and create your first hello world program. 13 | 14 | ## [PHP language reference](/php/ref) 15 | 16 | Built-in PHP language features and syntax. 17 | 18 | ## [PHP extensions](/php/ext) 19 | 20 | PHP consists of extensions. PHP extension is a self containing module that 21 | provides some particular functionality, such as sessions or accessing databases. 22 | 23 | ## [PHP SAPI modules](/php/sapi) 24 | 25 | **S**erver **A**pplication **P**rogramming **I**nterface - SAPI helps interacting 26 | between the outside world and the PHP/Zend engine. PHP comes with muliple SAPI 27 | modules for using it in command line, with web servers or even embedding it in 28 | other applications. 29 | 30 | ## [PHP community](/php/community) 31 | 32 | Awesome PHP community and PHP user groups. 33 | 34 | ## [Appendices](/php/appendices) 35 | 36 | Additional important chapters to understand and know more about PHP. 37 | -------------------------------------------------------------------------------- /php/appendices/README.md: -------------------------------------------------------------------------------- 1 | # Appendices 2 | 3 | ## [PHP coding style](coding-style.md) 4 | 5 | This chapter will discuss how should you style your PHP code (spaces or tabs, 6 | where to put curly brackets, etc.) 7 | 8 | ## [PHP evolution](evolution.md) 9 | 10 | How it all began and how PHP evolved through time. 11 | 12 | ## [PHP criticism](criticism.md) 13 | 14 | PHP is not perfect. Any language is. This chapter will focus on all the criticism 15 | around PHP language and its ecosystem and how to tackle these issues. 16 | 17 | ## [Best PHP practices](best-practices.md) 18 | 19 | There are many ways to write PHP. This is a collection of best PHP best practices. 20 | -------------------------------------------------------------------------------- /php/appendices/criticism.md: -------------------------------------------------------------------------------- 1 | # PHP criticism 2 | 3 | PHP began 4 | -------------------------------------------------------------------------------- /php/appendices/evolution.md: -------------------------------------------------------------------------------- 1 | # PHP evolution 2 | 3 | Knowing something about [PHP history](http://php.net/history.php) and about who 4 | initially created the PHP language and started the [PHP](http://php.net) 5 | project is interesting information that might help inspire you for developing 6 | something of your own. It might also help you to better understand the current 7 | state of PHP functionality. 8 | 9 | PHP was initially written by **Rasmus Lerdorf**. It all started in 1994 when 10 | Rasmus started working on the very first incarnation of PHP which was a simple 11 | set of Common Gateway Interface (CGI) binaries written in the C programming 12 | language. 13 | 14 | ## See also 15 | 16 | * [PHP Evolution](https://line.do/php-evolution/8oq) - Timeline with important 17 | milestones of PHP evolution. 18 | * [Wikipedia](http://en.wikipedia.org/wiki/PHP) 19 | -------------------------------------------------------------------------------- /php/community/README.md: -------------------------------------------------------------------------------- 1 | # PHP Community 2 | 3 | ## [PHP community and PHP user groups](groups.md) 4 | 5 | What is PHP community and what are PHP user groups. 6 | 7 | ## [PHP conferences](conferences.md) 8 | 9 | Meet some highlighted PHP conferences around the world. 10 | 11 | ## [ElePHPant](elephpant.md) 12 | 13 | PHP uses elephants in their logotypes. Learn what are elephpants and how they 14 | came to be. 15 | 16 | ## [PHP podcasts](podcasts.md) 17 | 18 | Some of the most listened and visited PHP and framework related podcasts. 19 | -------------------------------------------------------------------------------- /php/community/conferences.md: -------------------------------------------------------------------------------- 1 | # PHP conferences 2 | 3 | PHP conferences are PHP specific events, at which established, well known PHP 4 | speakers present their topics and users meet and discuss PHP related topics and 5 | have fun. They occur all over the world in many countries. 6 | 7 | [PHP.net](http://php.net) always updates and announces PHP conferences from all 8 | over the world. You can check the list of current conferences happening in the 9 | [PHP's conference section](http://php.net/conferences/index.php). 10 | 11 | There are some established conferences located in very comfy and easy to visit 12 | locations. 13 | 14 | ## Highlighted PHP conferences 15 | 16 | * **Bulgaria** 17 | * PHP Bulgaria 18 | * http://www.bgphp.org/ 19 | 20 | * **Croatia** 21 | * Web Summer Camp 2017 22 | * http://2017.websummercamp.com/ 23 | 24 | * **Germany** 25 | * International PHP Conference 26 | * https://phpconference.com/en/ 27 | 28 | * **Italy** 29 | * PHP Day 30 | * http://2017.phpday.it/ 31 | 32 | * **Netherlands** 33 | * Dutch PHP 34 | * https://www.phpconference.nl/ 35 | 36 | * LaraCon EU 37 | * https://laracon.eu/2017/ 38 | 39 | * **Romania** 40 | * SymfonyCon Romania 41 | * http://live.symfony.com/ 42 | 43 | * **Serbia** 44 | * PHPSerbia 45 | * http://www.conf2017.phpsrbija.rs/ 46 | 47 | * **USA** 48 | * LaraCon US 49 | * http://laracon.us/ 50 | 51 | * Symfony Live San Francisco 52 | * http://live.symfony.com/ 53 | 54 | * php[cruise]! - Baltimore 55 | * https://cruise.phparch.com/ 56 | 57 | * PHPtek 58 | * https://tek.phparch.com/ 59 | 60 | * Lone Star 61 | * http://lonestarphp.com/ 62 | 63 | There are a lot more. 64 | -------------------------------------------------------------------------------- /php/community/podcasts.md: -------------------------------------------------------------------------------- 1 | # PHP podcasts 2 | 3 | ## PHP related podcasts 4 | 5 | * [Lately in PHP](https://www.phpclasses.org/blog/category/podcast/) 6 | * [PHP Podcasts](https://www.phppodcasts.com/) 7 | * [PHP Roundtable](https://www.phproundtable.com/) 8 | * [PHP Town Hall](https://phptownhall.com/) 9 | * [PHPUgly Podcast](https://phpugly.com/) 10 | 11 | ## PHP framework related podcasts 12 | 13 | * [Laravel News Podcast](https://laravel-news.com/podcast/) 14 | * [Laravel Podcast](http://www.laravelpodcast.com/) 15 | * [Sound of Symfony](http://www.soundofsymfony.com/) 16 | 17 | ## General 18 | 19 | * [/dev/hell](http://devhell.info/) 20 | -------------------------------------------------------------------------------- /php/ext/README.md: -------------------------------------------------------------------------------- 1 | # PHP extensions 2 | 3 | PHP consists of extensions. PHP extension is a self containing module that 4 | provides some particular functionality, such as sessions or accessing databases. 5 | 6 | ## [PHP extensions introduction](intro.md) 7 | 8 | Introduction chapter will introduce the categorization of the PHP extensions, 9 | where they can be found and how you can install them. 10 | 11 | ## [Date and time](date-time.md) 12 | 13 | PHP date extension provides functions and classes for working with dates and 14 | time. 15 | 16 | ## [Sessions](/php/ext/sessions) 17 | 18 | PHP session extension provides functions and classes for persisting data between 19 | requests. Learn more about sessions in PHP and session extension. 20 | 21 | ## [Databases](/php/ext/db) 22 | 23 | Access databases with PHP. 24 | 25 | ## [Regex](regex.md) 26 | 27 | Regular expressions in PHP. 28 | 29 | ## [Phar](phar.md) 30 | 31 | Phar (PHP Archive) 32 | -------------------------------------------------------------------------------- /php/ext/db/README.md: -------------------------------------------------------------------------------- 1 | # Databases 2 | 3 | * [What is a database and how to access databases from PHP?](intro.md) 4 | * [Database management systems vs. file systems?](database-vs-filesystem.md) 5 | * [PDO](pdo.md) 6 | -------------------------------------------------------------------------------- /php/ext/db/database-vs-filesystem.md: -------------------------------------------------------------------------------- 1 | # Database management systems vs. file systems? 2 | 3 | ## Database management systems vs. file systems 4 | 5 | * DBMS - A computerized record-keeping system 6 | * File System - A collection of individual files accessed by applications programs. 7 | 8 | ## Common limitations of some file system based DBs 9 | 10 | * Separated and Isolated Data - Makes coordinating, assimilating and representing data difficult 11 | * Data Duplication - Wastes space and can lead to data integrity (inconsistency) problems 12 | * Application Program Dependencies - Changes to a single file can require changes to numerous application programs 13 | * Incompatible Files 14 | 15 | ## Advantages of a DBMS 16 | 17 | * Data Consistency and Integrity - by controlling access and minimizing data duplication 18 | * Application program independence - by storing data in a uniform fashion 19 | * Data Sharing - by controlling access to data items, many users can access data concurrently 20 | * Checkpointing and Recovery 21 | * Security and Privacy 22 | * Multiple views of data 23 | * Expandability, Flexibility, Scalability 24 | * Reduced application development times once the system is in place 25 | * Standards enforcement 26 | * However ..... 27 | * Commercial DBMS often have high initial cost 28 | * Many DBMSs have high overhead - require powerful computers 29 | * DBMS are not special purpose software programs 30 | * Performance depends on the application 31 | 32 | ## When is a DBMS not necessarily appropriate? 33 | 34 | * Database is small with a simple structure 35 | * Applications are simple, special purpose and relatively static. 36 | * Concurrent, multi-user access to data is not required. 37 | * Need a quick prototype to demonstrate feasibility 38 | * Need an easy way to see the data without having to write a program 39 | * Customers don't want to install a DBMS and want to get online quickly 40 | -------------------------------------------------------------------------------- /php/ext/phar.md: -------------------------------------------------------------------------------- 1 | # How to create Phar (PHP Archive)? 2 | 3 | ## Packed php application archive 4 | 5 | ``` 6 | Note 7 | "This action needs the php.ini setting phar.readonly to be set to 0 in order to work for Phar objects. Otherwise, a PharException will be thrown." 8 | ``` 9 | 10 | PHAR (“Php ARchive”) is analogous to the JAR file concept but for PHP. If you have PHP 5.3 or greater, the Phar extension is built-in and enabled; you can start using it without any additional requirements. 11 | PHAR files are treated as read-only by default, and you can use any PHAR file without any special configuration. This is great for deployment. But as you'll be creating your own PHARs you'll need to allow write-access which is done through the php.ini file. 12 | Open `php.ini`, find the `phar.readonly` directive, and modify it accordingly: 13 | 14 | ```ini 15 | phar.readonly = 0 16 | ``` 17 | 18 | Now you're ready to package your libraries and applications as PHARs. 19 | 20 | Below simple code can create phar from folder `project` or change it to your project name. 21 | 22 | ```php 23 | buildFromDirectory(dirname(__FILE__) . '/project'); 28 | $phar->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php')); 29 | 30 | $phar2 = new Phar('project2.phar', 0, 'project2.phar'); 31 | // add all files in the project, only include php files 32 | $phar2->buildFromDirectory(dirname(__FILE__) . '/project', '/\.php$/'); 33 | $phar2->setStub($phar->createDefaultStub('cli/index.php', 'www/index.php')); 34 | ``` 35 | -------------------------------------------------------------------------------- /php/ext/sessions/README.md: -------------------------------------------------------------------------------- 1 | # PHP sessions 2 | 3 | ## [Introduction](intro.md) 4 | 5 | Get to know what sessions are and how they work. 6 | -------------------------------------------------------------------------------- /php/ext/sessions/intro.md: -------------------------------------------------------------------------------- 1 | # Sessions 2 | 3 | Sessions in web applications provide a way to persist data between requests. 4 | 5 | When you start a new PHP session with `session_start()`, by default, there is a 6 | file created on the server somewhere in system temporary folder (/tmp on Linux, 7 | for example or the location set in the php.ini file under the `session.save_path` 8 | INI directive). File name can be of format `sess_ag525kn0fk6ik9r84kap9lkbfl` and 9 | its contents contain your `$_SESSION` data. 10 | 11 | And there is also a special single cookie created in user browser with name 12 | `PHPSESSID` and value of something like `ag525kn0fk6ik9r84kap9lkbfl` 13 | 14 | That cookie *connects* the user *browser* with that file where `$_SESSION` info 15 | is stored. Quite a simple storing mechanism. 16 | 17 | Now, these traditional sessions are slow and performance bottlenecks soon so other 18 | ways of storage are used, or also if you want to make them more secure, they can 19 | be encrypted (that file contents) and so on. 20 | 21 | Whatever you do, try not to store anything sensitive in cookies. You actually 22 | won't need to create and use custom created cookies at all in most cases. Only 23 | for example, when you want to display that EU cookie warnings and to remember is 24 | user clicked "ok, don't display this next time". And similar cases. 25 | 26 | For login, sessions are the way to go. 27 | 28 | Yes, `session_destroy()` removes that file on the server but the PHPSESSID cookie 29 | remains on the user browser. Which is not problematic because the new tmp file on 30 | the server will be created next time you call `session_start()` with new content 31 | of your defined $_SESSION array contents... 32 | -------------------------------------------------------------------------------- /php/intro/README.md: -------------------------------------------------------------------------------- 1 | # PHP introduction 2 | 3 | ## [Getting started](start.md) 4 | 5 | Learn what is PHP and why you should use it. 6 | 7 | ## [PHP installation](installation.md) 8 | 9 | To be able to follow these chapters, you need to install PHP and some 10 | prerequisites on your system. 11 | 12 | ## [Editors and IDEs](editors.md) 13 | 14 | For writing PHP code, you will need a text editor or IDE. This chapter will 15 | introduce you to some useful tools. 16 | 17 | ## [PHP basics](basics.md) 18 | 19 | Create PHP hello world and learn about the essential elements of PHP. 20 | -------------------------------------------------------------------------------- /php/intro/basics.md: -------------------------------------------------------------------------------- 1 | # PHP basics 2 | 3 | This chapter will go through a simple PHP program and show you basic PHP syntax. 4 | 5 | ## Hello world 6 | 7 | Let's create a *hello world* PHP program, and display the output in the 8 | command line and in browser. 9 | 10 | Create a new file called `hello.php` with the following contents: 11 | 12 | ```php 13 | 31 | 32 | ## PHP tags 33 | 34 | First line in above file is a so called *opening PHP tag* - ` 41 | 42 | 43 | 44 | 45 | ``` 46 | 47 | * Opening PHP tag: `` 49 | 50 | And display it in the browser: 51 | 52 | ```bash 53 | php -S localhost:8000 php-and-html.php 54 | ``` 55 | 56 | Now, visit URL `http://localhost:8000` in your favourite browser, and you should 57 | see output of `Hello world`. 58 | 59 | ## Comments 60 | 61 | Comments in code are language elements that indicate which parts of the code 62 | should not be parsed and processed. PHP provides two types of comments: 63 | 64 | * Single line comments: 65 | 66 | ```php 67 | 0 { 7 | return $x; 8 | } else { 9 | return -$x; 10 | } 11 | ``` 12 | 13 | ## Loops 14 | 15 | ```php 16 | // for 17 | for ($i = 1; $i<10; $i++) {} 18 | 19 | // while 20 | while ($i < 10) {} 21 | 22 | // do while 23 | $i = 0; 24 | do { 25 | echo $i; 26 | } while ($i > 0); 27 | 28 | 29 | // foreach 30 | foreach ($array as $key => $value) {} 31 | ``` 32 | 33 | ## Switch 34 | 35 | ```php 36 | // switch statement 37 | switch ($operatingSystem) { 38 | case 'darwin': 39 | echo 'Mac OS Hipster'; 40 | break; 41 | case 'linux': 42 | echo 'Linux Geek'; 43 | break; 44 | default: 45 | // Windows, BSD, ... 46 | echo 'Other'; 47 | } 48 | ``` 49 | -------------------------------------------------------------------------------- /php/ref/cookies.md: -------------------------------------------------------------------------------- 1 | # Cookies 2 | 3 | A cookie is a file that the server sets on user's computer to contain some information as key value pair. 4 | 5 | It is sent with every request to the server. 6 | 7 | The maximum size of a cookie must not exceed 4 Kilo Bytes. 8 | 9 | You can access the cookie variables through the `$_COOKIE` global variable. 10 | 11 | Warnings: 12 | - The user can disable cookies on his browser. 13 | - You must not use cookies to store sensitive information as it is not protected. 14 | 15 | ### Setting a cookie 16 | Using `setcookie` function. 17 | ```php 18 | setcookie( 19 | string $name, 20 | string $value = "", 21 | int $expires = 0, 22 | string $path = "", 23 | string $domain = "", 24 | bool $secure = false, 25 | bool $httponly = false 26 | ): bool 27 | 28 | // Alternative signature available as of PHP 7.3.0 29 | setcookie(string $name, string $value = "", array $options = []): bool 30 | 31 | ``` 32 | 33 | ### Cookie configuration 34 | 35 | - `$expires` sets the time the cookie should expire. 36 | - `$path` is the path on the server in which the cookie will be available on. Setting it to `/` makes it available to the entire domain. 37 | - `$domain` is the subdomain that the cookie is available to. 38 | - `$secure` if set to `true` make it available to `https` only. 39 | - `$httponly` if set to true make it accessible only through the HTTP protocol. This means that the cookie won't be accessible by JavaScript. 40 | 41 | 42 | ### Deleting the cookie 43 | 44 | You can do this by setting the `$expires` parameter to negative value. 45 | 46 | ```PHP 47 | setcookie($cookie_name, '' ,time() - 3600); 48 | ``` -------------------------------------------------------------------------------- /php/ref/errors.md: -------------------------------------------------------------------------------- 1 | # Errors 2 | 3 | When you develop you will definitely want to turn on error reporting in PHP. It 4 | gives you valuable information as to why something has failed. Let's check some 5 | of the most important error reporting directives in `php.ini`: 6 | 7 | * **error_reporting** 8 | 9 | This sets which errors should be reported. Using `E_ALL` is a good practice. 10 | 11 | * **display_errors** 12 | 13 | This handles displaying errors to the screen. 14 | 15 | * **log_errors** 16 | 17 | This controls reporting errors to a log file. Recommended practice is to 18 | always have this enabled. 19 | 20 | * **error_log** 21 | 22 | This defines error log file where errors should be written. It only applies 23 | if `log_errors` is enabled. 24 | 25 | Showing errors should depend on the environment your application is present. 26 | 27 | ```php 28 | getMessage(), "\n"; 19 | } finally { 20 | echo "This is always executed.\n"; 21 | } 22 | ``` 23 | -------------------------------------------------------------------------------- /php/ref/functions.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | A function is a language element that wraps a block of code between curly bracket 4 | characters and provides reusable functionality throughout your program. 5 | 6 | Let's take a look at a simple example: 7 | 8 | ```php 9 | An anti-pattern is a common response to a recurring problem that is usually 4 | > ineffective and risks being highly counterproductive. The term, coined in 5 | > 1995 by Andrew Koenig, was inspired by a book, "Design Patterns", which 6 | > highlights a number of design patterns in software development that its 7 | > authors considered to be highly reliable and effective. 8 | 9 | * [Wikipedia](https://en.wikipedia.org/wiki/Anti-pattern) 10 | 11 | ## See also 12 | 13 | * [AntiPatterns eBook](https://sourcemaking.com/antipatterns) 14 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/README.md: -------------------------------------------------------------------------------- 1 | # Design patterns in PHP 2 | 3 | * [What are design patterns in PHP?](intro.md) 4 | * [Abstract factory](abstract-factory.md) 5 | * [Adapter](adapter.md) 6 | * [Bridge](bridge.md) 7 | * [Builder](builder.md) 8 | * [Chain of responsibility](chain-of-responsibility.md) 9 | * [Command](command.md) 10 | * [Composite](composite.md) 11 | * [Decorator](decorator.md) 12 | * [Dependency injection](dependency-injection.md) 13 | * [Facade](facade.md) 14 | * [Flyweight](flyweight.md) 15 | * [Interpreter](interpreter.md) 16 | * [Iterator](iterator.md) 17 | * [Lazy loading](lazy-loading.md) 18 | * [Mediator](mediator.md) 19 | * [Memento](memento.md) 20 | * [Mock object](mock-object.md) 21 | * [Null object](null-object.md) 22 | * [Object pool](object-pool.md) 23 | * [Observer](observer.md) 24 | * [Prototype](prototype.md) 25 | * [Proxy design pattern](proxy.md) 26 | * [Servant design pattern](servant.md) 27 | * [Singleton design pattern](singleton.md) 28 | * [State design pattern](state.md) 29 | * [Strategy design pattern](strategy.md) 30 | * [Template method](template-method.md) 31 | * [Type tunnel design pattern](type-tunnel.md) 32 | * [Visitor design pattern](visitor.md) 33 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/abstract-factory.md: -------------------------------------------------------------------------------- 1 | # Abstract factory design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Abstract factory design pattern](https://en.wikipedia.org/wiki/Abstract_factory_pattern) 6 | * [DesignPatternsPHP: Abstract Factory](http://designpatternsphp.readthedocs.io/en/latest/Creational/AbstractFactory/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/adapter.md: -------------------------------------------------------------------------------- 1 | # Adapter design pattern in PHP 2 | 3 | ![Adapter Design Pattern UML Diagram](https://assets.php.earth/docs/oop/design-patterns/structural/adapter.png "Adapter Design Pattern UML Diagram") 4 | 5 | ## See also 6 | 7 | * [Wikipedia: Adapter pattern](http://en.wikipedia.org/wiki/Adapter_pattern) 8 | * [DesignPatternsPHP: Adapter/Wrapper](http://designpatternsphp.readthedocs.io/en/latest/Structural/Adapter/README.html) 9 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/bridge.md: -------------------------------------------------------------------------------- 1 | # Bridge design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Bridge pattern](https://en.wikipedia.org/wiki/Bridge_pattern) 6 | * [DesignPatternsPHP: Bridge pattern](http://designpatternsphp.readthedocs.io/en/latest/Structural/Bridge/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/builder.md: -------------------------------------------------------------------------------- 1 | # Builder design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Builder pattern](https://en.wikipedia.org/wiki/Builder_pattern) 6 | * [DesignPatternsPHP: Builder pattern](http://designpatternsphp.readthedocs.io/en/latest/Creational/Builder/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/chain-of-responsibility.md: -------------------------------------------------------------------------------- 1 | # Chain of responsibility design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Chain-of-responsibility pattern](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern) 6 | * [DesignPatternsPHP: Chain Of Responsibilities](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/ChainOfResponsibilities/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/command.md: -------------------------------------------------------------------------------- 1 | # Command design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Command pattern](https://en.wikipedia.org/wiki/Command_pattern) 6 | * [DesignPatternsPHP: Command](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Command/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/composite.md: -------------------------------------------------------------------------------- 1 | # Composite design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Composite pattern](https://en.wikipedia.org/wiki/Composite_pattern) 6 | * [DesignPatternsPHP: Composite](http://designpatternsphp.readthedocs.io/en/latest/Structural/Composite/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/decorator.md: -------------------------------------------------------------------------------- 1 | # Decorator design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern) 6 | * [DesignPatternsPHP: Decorator](http://designpatternsphp.readthedocs.io/en/latest/Structural/Decorator/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/facade.md: -------------------------------------------------------------------------------- 1 | # Facade design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Facade pattern](https://en.wikipedia.org/wiki/Facade_pattern) 6 | * [DesignPatternsPHP: Facade](http://designpatternsphp.readthedocs.io/en/latest/Structural/Facade/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/flyweight.md: -------------------------------------------------------------------------------- 1 | # Flyweight design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Flyweight pattern](https://en.wikipedia.org/wiki/Flyweight_pattern) 6 | * [DesignPatternsPHP: Flyweight](http://designpatternsphp.readthedocs.io/en/latest/Structural/Flyweight/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/interpreter.md: -------------------------------------------------------------------------------- 1 | # Interpreter design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Interpreter pattern](https://en.wikipedia.org/wiki/Interpreter_pattern) 6 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/iterator.md: -------------------------------------------------------------------------------- 1 | # Iterator design pattern in PHP 2 | 3 | Iterator design pattern is a software design pattern which provides access to 4 | the elements of an aggregate object sequentially without exposing its 5 | underlying representation. It makes elements appear as a collection of objects. 6 | 7 | * Promote to "full object status" the traversal of a collection. 8 | * Polymorphic traversal 9 | 10 | ## PHP implementations 11 | 12 | * PHP offers [Iterator interface](http://php.net/manual/en/class.iterator.php) 13 | out of the box. Its SPL library has also a wide variety of 14 | [useful iterators](http://php.net/manual/en/spl.iterators.php). After 15 | understanding the basics of the iterator pattern using these instead of 16 | reinventing the wheel is more convenient. 17 | 18 | ## See also 19 | 20 | * [Wikipedia: Iterator pattern](https://en.wikipedia.org/wiki/Iterator_pattern) 21 | * [DesignPatternsPHP: Iterator](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Iterator/README.html) 22 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/mediator.md: -------------------------------------------------------------------------------- 1 | # Mediator design pattern with PHP example 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Mediator pattern](https://en.wikipedia.org/wiki/Mediator_pattern) 6 | * [DesignPatternsPHP: Mediator](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Mediator/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/memento.md: -------------------------------------------------------------------------------- 1 | # Memento design pattern in PHP 2 | 3 | ## UML diagram 4 | 5 | ![Memento design pattern UML diagram](https://assets.php.earth/docs/oop/design-patterns/behavioral/memento.png "Memento design pattern UML diagram") 6 | 7 | ## See also 8 | 9 | * [Memento design pattern on Wikipedia](http://en.wikipedia.org/wiki/Memento_pattern) 10 | * [DesignPatternsPHP: Memento](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Memento/README.html) 11 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/mock-object.md: -------------------------------------------------------------------------------- 1 | # Mock object design pattern in PHP 2 | 3 | Mock objects imitate the behavior of the real objects. They are used in 4 | testing, where creating mock objects makes testing simpler and still provides 5 | the same behavior as the real object used in the application code. They can 6 | also be used as a base while developing a specific part of an application in a 7 | team, without utilizing the entire application. 8 | 9 | ## Implementations 10 | 11 | * [PHPUnit](https://phpunit.de/manual/current/en/test-doubles.html) 12 | 13 | ## See also 14 | 15 | * [Wikipedia: Mock object](https://en.wikipedia.org/wiki/Mock_object) 16 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/observer.md: -------------------------------------------------------------------------------- 1 | # Observer design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Observer pattern](https://en.wikipedia.org/wiki/Observer_pattern) 6 | * [DesignPatternsPHP: Observer pattern](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Observer/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/prototype.md: -------------------------------------------------------------------------------- 1 | # Prototype design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Prototype pattern](https://en.wikipedia.org/wiki/The_Observer) 6 | * [DesignPatternsPHP: Prototype](http://designpatternsphp.readthedocs.io/en/latest/Creational/Prototype/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/proxy.md: -------------------------------------------------------------------------------- 1 | # Proxy design pattern in PHP 2 | 3 | ![Proxy design pattern UML diagram](https://assets.php.earth/docs/oop/design-patterns/structural/proxy.png "Proxy Design Pattern UML Diagram") 4 | 5 | ## See also 6 | 7 | * [Wikipedia: Proxy pattern](https://en.wikipedia.org/wiki/Proxy_pattern) 8 | * [DesignPatternsPHP: Proxy](http://designpatternsphp.readthedocs.io/en/latest/Structural/Proxy/README.html) 9 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/servant.md: -------------------------------------------------------------------------------- 1 | # Servant design pattern in PHP 2 | 3 | Servant design pattern is a behavioral design pattern where multiple classes 4 | use the servant's class behavior to **avoid repeating code** 5 | (*see: [DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)*). 6 | Behavior functionality is defined only in one place: In servant. 7 | 8 | The servant design pattern is not a defined pattern in the Gang of Four (GoF) 9 | book. It is very similar to the 10 | [command design pattern](/php/ref/oop/design-patterns/command.md) 11 | but with a somewhat different solution to the problem. 12 | 13 | ![Servant design pattern UML](https://assets.php.earth/docs/oop/design-patterns/servant.png "Servant Design Pattern UML") 14 | 15 | ## See also 16 | 17 | * [Wikipedia: Servant design pattern](https://en.wikipedia.org/wiki/Servant_(design_pattern)) 18 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/state.md: -------------------------------------------------------------------------------- 1 | # State design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: State pattern](https://en.wikipedia.org/wiki/State_pattern) 6 | * [DesignPatternsPHP: State](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/State/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/strategy.md: -------------------------------------------------------------------------------- 1 | # Strategy design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Strategy pattern](https://en.wikipedia.org/wiki/Strategy_pattern) 6 | * [DesignPatternsPHP: Strategy](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Strategy/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/template-method.md: -------------------------------------------------------------------------------- 1 | # Template method design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Template method pattern](https://en.wikipedia.org/wiki/Template_method_pattern) 6 | * [DesignPatternsPHP: Template method](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/TemplateMethod/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/type-tunnel.md: -------------------------------------------------------------------------------- 1 | # Type tunnel design pattern in PHP 2 | 3 | The type tunnel pattern is not exactly a recognized software design pattern by 4 | GoF (Gang of Four book). Type tunnel is used in cases where multiple unrelated 5 | types are passed (tunneled) through adaptation layer and converted to the type 6 | the underlying layer expects. 7 | 8 | ![Type tunnel design pattern UML](https://assets.php.earth/docs/oop/design-patterns/type-tunnel.png "Type Tunnel Design Pattern UML") 9 | 10 | Type tunnel also has side effects that compensate its benefits, because in a 11 | dynamically typed language such as PHP, the types can be solved differently. 12 | 13 | It can be used best in statically typed programming languages such as C++, but 14 | in case of PHP, implementing type tunnel isn't really applicable. 15 | 16 | ## See also 17 | 18 | * [Type Tunnel](https://en.wikipedia.org/wiki/Type_Tunnel_pattern) 19 | * [Generalized String Manipulation: Access Shims and Type Tunneling](http://www.drdobbs.com/generalized-string-manipulation-access-s/184401689) 20 | * [PHP Types](http://php.net/manual/en/language.types.php) 21 | -------------------------------------------------------------------------------- /php/ref/oop/design-patterns/visitor.md: -------------------------------------------------------------------------------- 1 | # Visitor design pattern in PHP 2 | 3 | ## See also 4 | 5 | * [Wikipedia: Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern) 6 | * [DesignPatternsPHP: Visitor pattern](http://designpatternsphp.readthedocs.io/en/latest/Behavioral/Visitor/README.html) 7 | -------------------------------------------------------------------------------- /php/ref/oop/dic.md: -------------------------------------------------------------------------------- 1 | # What is dependency injection container in PHP? 2 | 3 | To better understand dependency injection container, the 4 | [dependency injection design pattern](/php/ref/oop/design-patterns/dependency-injection.md) 5 | is a prerequisite. 6 | 7 | Dependency injection container is very useful and recommended way of managing 8 | class dependencies. It is a utility which helps you to implement the dependency 9 | injection pattern in your application. 10 | 11 | Dependency injection container is a combination of container design pattern, 12 | factory pattern and (optionally) flyweight pattern when utilizing objects as 13 | service descriptors. General implementations of dependency injection container 14 | are also inspecting components (utilizing reflection). 15 | 16 | ## See also 17 | 18 | * [PHP-DI](http://php-di.org/) - Dependency injection container PHP library. 19 | * [Pimple](http://pimple.sensiolabs.org/) - A simple PHP dependency injection 20 | container. 21 | * [Do you need a Dependency Injection Container?](http://fabien.potencier.org/do-you-need-a-dependency-injection-container.html) 22 | * [Symfony Dependency Injection Component](http://symfony.com/doc/current/components/dependency_injection.html) 23 | * [Laravel Service Container](https://laravel.com/docs/5.3/container) 24 | * [Aura.DI](https://github.com/auraphp/Aura.Di) 25 | * [Dependency Injection: An analogy](https://mwop.net/blog/260-Dependency-Injection-An-analogy.html) 26 | -------------------------------------------------------------------------------- /php/ref/oop/solid.md: -------------------------------------------------------------------------------- 1 | # SOLID 2 | 3 | SOLID is a collection of good programming practices for object oriented 4 | programming and consists of 6 principles. These aren't rules that you should be 5 | following strictly everywhere. These are more like best practices you should 6 | use when possible and understood. If there are better practices than these 7 | found and developed at some point in the future, they too will be extended and 8 | explained in separate chapters. 9 | 10 | SOLID stands for: 11 | 12 | * **S** as single responsibility principle 13 | * **O** as open/close principle 14 | * **L** as Liskov segregation principle 15 | * **I** as interface segregation principle 16 | * **D** as dependency inversion principle 17 | 18 | ## Single Responsibility Principle (SRP) 19 | 20 | Single responsibility principle states that each class or module should have 21 | one and only one role or responsibility. 22 | 23 | ## Open/Close Principle (OC) 24 | 25 | Open/close principle states that each class should be open for extension and at 26 | the same time closed for modification. 27 | 28 | ## Liskov Segregation Principle (LSP) 29 | 30 | Liskov segregation principle states that objects should be replaceable with 31 | instances of any of their parent classes. 32 | 33 | ## Interface Segregation Principle (ISP) 34 | 35 | Interface segregation principle states that classes should not be limited and 36 | locked for accepting more of their kind. 37 | 38 | ## Dependency Inversion Principle 39 | 40 | Dependency inversion principle states that classes should depend on 41 | abstractions rather than only certain class dependencies. Abstraction should be 42 | implemented without detailed functionality so that classes can use the 43 | abstraction and extend it accordingly. 44 | 45 | ## See also 46 | 47 | The following resources are advised to read beside this article to get 48 | different explanations and to know more about the SOLID principles. 49 | 50 | * [Wikipedia: SOLID (object oriented design)](https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)) 51 | -------------------------------------------------------------------------------- /php/ref/operators.md: -------------------------------------------------------------------------------- 1 | # Operators 2 | 3 | ## Arithmetic operators 4 | 5 | |Operator|Name|Result| 6 | |--------|----|-----------| 7 | |`-$a`|negation|Opposite of $a.| 8 | |`$a + $b`|addition|Sum of $a and $b.| 9 | |`$a - $b`|Subtraction|Difference of $a and $b.| 10 | |`$a * $b`|Multiplication|Product of $a and $b.| 11 | |`$a / $b`|division|Quotient of $a and $b.| 12 | |`$a % $b`|modulus|Remainder of $a divided by $b.| 13 | |`$a ** $b`|Exponentiation|Result of raising $a to the $b'th power.| 14 | 15 | ## Comparison operators 16 | 17 | |Operator|Name|Result| 18 | |--------|----|-----------| 19 | |`$a == $b`|Equal|TRUE if $a is equal to $b after type juggling.| 20 | |`$a === $b`|Identical|TRUE if $a is equal to $b, and they are of the same type.| 21 | |`$a != $b`|Not equal|TRUE if $a is not equal to $b after type juggling.| 22 | |`$a <> $b`|Not equal|TRUE if $a is not equal to $b after type juggling.| 23 | |`$a !== $b`|Not identical|TRUE if $a is not equal to $b, or they are not of the same type.| 24 | |`$a < $b`|Less than|TRUE if $a is strictly less than $b.| 25 | |`$a > $b`|Greater than|TRUE if $a is strictly greater than $b.| 26 | |`$a <= $b`|Less than or equal to|TRUE if $a is less than or equal to $b.| 27 | |`$a >= $b`|Greater than or equal to|TRUE if $a is greater than or equal to $b.| 28 | |`$a <=> $b`|Spaceship|-1 if $a is less than $b, 1 if $a is greater than $b, otherwise 0.| 29 | 30 | ## Logical operators 31 | 32 | |Operator|Name|Result| 33 | |--------|----|------| 34 | |`! $a`|Not|TRUE if $a is not TRUE.| 35 | |`$a && $b`|And|TRUE if both $a and $b are TRUE.| 36 | |`$a || $b`|Or|TRUE if either $a or $b is TRUE.| 37 | |`$a and $b`|And|Like `&&` but precedence is lower.| 38 | |`$a or $b`|Or|Like `||` but precedence is lower.| 39 | |`$a xor $b`|Xor|TRUE if either $a or $b is TRUE, but not both.| 40 | 41 | ## Simple-assignment operators 42 | 43 | The simple-assignment operator `=` assigns its right operand to its left operand. 44 | 45 | ```php 46 | >=`|`$x >>= $y`|`$x = $x >> $y`| 66 | |`&=`|`$x &= $y`|`$x = $x & $y`| 67 | |`^=`|`$x ^= $y`|`$x = $x ^ $y`| 68 | |`|=`|`$x |= $y`|`$x = $x | $y`| 69 | -------------------------------------------------------------------------------- /php/ref/predefined-variables.md: -------------------------------------------------------------------------------- 1 | # Predefined variables 2 | 3 | PHP provides multiple predefined variables. 4 | 5 | ## Superglobals 6 | 7 | ## $_GLOBALS 8 | 9 | ## $_SERVER 10 | 11 | ## $_GET 12 | 13 | ## $_POST 14 | 15 | ## $_FILES 16 | 17 | ## $_REQUEST 18 | 19 | ## $_SESSION 20 | 21 | ## $_ENV 22 | 23 | ## $_COOKIE 24 | 25 | ## $php\_errormsg 26 | 27 | ## $HTTP\_RAW\_POST\_DATA 28 | 29 | ## $http\_response\_header 30 | 31 | ## $argc 32 | 33 | ## $argv 34 | -------------------------------------------------------------------------------- /php/ref/references.md: -------------------------------------------------------------------------------- 1 | # References 2 | -------------------------------------------------------------------------------- /php/ref/sessions.md: -------------------------------------------------------------------------------- 1 | # Sessions 2 | 3 | A session is a way to store information to be used across multiple pages. 4 | 5 | Unlike a cookie, the information is not stored on the users computer. It is stored either on a file on the server, in the database (MySQL for example), or Redis. 6 | 7 | You can access the session variables through the `$_SESSION` global variable. 8 | 9 | ### Starting the session 10 | 11 | You can start the session using the `session_start()` function. If it has already started nothing will happen. 12 | 13 | Note : The `session_start()` function must be the first thing to be called in the file. 14 | 15 | ### Session configuration 16 | 17 | There are many configuration settings for sessions, and you can check them out in the [manual](https://www.php.net/manual/en/session.configuration.php), but we'll focus on just the most important ones here. 18 | 19 | - `session.name` allows you to change the default session name to the name you want. 20 | 21 | - `session.auto_start` starts the session automatically. The default is `false`. 22 | 23 | - `session.gc_maxlifetime` sets the maximum lifetime for the session before invalidating it. 24 | 25 | ### Session cookie name 26 | 27 | You can know the session name by calling the `session_name()` function. The default name is `PHPSESSID`, but you can change it easily in 4 ways: 28 | 29 | - In your `php.ini` file via the `session.name` setting. 30 | 31 | - Through Apache. 32 | 33 | - Via your `.htaccess` file. 34 | 35 | - By using the `ini_set()` function at the start of the file before calling the `session_start()` function. 36 | 37 | ### Invalidating the session 38 | 39 | You can achieve this in 3 ways: 40 | 41 | - By calling the `session_unset()` function which unsets the `$_SESSION` variable. 42 | 43 | - By expiring the session cookie in the user's browser: 44 | ```PHP 45 | setcookie(session_name(), '' ,time() - 3600); 46 | ``` 47 | 48 | - By calling the `session_destroy()` function. 49 | -------------------------------------------------------------------------------- /php/ref/types/README.md: -------------------------------------------------------------------------------- 1 | # PHP types 2 | 3 | PHP supports 10 primitive types: 4 | 5 | ## Scalar types 6 | 7 | * boolean 8 | * integer 9 | * float (float pointing number or double) 10 | * string 11 | 12 | ## Compound types 13 | 14 | * [array](arrays.md) 15 | * object 16 | * callable 17 | * iterable 18 | 19 | ## Special types 20 | 21 | * resource 22 | * NULL 23 | -------------------------------------------------------------------------------- /php/ref/types/arrays.md: -------------------------------------------------------------------------------- 1 | # Arrays 2 | 3 | Array is a container with a fixed number of elements, where each element is 4 | indexed from `0` incrementally: 5 | 6 | ```php 7 | 'bar', 22 | 'bar' => 'foo', 23 | ]; 24 | 25 | // Outputs "bar" 26 | echo $array['foo']; 27 | ``` 28 | 29 | ## Operations on arrays 30 | 31 | | Operator | Name | Result | 32 | |----------|------|--------| 33 | | `$a + $b` | Union|Union of $a and $b. | 34 | | `$a == $b` | Equality | TRUE if $a and $b have the same key/value pairs. | 35 | | `$a === $b` | Identity | TRUE if $a and $b have the same key/value pairs in the same order and of the same types. | 36 | | `$a != $b` | Inequality |TRUE if $a is not equal to $b. | 37 | | `$a <> $b` | Inequality | TRUE if $a is not equal to $b. | 38 | | `$a !== $b` | Non-identity | TRUE if $a is not identical to $b. | 39 | -------------------------------------------------------------------------------- /php/ref/variables.md: -------------------------------------------------------------------------------- 1 | # Variables 2 | 3 | Variable is used to store some value in your program. PHP variables are prefixed 4 | with a dollar sign `$`. 5 | 6 | ```php 7 | 'foo', 2 => 'bar']); 8 | var_dump($json); 9 | // string(21) "{"0":"foo","2":"bar"}" 10 | 11 | // An array with ordered indexes will be array by default 12 | $json = json_encode([0 => 'foo', 1 => 'bar']); 13 | var_dump($json); 14 | // string(13) "["foo","bar"]" 15 | 16 | // JSON_FORCE_OBJECT will make it an object 17 | $json = json_encode([0 => 'foo', 1 => 'bar'], JSON_FORCE_OBJECT); 18 | var_dump($json); 19 | // string(21) "{"0":"foo","1":"bar"}" 20 | ``` 21 | -------------------------------------------------------------------------------- /tips/arrays/README.md: -------------------------------------------------------------------------------- 1 | # Array tips 2 | 3 | * [JSON_FORCE_OBJECT](01-json-force-object.md) 4 | -------------------------------------------------------------------------------- /tips/composer/01-performance.md: -------------------------------------------------------------------------------- 1 | # Better performance with Composer 2 | 3 | Composer is de-facto standard package manager for PHP. To get better performance 4 | when installing PHP packages, use the lightning fast 5 | [prestissimo plugin](https://github.com/hirak/prestissimo). 6 | 7 | Install the plugin globally: 8 | 9 | ```bash 10 | composer require hirak/prestissimo 11 | ``` 12 | 13 | And as usual, use Composer to get a performance boost of ~10x because of 14 | parallel installations: 15 | 16 | ```bash 17 | composer install 18 | ``` 19 | -------------------------------------------------------------------------------- /tips/composer/README.md: -------------------------------------------------------------------------------- 1 | # Composer tips 2 | 3 | * [Performance](01-performance.md) 4 | -------------------------------------------------------------------------------- /tips/datetime/01-copyright-year.md: -------------------------------------------------------------------------------- 1 | # Year in the Footer 2 | 3 | Many websites include current year and copyright info in the footer. A neat way 4 | to stay current is to output the year dynamically. 5 | 6 | Instead of this: 7 | 8 | ```php 9 | echo '2016 © Acme'; 10 | ``` 11 | 12 | You can output the current year dynamically: 13 | 14 | ```php 15 | echo date('Y').' © Acme'; 16 | ``` 17 | -------------------------------------------------------------------------------- /tips/datetime/02-datetime.md: -------------------------------------------------------------------------------- 1 | # DateTime::createFromFormat 2 | 3 | Pipe and exclamation mark characters reset all fields (year, month, day, hour, 4 | minute, second, fraction, and timezone information) to the Unix Epoch. 5 | 6 | http://php.net/manual/en/datetime.createfromformat.php 7 | 8 | ```php 9 | $date = '2015-10-21'; 10 | 11 | $date_1 = DateTime::createFromFormat('Y-m-d', $date); 12 | 13 | // Y-m-d| will set the year, month and day to the information found 14 | // in the string to parse, and sets the hour, minute and second to 0. 15 | $date_2 = DateTime::createFromFormat('Y-m-d|', $date); 16 | 17 | var_dump($date_1->format('r'), $date_2->format('r')); 18 | // string(31) "Wed, 21 Oct 2015 04:32:09 +0200" 19 | // string(31) "Wed, 21 Oct 2015 00:00:00 +0200" 20 | ``` 21 | -------------------------------------------------------------------------------- /tips/datetime/03-easter.md: -------------------------------------------------------------------------------- 1 | # How to get the date of Easter in PHP? 2 | 3 | If PHP is compiled with `--enable-calendar`, you can use `easter_date()`: 4 | http://php.net/manual/en/function.easter-date.php 5 | 6 | ```php 7 | if (time() <= easter_date(2017)) { 8 | echo 'HaPHPy Easter!'; 9 | } 10 | ``` 11 | 12 | and `easter_days()`: 13 | http://php.net/manual/en/function.easter-days.php 14 | 15 | The computation of the date of Easter can also be done [manually](https://en.wikipedia.org/wiki/Computus). 16 | -------------------------------------------------------------------------------- /tips/datetime/README.md: -------------------------------------------------------------------------------- 1 | # Date and time tips 2 | 3 | * [Copyright year](01-copyright-year.md) 4 | * [DateTime](02-datetime.md) 5 | * [How to get the date of Easter in PHP?](03-easter.md) 6 | -------------------------------------------------------------------------------- /tips/oop/01-visibility.md: -------------------------------------------------------------------------------- 1 | # Visibility 2 | 3 | Private and protected properties of classes are not about security, but provide 4 | information about the code for users, to let them know how to use them. 5 | 6 | http://php.net/manual/en/language.oop5.visibility.php 7 | 8 | Private and protected properties can be read by converting objects to arrays, 9 | closures, or by reverse-engineering using the reflection API. 10 | 11 | ```php 12 | class Foo 13 | { 14 | private $private = "private"; 15 | protected $protected = "protected"; 16 | } 17 | ``` 18 | 19 | Retrieving the private property value directly results in a fatal error: 20 | 21 | ```php 22 | $foo = new Foo(); 23 | var_dump($foo->private); 24 | // PHP Fatal error: Uncaught Error: Cannot access private property Foo::$private in 7.php: 17 25 | ``` 26 | 27 | Converting to an array: 28 | 29 | ```php 30 | $foo = (array) $foo; 31 | var_dump($foo["\0Foo\0private"]); 32 | var_dump($foo["\0*\0protected"]); 33 | // string(7) "private" 34 | // string(7) "protected" 35 | ``` 36 | 37 | Using the reflection API: 38 | 39 | ```php 40 | $foo = new Foo(); 41 | $reflection = new ReflectionObject($foo); 42 | $private = $reflection->getProperty('private'); 43 | $private->setAccessible(true); 44 | var_dump($private->getValue($foo)); 45 | // string(7) "private" 46 | 47 | $protected = $reflection->getProperty('protected'); 48 | $protected->setAccessible(true); 49 | var_dump($protected->getValue($foo)); 50 | // string(7) "protected" 51 | ``` 52 | 53 | Using a closure: 54 | 55 | ```php 56 | $foo = new Foo(); 57 | var_dump((function(){return $this->private;})->bindTo($foo, $foo)()); 58 | var_dump((function(){return $this->protected;})->bindTo($foo, $foo)()); 59 | // string(7) "private" 60 | // string(7) "protected" 61 | ``` 62 | -------------------------------------------------------------------------------- /tips/oop/README.md: -------------------------------------------------------------------------------- 1 | # OOP tips 2 | 3 | * [Visibility](01-visibility.md) 4 | -------------------------------------------------------------------------------- /tips/strings/01-emails.md: -------------------------------------------------------------------------------- 1 | # Validating emails 2 | 3 | You can use PHP filters to validate emails with PHP - `FILTER_VALIDATE_EMAIL`. 4 | 5 | ```php 6 | $email = $_POST['email'] ?? null; 7 | 8 | if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { 9 | $error = 'Invalid email'; 10 | } 11 | ``` 12 | -------------------------------------------------------------------------------- /tips/strings/README.md: -------------------------------------------------------------------------------- 1 | # Strings tips 2 | 3 | * [Validating emails](01-emails.md) 4 | -------------------------------------------------------------------------------- /tips/style/01-ifs.md: -------------------------------------------------------------------------------- 1 | # Return from if statements as soon as possible 2 | 3 | ```php 4 | function foo($bar, $baz) { 5 | if (!checkSomething($bar, $baz)) { 6 | if (!findSomething($bar, $baz)) { 7 | if (!checkFoo($bar, $baz)) { 8 | if (count($bar) > 0 && $baz == 1) { 9 | doSomething(); 10 | } 11 | } 12 | } 13 | } 14 | } 15 | ``` 16 | 17 | Instead, this is much more readable and manageable: 18 | 19 | ```php 20 | function foo($bar, $baz) { 21 | if (checkSomething($bar)) { 22 | return; 23 | } 24 | 25 | if (findSomething($bar, $baz)) { 26 | return; 27 | } 28 | 29 | if (checkFoo($bar, $baz)) { 30 | return; 31 | } 32 | 33 | if (!(count($bar) > 0 && $baz == 1)) { 34 | return; 35 | } 36 | 37 | doSomething(); 38 | } 39 | ``` 40 | -------------------------------------------------------------------------------- /tips/style/README.md: -------------------------------------------------------------------------------- 1 | # Style tips 2 | 3 | * [Return from if statements as soon as possible](01-ifs.md) 4 | -------------------------------------------------------------------------------- /tips/unicorns/01-comments.md: -------------------------------------------------------------------------------- 1 | # Comments 2 | 3 | When you want to comment out a chunk of code, you can do so by just removing a 4 | single backslash. 5 | 6 | ```php 7 | //* 8 | $debug = true; 9 | die(var_dump($debug)); 10 | //*/ 11 | ``` 12 | 13 | ```php 14 | /* 15 | $debug = true; 16 | die(var_dump($debug)); 17 | //*/ 18 | ``` 19 | -------------------------------------------------------------------------------- /tips/unicorns/02-dir.md: -------------------------------------------------------------------------------- 1 | # Including files 2 | 3 | When dealing with file includes, `__DIR__` can be a significant help. 4 | 5 | ```php 6 | include __DIR__.'/../relative/path/to/file.php'; 7 | ``` 8 | -------------------------------------------------------------------------------- /tips/unicorns/03-haystack-needle.md: -------------------------------------------------------------------------------- 1 | # Haystack/Needle 2 | 3 | All string functions are haystack/needle, and array functions are needle/haystack, 4 | except for `array_filter()`. 5 | -------------------------------------------------------------------------------- /tips/unicorns/04-ternary-operator.md: -------------------------------------------------------------------------------- 1 | # Ternary Operator 2 | 3 | Most times the same action can be done with the ternary operator. The following 4 | lines of code show same conditional usages. 5 | 6 | ```php 7 | if ($i === 2) { 8 | $j = 0; 9 | } else { 10 | ++$j; 11 | } 12 | ``` 13 | 14 | With ternary operator you can do a one-liner: 15 | 16 | ```php 17 | $j = ($i === 2) ? 0 : ++$j; 18 | ``` 19 | -------------------------------------------------------------------------------- /tips/unicorns/README.md: -------------------------------------------------------------------------------- 1 | # Other PHP tips 2 | 3 | * [Comments](01-comments.md) 4 | * [Including files](02-dir.md) 5 | * [Haystack/Needle](03-haystack-needle.md) 6 | * [Ternary operator](04-ternary-operator.md) 7 | --------------------------------------------------------------------------------