How To Install Php On Linux
Setting up a server tin be a daunting task, particularly when installing languages similar PHP. If you lot want to become a WordPress exam server up and running, it's a necessary skill to learn.
Got no idea where to start to get PHP on your server? Depending on your unique setup, in that location are many ways to exercise it. Where do you download PHP, which version, what do you need to brand information technology piece of work, and how practise y'all install PHP on various OSes?
We'll reply them all in this one-stop PHP installation guide.
Allow's begin!
Bank check out our video guide to installing PHP
What is PHP?
PHP is an open up source scripting language primarily used for web development and server-side (backend) scripting. In simple terms:
- PHP tin be installed on a server to run scripts (e.thousand. pieces of code to add together forms to your site).
- Information technology is run server-side rather than client-side, so it works in the backend rather than in the browser.
- Information technology integrates well with HTML, making it highly suitable for spider web development.
Information technology's as well one of the easiest web scripting languages to larn, making it a popular choice for beginners. But information technology's also quite powerful and suitable for avant-garde website functions.
Many websites and tools use PHP and its many extensions (.Internet, Apache, and MySQL may sound familiar). WordPress is built primarily on PHP, and near of its plugins and themes also run on it.
Does Your Server Need PHP?
So you know what PHP is, but why should you install it on your server?
The nearly notable reason is that it's a requirement to become WordPress up and running, equally it'southward built almost exclusively on PHP. PHP also powers most WordPress functions, hooks, themes, and plugins.
You can see all the other WordPress system requirements hither:
Then, if you lot want to run a WordPress test server to play effectually with or set up a staging site, you'll need to install PHP.
Besides that, PHP is a great launching point for beginner devs. It's straightforward to utilize compared to other spider web scripting languages, but that doesn't come at any expense of functionality. Yous can do all sorts of things with it if you're skilled enough.
PHP is likewise quite pop. Then, you lot can find plenty of extensions and resources online.
Too that, if you want to larn to code WordPress themes and plugins, you'll need to learn PHP. Setting up a test server is a great way to experiment.
Do notation that many spider web hosting servers (such equally Kinsta) come preinstalled with PHP and WordPress. Kinsta even includes the ability to create a WordPress staging site, and then that'south easy to get at too.
The only reason you'll demand to do this manually is if you're setting upwards a server from scratch, either on your local computer or in an unmanaged hosting surround.
That said, let'southward get into the server setup instructions.
PHP Prerequisites
Before installing PHP, you'll need to make sure your server can handle it. Luckily, the requirements are adequately basic, and a lot of the software is likely already installed on your computer.
If y'all've never created a server before, you should check out this guide to set a local server on multiple OSes. The verbal specifics vary depending on your operating system, but you should know how to work with the command line and exist ready to install new software.
Any operating system y'all're installing PHP on, you'll need a web server to run information technology. Yous'll likewise likely need to install a database like MySQL, and so go on that in heed.
Here are the PHP prerequisites for each Bone, starting with Linux:
- An ANSI C compiler.
- Module-specific components like GD graphics libraries or PDF libraries.
- Optional: Autoconf ii.59+ (for PHP versions < 7.0), Autoconf 2.64+ (for PHP versions > vii.2), Automake 1.4+, Libtool ane.4+, re2c 0.13.4+, and Bison.
You lot should as well be familiar with navigating Unix-like OSes already.
At present the PHP requirements for Windows:
- Multiple Windows OSes are supported on PHP 5.5+, but 7.two.0+ users cannot utilise Windows 2008 or Windows Vista.
- Visual C Runtime (CRT).
- Visual Studio 2022, 2022, 2022, or Microsoft Visual C++ Redistributable for Visual Studio 2022, depending on your PHP version.
Lastly, there are no prerequisites for macOS considering PHP comes arranged with the organisation. Nosotros'll explain how to enable it below.
Where to Download PHP
If you need to download the PHP files manually, you should get them from the official site's PHP downloads page.
Avoid installing it from third-party sites unless you know they're safe, as downloading files from third-party sites can pb to accidentally installing malware.
If you're downloading for a Windows machine, look for the "Windows downloads" link in each version of PHP and make sure you're installing the proper files.
You tin also install older versions of PHP, just this is not recommended unless you know what you're doing, as they expose your server to bugs and major security flaws.
If y'all're running a Linux distribution, you usually don't need to become the files through the website, and yous should employ the command line. We'll become over that in detail below.
Which PHP Version Should I Utilize?
If you've clicked that download link above, you're likely looking at all those files and feeling overwhelmed. Which PHP version is the right 1?
Mostly speaking, if you lot're starting a brand new projection where compatibility issues aren't a problem, you should become the latest stable version of PHP.
It is sometimes possible to download beta versions of PHP, which are fifty-fifty newer, just these are often buggy and only released to assistance the developers gather feedback. Most of the time, you should stick with the stable releases.
What about older versions? Every PHP version comes with new features, merely that means new incompatibilities with older features. If yous need to do something specific that{s not supported on the latest PHP version, you can utilize an older version, but y'all should stick only with the currently supported versions.
If you lot're not certain, then apply the latest version of PHP.
Take note that WordPress is simply compatible with sure versions of PHP. Information technology technically supports PHP versions starting at 5.6.xx+, but these are quite erstwhile and thus non recommended. Versions 7.ii to vii.iv are currently the best-supported versions for WordPress.
PHP version 8 is also compatible, merely currently, this is very new, and non all plugins work properly. If you're worried well-nigh compatibility issues, stick with PHP version 7.4. Yous can read our PHP benchmarks postal service to see how diverse PHP CMSes and frameworks perform on different PHP versions.
How to Install PHP on Linux
Before starting, yous should exist familiar with the Concluding and how to operate Unix-like OSes in general. Generally, these control line codes should work on any Linux distribution that uses the normal syntax in the Terminal, only we've left some notes below for specific OSes.
First, yous should brand sure your packages are up to date, so run this command in the Terminal.
sudo apt-get update && sudo apt-become upgrade At present you lot're fix to install PHP. The command to do and then is effortless and straightforward.
sudo apt-go install php
This volition install the latest version of PHP along with several extensions. Yous can use this code to run across which version you accept.
Subscribe At present
php –v What if you want to install a specific version of PHP, such as PHP vii.4? Yous'll need to use a PPA, or Personal Bundle Annal, by Ondřej Surý. This is a safety way to install older supported versions of PHP. Run these iii commands one at a fourth dimension:
sudo apt install software-properties-mutual sudo add together-apt-repository ppa:ondrej/php sudo apt-get update Now your organisation recognizes the archive, and you can install PHP 7.4. Type in the following command:
sudo apt install php7.4 And of grade, you lot can supersede this number with whatever PHP version you want.
That covers the basics, but if y'all need extra help with configuration, the PHP installation documentation for Unix can assist.
Installing PHP on Ubuntu
For Ubuntu users, there aren't many specific concerns as long as you follow the guide above. Ubuntu is one of the most pop distributions, so well-nigh Linux guides are practically fabricated for that system.
One culling option available to you is downloading a LAMP stack. LAMP stands for Linux, Apache, MySQL, and PHP. It's essentially a package of all the software you demand to get a server up and running.
While y'all can manually download each of these tools separately, yous could get Taskel, a bundle that will install all these at once. Just run these two commands in succession in the Final:
sudo apt install tasksel sudo tasksel install lamp-server
Installing PHP on CentOS 7
This operating organisation is a lilliputian different from other Linux distributions. On CentOS, the apt and apt-get commands are not the ideal ways to install the software. Instead, information technology uses yum, Yellowdog Updater Modified, a better package managing director for RHEL-based operating systems.
Otherwise, the commands you lot'll need to utilize are pretty similar. To update your packages, run this control instead:
sudo yum install epel-release && sudo yum update As for other commands, you tin usually supersede apt-get with yum. To install PHP, use this command.
sudo yum install php PHP commands such as php –five should work the aforementioned on CentOS vii, and so you don't need to worry about that.
Installing PHP on Debian
Terminal for Unix-like operating systems is Debian. This time there are simply a few small-scale concerns, but most of the commands listed to a higher place should work fine.
For Debian, you tin use either apt-get or bent in your Terminal commands. The aptitude command is a lilliputian more comprehensive and provides a bill of fare interface. It's upwardly to personal preference which yous use, and either will get the task done.
So instead of using the usual apt-get control, you lot could run this one instead:
sudo aptitude install php Debian can exist finicky. If you discover PHP isn't parsing or extensions aren't working, make sure you've updated your server's web configuration file and that it'due south loading the extension ini files.
Besides a few small things, instructions for Debian are practically identical to those for other Linux distributions.
How to Install PHP on Windows
If y'all're using a Windows organisation, unlike macOS and Linux, you don't need to install PHP through the command line (though it is an choice if you'd adopt).
An easy way to install PHP from here is to enable IIS and so utilize WebPI to install PHP. After launching WebPI, you tin find it nether the Products tab. Click Add together on the version you want, and then click Install.
You tin can likewise download PHP for Windows and manually configure it to work with IIS. Brand certain to get a not-thread-condom version if y'all're using IIS.
If all this is too complicated, you could instead install WampServer or XAMPP, every bit these come with everything you need to start working with a web server: Apache, a database, and of course PHP.
These instructions volition piece of work with nigh modern Windows OSes such equally Windows 10, 7, and Vista. If you're using an older version of Windows, you should check out the legacy Windows installation documentation.
Windows may need a petty extra configuration to get PHP working properly, so brand sure to check the recommended Windows configuration documentation. Yous just have to make a few small ini tweaks.
How to Install PHP on macOS
PHP comes preinstalled on nearly macOS systems, so you usually don't need any manual installation.
All yous need to do is uncomment a few lines of code in the Apache configuration file httpd.conf, which you lot tin can unremarkably discover at /private/etc/apache2/httpd.conf. Uncomment these 2 lines by removing the hashtag symbol:
# LoadModule php5_module libexec/httpd/libphp5.so # AddModule mod_php5.c You may demand to do extra configuration if you don't like some file settings' default values. Otherwise, find the DocumentRoot, and so create and load a PHP file with this code:
<?php phpinfo(); ?> You lot tin always cheque the PHP version with the php –v command to make certain PHP was installed correctly.
If you lot do need to download PHP manually, then y'all should install Homebrew and use this unproblematic control:
brew install php All Almost PHP Extensions
One time you've got PHP up and running, it'south a expert idea to think about extensions. These compiled libraries add all sorts of actress, helpful functionality. Think of them as plugins that add on to what PHP already offers. Some of these are required to run PHP frameworks, such equally Laravel and Symfony.
While it'due south completely possible to code everything yourself without ever touching an extension, there'south no reason to practise it all on your own when widely-used shortcuts exist to make your life easier.
PHP already comes with dozens of built-in extensions, some of which you must enable manually, and others you can start using right abroad. You tin also install PHP extensions through sites like PECL, which hosts hundreds of 3rd-party packages.
The PHP manual offers extension documentation for many of these besides, and so y'all can get the hang of using them.
Not sure where to first? Here are merely a handful of a few popular PHP extensions:
- Apache: Apache is a widely used web server software recommended by WordPress due to its great compatibility with it and PHP. Apache comes bundled with PHP, so you don't need to install it manually.
- .Net: .NET is a popular software framework that you tin use to build web applications and more than. It works with multiple languages, including PHP. You may likewise be interested in PeachPie, which allows you lot to run PHP code in .NET.
- MySQLi: A amend version of the old MySQL extension, MySQLi enables you to work with MySQL database software. This one is a must-have to help you ready your database.
Whenever you install an extension, you demand to uncomment it. Just open php.ini and remove the semicolon (;) in front of extension=extensionname.
Y'all should as well check out these PHP frameworks if yous'd like to standardize your code and build with premade libraries. They're a bang-up fashion to go started with developing web applications with PHP.
Summary
Whatever operating system yous're using, installing PHP isn't such a hard process. If yous want to make a WordPress examination server, you'll need it. Aspiring PHP programmers will find setting up a web server and installing PHP on it a great exercise.
Make sure you download PHP either through the command line or from its official site. Y'all tin can either go the latest stable version of PHP or whatever other version compatible with WordPress.
And if y'all'd similar to get started with developing WordPress sites right away, you can try DevKinsta! It comes with PHP preinstalled. It besides lets y'all hot-swap between different PHP versions so that you can test your site in unlike server environments.
Save fourth dimension, costs and maximize site performance with:
- Instant help from WordPress hosting experts, 24/7.
- Cloudflare Enterprise integration.
- Global audience achieve with 29 data centers worldwide.
- Optimization with our born Awarding Performance Monitoring.
All of that and much more than, in ane programme with no long-term contracts, assisted migrations, and a xxx-day-coin-back-guarantee. Check out our plans or talk to sales to notice the plan that's right for yous.
Source: https://kinsta.com/blog/install-php/
Posted by: scotttrall1987.blogspot.com

0 Response to "How To Install Php On Linux"
Post a Comment