Blog for Learning

| lesson material | material summary | questions and answers | definitions | types and examples | other information | materi pelajaran | ringkasan materi | pertanyaan dan jawaban | definisi | jenis-jenis dan contoh-contoh | informasi lainnya |

Powered by Blogger.

Pages

Make a PHP Project with a Composer

Project with Composer
Actually to start learning PHP programming, we don't need a lot of tools.
Enough with these 4 tools:
  1. PHP;
  2. Composer;
  3. Text Editor;
  4. and Browser.
We can already make PHP projects with the latest technology.
Let's try ...

Creating a PHP Project with Composer

Make sure the composer is installed on your computer. I have discussed how to install it in: How to Use Composer for PHP Project Management .
Type the following command to create a new project:
mkdir <nama project>
cd <nama project>
composer init
First we must create a new directory with the command mkdir, then enter the directory with the command cd.
After that, we can create a new project there with the command composer init.
Example:
Create a new project with composer
If there are questions that appear, press enter and answer no, because later we can edit.
The composer will create a file composer.jsonwith contents like this:
{
    "name": "petanikode/belajar-php",
    "authors": [
        {
            "name": "Ardianta",
            "email": "dian@petanikode.com"
        }
    ],
    "require": {}
}
this is information about our project.
Next, please open the directory belajar-phpwith the text editor.
PHP project in the text editor

Run PHP Server with Composer

Actually we can run the server with this command:
php -S localhost:8080
But because we want to use composers to do it, we have to add the command inside composer.json.
The script is composed by JSON
After that, we can execute with the command:
composer server
Open the terminal, then type the command. Then the PHP server will run on the port 8080.
Running a PHP server
Now let's open the browser and navigate to the address http: // localhost: 8080 .
The PHP server is running
The result is "Not Found" because there are no PHP files that we have created.

Creating a PHP Program

Make a file index.phpwith contents like this:
<?php

echo "Hello World!";
PHP Hello World Program
After that, refresh the browser.
Then it will look like this:
PHP Hello World Program
Easy isn't it.
Next, try making another PHP file.
File: about.php
<?php

echo "<h1>About me</h1>";
echo "Saya adalah programmer PHP yang suka PHPin komputer<br>";
echo "Kadang komputernya sampai hang dan saya bingung mau ngapain";
After that open the address: http: // localhost: 8080 / about.php
PHP About Me Program

0 Komentar untuk "Make a PHP Project with a Composer"

Silahkan berkomentar sesuai artikel

 
Template By Kunci Dunia
Back To Top