![Project with Composer](https://d33wubrfki0l68.cloudfront.net/190b80fa89b7424a06929d37a080345584859660/6c8fc/img/php/composer/composer.png)
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:
![Create a new project with composer](https://d33wubrfki0l68.cloudfront.net/bcdacdc60f8f5d4d58f5c38f9449aa9e1ea961f9/ea09a/img/php/project/composer-init.png)
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.![PHP project in the text editor](https://d33wubrfki0l68.cloudfront.net/44963ac86e7408c793b871def7397623a818d08b/2ae02/img/php/project/teks-editor.png)
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](https://d33wubrfki0l68.cloudfront.net/aa45afacb356f4c7efca82bb08e1be8f5b075343/5a6ee/img/php/project/composer-json.png)
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](https://d33wubrfki0l68.cloudfront.net/873db96522b48f0d9226a0057e9fe36a9a772e8c/53de5/img/php/project/server-php.png)
![The PHP server is running](https://d33wubrfki0l68.cloudfront.net/86c5c078ca51719b57ba8cff1bd24396873c4b1b/acd2c/img/php/project/browser.png)
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!";
![PHP Hello World Program](https://d33wubrfki0l68.cloudfront.net/9c09bb386cba3b1f7f472a4a3aa958d9e5471811/e3bab/img/php/project/program-php.png)
After that, refresh the browser.
Then it will look like this:
![PHP Hello World Program](https://d33wubrfki0l68.cloudfront.net/f88734a0322be387592b0d50349d552ea4c71a96/f50c1/img/php/project/hello-world.png)
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](https://d33wubrfki0l68.cloudfront.net/9b4fce61526bc0c7019c8137942e670b38e087db/03bdb/img/php/project/program-about.png)
Reference: https://www.petanikode.com/php-project/
0 Komentar untuk "Make a PHP Project with a Composer"
Silahkan berkomentar sesuai artikel