In this article you will learn how to install PHP on Windows, Linux systems and how to configure it with basic extensions and minimum configuration settings.
Install PHP on Windows 10 systems
To download the latest version of PHP Click here. There you can see different versions of PHP. It is suggestible to always download the stable version. First make choice to download 'Thread Safe' or 'Non Thread Safe', in general always download 'Thread safe' version unless you use 'FastCGI'.
- Extarct to 'C:\' drive to a folder C:\php7.3 with it's version.
- Rename php.ini-development to php.ini.
- Edit the php.ini file using any editor and do the following changes and save.
- Increase memory_limit from '128M' to '1G' if you use 'composer' for dependency manager as it needs more space.
- Enable to load extensions by uncommenting ;extension_dir = "ext" (uncommenting means remove ';' at the begining) to become like this extension_dir = "ext".
Also enable the following extensions by uncommenting them, which are minimum required for any project.
- By adding C:\php7.3 to system PATH we can enable global use of 'Php' from command line like 'cmd' and 'PowerShell'.
- If an error 'VCRUNTIME140.DLL was not found' is encountered while using 'php' commands download and install Visual C++ Redistributable for Visual Studio 2015.
Now you can verify it's installtion using the following command. Which shows the "PHP" version installed, if you get this message as shown below means you have successfully installed "PHP" on your Windows system.
Read this: What is composer and how to install it?
Install PHP on Ubuntu 20.04Step-1 Update Repositories
Update your Ubuntu system repositories before proceeding for PHP installation using command.
Step-2 Install PHP
$ sudo apt update
After updating is complete first make sure to install which version of "PHP". To install a particular version of "PHP" run the following command.
$ sudo apt install -y php7.x
Here 7.X represents the verison of PHP you want to install. Replace this with your required version.Step-3 Verify PHP Installation
Now verify your PHP installation by running the following command to check it's installed version. Please see below screeshot for reference.
$ php -v
If you could able to see the version means PHP is successfully installed on your Ubuntu machine.Step-4 Install PHP Modules
You can check for all available PHP modules for installation using the following command.
$ sudo apt-cache search php7*
Now you have to install required PHP modules for your application by running the following command.
$ sudo apt install php7.x-mbstring php7.x-cgi php7.x-gd php7.x-mysql php7.x-curl php7.x-xsl
In the above command replace php7.x with your required PHP verison. For ex:php7.x-mbstring will install "mbstring" extension. In this way we can install multiple modules using a single command.
Hope by now you should get successfully installed PHP and its modules on your Ubuntu machine. Happy coding.