blob: e8ad3806021cd06a55adae2bdde461c8142cae2f [file] [log] [blame]
<!-- jQuery Eclipse IP approval https://dev.eclipse.org/ipzilla/show_bug.cgi?id=10801 -->
<script type="text/javascript" charset="utf8" src="../../../docs/assets/scripts/jquery-1.8.1.min.js"></script>
<script type="text/javascript" charset="utf8">
$(document).ready(function(){
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
var image = images[i];
var parentElement = image.parentElement;
var a = document.createElement('a');
if (! image.getAttribute('src').includes("logo-codenvy.svg") && ! image.getAttribute('src').includes("codenvy-contribute.svg") ){
a.href = image.getAttribute('src');
a.target = "_blank";
a.appendChild(image);
parentElement.appendChild(a);
}
}
});
</script>
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>PHP -
Tutorials
- Eclipse Che</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="generator" content="Jekyll v3.5.1">
<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic,900">
<link rel="stylesheet" href="../../../docs/assets/css/screen.css">
<link rel="icon" type="image/x-icon" href="../../../docs/assets/imgs/favicon.ico">
<!--[if lt IE 9]>
<script src="/js/html5shiv.min.js"></script>
<script src="/js/respond.min.js"></script>
<![endif]-->
</head>
<body class="wrap">
<header>
<nav class="mobile-nav show-on-mobiles">
<ul>
<li class="">
<a href="../../../docs/index.html">Docs</a>
</li>
<li class="current">
<a href="../../../docs/tutorials/multi-machine/index.html">Tutorials</a>
</li>
<li class="">
<a href="../../../docs/openshift/config/index.html">OpenShift</a>
</li>
<li>
<a href="https://github.com/eclipse/che-docs/tree/master/src/main">GitHub</a>
</li>
</ul>
</nav>
<div class="grid">
<div class="unit one-third center-on-mobiles">
<a href="https://eclipse.org/che/">
<span class="sr-only">Eclipse Che</span>
<img src="../../../docs/assets/imgs/logo-eclipseche.svg" alt="Eclipse Che Logo" width="249" height="115">
</a>
</div>
<nav class="main-nav unit two-thirds hide-on-mobiles">
<ul>
<li class="">
<a href="../../../docs/index.html">Docs</a>
</li>
<li class="current">
<a href="../../../docs/tutorials/multi-machine/index.html">Tutorials</a>
</li>
<li class="">
<a href="../../../docs/openshift/config/index.html">OpenShift</a>
</li>
<li>
<a href="https://github.com/eclipse/che-docs/tree/master/src/main">GitHub</a>
</li>
</ul>
</nav>
</div>
</header>
<section class="tutorials">
<div class="grid">
<div class="docs-nav-mobile unit whole show-on-mobiles">
<select onchange="if (this.value) window.location.href=this.value">
<option value="">Navigate the docs…</option>
<optgroup label="User Tutorials">
<ul>
</ul>
<ul>
<li class=""><a href="../../../docs/tutorials/multi-machine/index.html">Multi-Machine Workspaces</a></li>
<li class=""><a href="../../../docs/tutorials/maven/index.html">Java+Maven</a></li>
<li class=""><a href="../../../docs/tutorials/gradle/index.html">Java+Gradle</a></li>
<li class=""><a href="../../../docs/tutorials/java/index.html">Java Console Apps</a></li>
<li class=""><a href="../../../docs/tutorials/swing/index.html">Java Swing</a></li>
<li class=""><a href="../../../docs/tutorials/nodejs/index.html">Node.js</a></li>
<li class=""><a href="../../../docs/tutorials/angular2/index.html">Angular 2</a></li>
<li class=""><a href="../../../docs/tutorials/meteor/index.html">Meteor</a></li>
<li class=""><a href="../../../docs/tutorials/wordpress/index.html">Wordpress</a></li>
<li class="current"><a href="../../../docs/tutorials/php/index.html">PHP</a></li>
<li class=""><a href="../../../docs/tutorials/composer/index.html">Composer</a></li>
<li class=""><a href="../../../docs/tutorials/android/index.html">Android</a></li>
<li class=""><a href="../../../docs/tutorials/spring-boot/index.html">Spring Boot</a></li>
<li class=""><a href="../../../docs/tutorials/rails/index.html">Rails</a></li>
<li class=""><a href="../../../docs/tutorials/laravel/index.html">Laravel</a></li>
<li class=""><a href="../../../docs/tutorials/tomee/index.html">TomEE</a></li>
<li class=""><a href="../../../docs/tutorials/che-in-che/index.html">Che in Che</a></li>
<li class=""><a href="../../../docs/tutorials/gae/index.html">Google App Engine</a></li>
<li class=""><a href="../../../docs/tutorials/che-and-appfog/index.html">AppFog</a></li>
<li class=""><a href="../../../docs/tutorials/subversion/index.html">Subversion Repos</a></li>
<li class=""><a href="../../../docs/tutorials/ftpsftp/index.html">FTP/SFTP</a></li>
<li class=""><a href="../../../docs/tutorials/cuba/index.html">Cuba Platform</a></li>
<li class=""><a href="../../../docs/tutorials/sourcegraph/index.html">Sourcegraph</a></li>
<li class=""><a href="../../../docs/tutorials/vaadin/index.html">Vaadin</a></li>
<li class=""><a href="../../../docs/tutorials/platformio/index.html">PlatformIO</a></li>
</ul>
</optgroup>
</select>
</div>
<div class="unit four-fifths">
<article>
<div class="improve right hide-on-mobiles">
<a href="https://github.com/codenvy/che-docs/blob/master/src/main/_docs/tutorials/tutorial-php.md"><i class="fa fa-pencil"></i> &nbsp;Improve this page</a>
<!--<a href="https://github.com/eclipse/che/blob/master/docs/_docs/tutorials/tutorial-php.md"><i class="fa fa-pencil"></i> &nbsp;Improve this page</a>-->
</div>
<div class="doc-title">
<h1>PHP</h1>
<div class="doc-title-border">
</div>
</div>
<h1 id="1-create-a-php-project">1. Create a PHP Project</h1>
<p>Start Che, create a PHP project using a sample app:</p>
<p><img src="../../../docs/assets/imgs/php.png" alt="php.png" /></p>
<h1 id="2-explore-and-modify-the-project-code">2. Explore and Modify the Project Code</h1>
<p>The sample project contains just a simple “Hello World!” script written in PHP.</p>
<p>Expand the project’s source tree in the Project Explorer panel on the left side of the screen. Double-click on the <code class="highlighter-rouge">index.php</code> file to open it in the PHP editor.</p>
<p>The <code class="highlighter-rouge">index.php</code> file contains a single instruction that will print “Hello World!” to the standard output.</p>
<div class="language-php highlighter-rouge"><pre class="highlight"><code><span class="cp">&lt;?php</span>
<span class="k">echo</span> <span class="s2">"Hello World!"</span><span class="p">;</span>
</code></pre>
</div>
<p>You can use the editor to edit the script. The PHP editor provides rich <a href="../../../docs/ide/intellisense/index.html">IntelliSense</a> features like syntax hightlighting, code completion, code validation, code navigation, etc.</p>
<h1 id="3-execute-as-a-script">3. Execute as a Script</h1>
<p>The PHP stack has the <code class="highlighter-rouge">run php script</code> command that allows you to run the currently opened PHP file as a CLI script, i.e. the output of the PHP script will be printed in the Terminal panel.</p>
<p>While you have the <code class="highlighter-rouge">index.php</code> file on focus in the PHP editor, run the <code class="highlighter-rouge">run php script</code> command in the CMD command widget. “Hello World!” will be printed in the Terminal panel.</p>
<p><img src="../../../docs/assets/imgs/tutorial-php-1.png" alt="php.png" /></p>
<h1 id="4-run-as-a-web-app">4. Run as a Web App</h1>
<p>The PHP stack includes the Apache Web Server and has commands for starting, stopping and restarting it.</p>
<p><code class="highlighter-rouge">start apache</code> will start the server and tail apache error and access logs. It will also produce a preview URL that will point to your current project directory that Apache is already listening (Document root is changed to <code class="highlighter-rouge">projects</code>).</p>
<p>You should see a Hello World page. Open <code class="highlighter-rouge">index.php</code>, edit it, refresh the preview page in your browser to see live changes.</p>
<p><img src="../../../docs/assets/imgs/tutorial-php-2.png" alt="php.png" /></p>
<h1 id="5-debug">5. Debug</h1>
<p>The PHP stack includes the Zend Debugger module, which allows debugging PHP both as CLI script and Web app. See the <a href="../../../docs/ide/debug/index.html#php">Debug - PHP</a> page for details.</p>
<h1 id="6-composer-and-unit-tests">6. Composer and Unit Tests</h1>
<p>A PHP stack has <a href="https://getcomposer.org/">Composer</a> already installed and configured. Composer is used to manage project dependencies, i.e. makes it easy to use 3rd party libs and frameworks. Look at the <a href="../../../docs/tutorials/composer/index.html">Composer tutorial</a> for more details on how to work with Composer in Che.</p>
<p>Let’s add the <a href="https://phpunit.de/">PHPUnit</a> testing framework and write a simple Unit test.</p>
<p>In project root, create <code class="highlighter-rouge">composer.json</code> file with the following contents:</p>
<div class="language-json highlighter-rouge"><pre class="highlight"><code><span class="p">{</span><span class="w">
</span><span class="nt">"require-dev"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="nt">"phpunit/phpunit"</span><span class="p">:</span><span class="w"> </span><span class="s2">"^6.1"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre>
</div>
<p>The JSON editor provides IntelliSense too. It provides code completion and validation according to the composer.json schema.</p>
<p>In the <code class="highlighter-rouge">Processes</code> panel, click New Terminal (+) button. This will open up a bash terminal:</p>
<div class="language-sh highlighter-rouge"><pre class="highlight"><code><span class="gp">$ </span><span class="nb">cd</span> /projects/web-php-simple
<span class="gp">$ </span>composer update
</code></pre>
</div>
<p>This will install the <code class="highlighter-rouge">phpunit</code> framework into <code class="highlighter-rouge">vendor</code> directory in the project.</p>
<p>Now, let’s write a simple test. Create a <code class="highlighter-rouge">test.php</code> file:</p>
<div class="language-php highlighter-rouge"><pre class="highlight"><code><span class="cp">&lt;?php</span>
<span class="k">use</span> <span class="nx">PHPUnit\Framework\TestCase</span><span class="p">;</span>
<span class="k">class</span> <span class="nc">SimpleTest</span> <span class="k">extends</span> <span class="nx">TestCase</span> <span class="p">{</span>
<span class="k">public</span> <span class="k">function</span> <span class="nf">testTrueIsTrue</span><span class="p">()</span> <span class="p">{</span>
<span class="nv">$foo</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
<span class="nv">$this</span><span class="o">-&gt;</span><span class="na">assertTrue</span><span class="p">(</span><span class="nv">$foo</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre>
</div>
<p>This test basically checks nothing but demonstrates use of composer-provided frameworks.</p>
<p>Run the test. Right-click on the <code class="highlighter-rouge">test.php</code> file and select <code class="highlighter-rouge">Run Test</code> &gt; <code class="highlighter-rouge">PHPUnit</code>. The test will be executed and the result will be displayed in the <code class="highlighter-rouge">Test Results</code> pane.</p>
<p><img src="../../../docs/assets/imgs/phpunit-results.png" alt="phpunit-results.png" /></p>
</article>
</div>
<div class="unit one-fifth hide-on-mobiles">
<aside>
<h4>User Tutorials</h4>
<ul>
<li class=""><a href="../../../docs/tutorials/multi-machine/index.html">Multi-Machine Workspaces</a></li>
<li class=""><a href="../../../docs/tutorials/maven/index.html">Java+Maven</a></li>
<li class=""><a href="../../../docs/tutorials/gradle/index.html">Java+Gradle</a></li>
<li class=""><a href="../../../docs/tutorials/java/index.html">Java Console Apps</a></li>
<li class=""><a href="../../../docs/tutorials/swing/index.html">Java Swing</a></li>
<li class=""><a href="../../../docs/tutorials/nodejs/index.html">Node.js</a></li>
<li class=""><a href="../../../docs/tutorials/angular2/index.html">Angular 2</a></li>
<li class=""><a href="../../../docs/tutorials/meteor/index.html">Meteor</a></li>
<li class=""><a href="../../../docs/tutorials/wordpress/index.html">Wordpress</a></li>
<li class="current"><a href="../../../docs/tutorials/php/index.html">PHP</a></li>
<li class=""><a href="../../../docs/tutorials/composer/index.html">Composer</a></li>
<li class=""><a href="../../../docs/tutorials/android/index.html">Android</a></li>
<li class=""><a href="../../../docs/tutorials/spring-boot/index.html">Spring Boot</a></li>
<li class=""><a href="../../../docs/tutorials/rails/index.html">Rails</a></li>
<li class=""><a href="../../../docs/tutorials/laravel/index.html">Laravel</a></li>
<li class=""><a href="../../../docs/tutorials/tomee/index.html">TomEE</a></li>
<li class=""><a href="../../../docs/tutorials/che-in-che/index.html">Che in Che</a></li>
<li class=""><a href="../../../docs/tutorials/gae/index.html">Google App Engine</a></li>
<li class=""><a href="../../../docs/tutorials/che-and-appfog/index.html">AppFog</a></li>
<li class=""><a href="../../../docs/tutorials/subversion/index.html">Subversion Repos</a></li>
<li class=""><a href="../../../docs/tutorials/ftpsftp/index.html">FTP/SFTP</a></li>
<li class=""><a href="../../../docs/tutorials/cuba/index.html">Cuba Platform</a></li>
<li class=""><a href="../../../docs/tutorials/sourcegraph/index.html">Sourcegraph</a></li>
<li class=""><a href="../../../docs/tutorials/vaadin/index.html">Vaadin</a></li>
<li class=""><a href="../../../docs/tutorials/platformio/index.html">PlatformIO</a></li>
</ul>
</aside>
</div>
<div class="clear"></div>
</div>
</section>
<script>
var anchorForId = function (id) {
var anchor = document.createElement("a");
anchor.className = "header-link";
anchor.href = "#" + id;
anchor.innerHTML = "<span class=\"sr-only\">Permalink</span><i class=\"fa fa-link\"></i>";
anchor.title = "Permalink";
return anchor;
};
var linkifyAnchors = function (level, containingElement) {
var headers = containingElement.getElementsByTagName("h" + level);
for (var h = 0; h < headers.length; h++) {
var header = headers[h];
if (typeof header.id !== "undefined" && header.id !== "") {
header.appendChild(anchorForId(header.id));
}
}
};
document.onreadystatechange = function () {
if (this.readyState === "complete") {
var contentBlock = document.getElementsByClassName("artik")[0] || document.getElementsByClassName("openshift")[0] || document.getElementsByClassName("tutorials")[0] || document.getElementsByClassName("docs")[0] || document.getElementsByClassName("news")[0];
if (!contentBlock) {
return;
}
for (var level = 1; level <= 6; level++) {
linkifyAnchors(level, contentBlock);
}
}
};
</script>
</body>
</html>