The Electrical Power Crash Is Just Like a Stock Market Crash

Electrical grids are designed to survive outages at generating plants, but system designers assume the failures will come one at a time and randomly. This time diversification failed because the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How do I install PHP in my computer ?

For Windows machines, there is one tool called as XAMPP which is a complete set of softwares and tools required for web development. XAMPP includes Apache Server, MySQL, PHP and Perl (eerl…we will talk about it later)

X: [cross platform operating systems] meaning it can run on any OS Mac OX , Windows , Linux etc.

Apache: a local server to deploy you development to test applications

MySQL: PHP always comes with MySQL

PHP: You already know about it, right..?

Perl: Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages.

XAMPP creates a directory structure in c:\xampp path similar to this:

php-cgi is intended for a webserver. Among other things it handles HTTP headers for you.

To start with PHP installation on ubuntu we have some prerequisites like:

Run the below commands one by one:

sudo apt update
sudo apt upgrade
sudo apt install apache2

That’s it, Apache2 is installed and started automatically. You can check the Apache2 service status by using the following command:

sudo systemctl status apache2

● apache2.service — The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019–04–16 00:35:04 UTC; 1h 30min ago
Process: 1376 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Process: 1381 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 1396 (apache2)
Tasks: 11 (limit: 502)
Memory: 84.1M
CGroup: /system.slice/apache2.service
├─1396 /usr/sbin/apache2 -k start
├─2159 /usr/sbin/apache2 -k start
├─2160 /usr/sbin/apache2 -k start
├─2161 /usr/sbin/apache2 -k start
├─2162 /usr/sbin/apache2 -k start
├─2163 /usr/sbin/apache2 -k start
├─2164 /usr/sbin/apache2 -k start
├─2165 /usr/sbin/apache2 -k start
├─2166 /usr/sbin/apache2 -k start
├─2167 /usr/sbin/apache2 -k start
└─2198 /usr/sbin/apache2 -k start

Apr 16 00:35:04 stocklot.pk systemd[1]: Starting The Apache HTTP Server…
Apr 16 00:35:04 stocklot.pk systemd[1]: Started The Apache HTTP Server.

The other following commands can be used to stop, start and enable Apache2 service.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

So now you have installed Apache server on your ubuntu, now we are installing PHP 7, 7.2 to be exact,

sudo apt-get install software-properties-common

sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update

sudo apt-get install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-curl php7.2-mbstring php7.2-xmlrpc php7.2-mysql php7.2-gd php7.2-xml php7.2-intl php7.2-ldap php7.2-imagick php7.2-json php7.2-cli

php -v

You should see this:

PHP 7.2.17–1+ubuntu18.10.1+deb.sury.org+3 (cli) (built: Apr 10 2019 10:51:33) ( NTS )
Copyright © 1997–2018 The PHP Group
Zend Engine v3.2.0, Copyright © 1998–2018 Zend Technologies
with Zend OPcache v7.2.17–1+ubuntu18.10.1+deb.sury.org+3, Copyright © 1999–2018, by Zend Technologies

Step 4: Restart Apache2

After installing PHP and related modules, all you have to do is restart Apache2 to reload PHP configurations.

To restart Apache2, run the commands below

sudo systemctl restart apache2.service

To test PHP 7.2 settings with Apache2, create a phpinfo.php file in Apache2 root directory by running the following command:

sudo nano /var/www/html/phpinfo.php

Then type the content below and save the file.

<?php phpinfo(); ?>

Save the file and browse to your server hostname followed by /phpinfo.php. You should see PHP default test page.

May be you might have an old PHP version like PHP 5.6 in your system and you installed PHP 7.2 too so thats multiple PHP in your machine. There are some applications which were developed when older PHP 5.6 was latest version, they are still live and you working on those applications, You might be working on Laravel simultaneously but Laravel requires PHP 7+ to get started. Getting the picture ?

In that case you can switch between the PHP versions to suit your requirements.

Switch From PHP 5.6 => PHP 7.2

Apache:-

sudo a2dismod php5.6
sudo a2enmod php7.2
sudo service apache2 restart

Command Line:-

sudo update-alternatives — set php /usr/bin/php7.2
sudo update-alternatives — set phar /usr/bin/phar7.2
sudo update-alternatives — set phar.phar /usr/bin/phar.phar7.2
sudo update-alternatives — set phpize /usr/bin/phpize7.2
sudo update-alternatives — set php-config /usr/bin/php-config7.2

And vice-versa, Switch From PHP 7.2 => PHP 5.6

Apache:-

sudo a2dismod php7.2
sudo a2enmod php5.6
sudo service apache2 restart

Command Line:-

sudo update-alternatives — set php /usr/bin/php5.6
sudo update-alternatives — set phar /usr/bin/phar5.6
sudo update-alternatives — set phar.phar /usr/bin/phar.phar5.6
sudo update-alternatives — set phpize /usr/bin/phpize5.6
sudo update-alternatives — set php-config /usr/bin/php-config5.6

How do I install PHP on Apple-Mac ?

Prerequisites:

Terminal: You must have Mac Terminal access and little knowledge about working with the terminal application. To login to your Mac system and open terminal

Homebrew: Homebrew is a popular package manager for the Mac operating systems. It is useful for installing most open source software like Node.

Open the terminal and run the below command:

Verify PHP Installation

The PHP versions for macOS are maintained by php-osx and doesn’t overwrite the current php binaries installed on your system. The installs everything in /usr/local/php5. The new php binary is therefore in /usr/local/php5/bin/php.

export PATH=/usr/local/php5/bin:$PATH

Rest is the same process as mentioned for Ubuntu. :)

Do I need to install other softwares too after PHP installation ?

Yeah, there are. Where would you write your code ? You definitely need a good editor for it.

Below are my recommended editor you can choose from:

So guys, I hope I have given you a complete tutorial on how to install PHP on your system. Somethin’ not working ? Getting error ? Do comment below, I will try to resolve your queries ASAP.

Add a comment

Related posts:

I am only after my own lost loves

Who ever really changes anyone else’s mind with a song, or a poem? Or a dramatic monolog of love and longing? Does that ever move anyone who was a little bit repulsed by you towards a state of…

Background

Dengue remains a public health crisis in Singapore. This project is to predict the number of dengue cases in the next eight weeks to aid with dengue prevention efforts. We create models based on…