
Actually to start learning PHP programming, we don't need a lot of tools.
Enough with these 4 tools:
- PHP;
- Composer;
- Text Editor;
- 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:

If there are questions that appear, press enter and answer no, because later we can edit.
The composer will create a file
composer.json
with 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-php
with 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
.
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
.

The result is "Not Found" because there are no PHP files that we have created.
Creating a PHP Program
Make a file
index.php
with contents like this:<?php
echo "Hello World!";

After that, refresh the browser.
Then it will look like this:

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

Reference: https://www.petanikode.com/php-project/
0 Komentar untuk "Make a PHP Project with a Composer"
Silahkan berkomentar sesuai artikel