PHP's Built-In Web Server Install PHP

Often times I need to test PHP code quickly. Luckily, PHP has a built-in web server! Using the PHP web server is quite simple if you remember the commands.

The first step is to change to the directory with your PHP file.

cd /path/to/your/website

Next, you need to switch on the PHP built-in web server. 

php -S localhost:8080

The above command will start a PHP built-in web server that can be accessed in your browser at http://localhost:8080.

Using another directory

Another option is to use the -t flag. This allows you to set the document root relative to your current directory.

php -S localhost:8080 -t test/alternate

The previous command will start a PHP built-in web server that can be accessed in your browser at http://localhost:8080. However, the files will be served from the subdirectory ./test/alternate

 

Install PHP 7.1

Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install it.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.1

Now use the following command to check installed php version on your system.

php -v 

PHP 7.1.0-5+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.1.0-5+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies

Install PHP 7.0

Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install it.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.0

Now use the following command to check installed php version on your system.

php -v 

PHP 7.0.14-2+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.14-2+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies

Install PHP 7 Modules

You may also need to install modules based on your application requirements. Use the following command to find our available php 7 modules.

sudo apt-cache search php7-* 

php-all-dev - package depending on all supported PHP development packages
php7.0 - server-side, HTML-embedded scripting language (metapackage)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-common - documentation, examples and common module for PHP
php7.0-curl - CURL module for PHP
php7.0-dev - Files for PHP7.0 module development
php7.0-gd - GD module for PHP
php7.0-gmp - GMP module for PHP
...
...
...
php7.1-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php7.1-xmlrpc - XMLRPC-EPI module for PHP
php7.1-zip - Zip module for PHP
php7.1-opcache - Zend OpCache module for PHP
php7.1 - server-side, HTML-embedded scripting language (metapackage)
php7.1-xsl - XSL module for PHP (dummy)

Now install modules which is required for you.

sudo apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi

Congratulation! Enjoy the development with PHP 7.

Install additional packages

sudo apt-get install php-curl php-gd php-mbstring php-mcrypt php-xml php-xmlrpc

 

Visit sunny St. George, Utah, USA

Get In Touch

We would love to hear from you.

Please enter your email address.
Please enter a valid email address.
Please enter the verification number.
You have entered a wrong verification number.
Please enter a message.
Please check your message for any errors.
Your message has been sent successfully.
Sorry, error occured this time sending your message.
* required