Setting up a vps can be a daunting task, especially when installing languages like PHP. If you want khổng lồ get a WordPress chạy thử server up và running, it’s a necessary skill to learn.

Bạn đang xem: Install and configure php

Got no idea where khổng lồ start to lớn get PHP on your server? Depending on your unique setup, there are many ways to do it. Where vì you download PHP, which version, what vì you need to lớn make it work, và how bởi you install PHP on various OSes?

Check out our clip guide to lớn installing PHP

What is PHP?

PHP logo

PHP is an open source scripting language primarily used for web development và server-side (backend) scripting. In simple terms:

See how stacks up against the competition. Select your provider WP Engine SiteGround GoDaddy Bluehost Flywheel HostGator Cloudways AWS Digital Ocean DreamHost Other Compare
PHP can be installed on a hệ thống to run scripts (e.g. Pieces of code to add forms to lớn your site).It is run server-side rather than client-side, so it works in the backend rather than in the browser.

It’s also one of the easiest web scripting languages to learn, making it a popular choice for beginners. But it’s also quite powerful and suitable for advanced website functions.

Many websites & tools use PHP & its many extensions (.NET, Apache, và MySQL may sound familiar). WordPress is built primarily on PHP, và most 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 most notable reason is that it’s a requirement to lớn get WordPress up & running, as it’s built almost exclusively on PHP. PHP also powers most WordPress functions, hooks, themes, & plugins.

You can see all the other WordPress system requirements here:

WordPress requirements

So, if you want lớn run a WordPress demo server khổng lồ play around with or phối up a staging site, you’ll need khổng lồ install PHP.

Besides that, PHP is a great launching point for beginner devs. It’s straightforward to use compared khổng lồ other website scripting languages, but that doesn’t come at any expense of functionality. You can vày all sorts of things with it if you’re skilled enough.

PHP is also quite popular. So, you can find plenty of extensions & resources online.

Besides that, if you want to learn to lớn code WordPress themes and plugins, you’ll need to lớn learn PHP. Setting up a test server is a great way to experiment.

Do note that many website hosting servers (such as come preinstalled with PHP and WordPress. even includes the ability khổng lồ create a WordPress staging site, so that’s easy khổng lồ get at too.

The only reason you’ll need to vị this manually is if you’re setting up a hệ thống from scratch, either on your local computer or in an unmanaged hosting environment.

That said, let’s get into the server cài đặt instructions.

PHP Prerequisites

Before installing PHP, you’ll need to make sure your vps can handle it. Luckily, the requirements are fairly basic, & a lot of the software is likely already installed on your computer.

If you’ve never created a hệ thống before, you should kiểm tra out this guide lớn set up a local hệ thống on multiple OSes. The exact specifics vary depending on your operating system, but you should know how to lớn work with the command line and be ready lớn install new software.

Whatever operating system you’re installing PHP on, you’ll need a web vps to run it. You’ll also likely need to install a database lượt thích MySQL, so keep that in mind.

Here are the PHP prerequisites for each OS, starting with Linux:

An ANSI C compiler.Module-specific components lượt thích GD graphics libraries or PDF libraries.Optional: Autoconf 2.59+ (for PHP versions 7.2), Automake 1.4+, Libtool 1.4+, re2c 0.13.4+, & Bison.

You should also be familiar with navigating Unix-like OSes already.

Xem thêm: How To Convert Json To Php Using Json_Decode, How To Parse Json In Php

Now the PHP requirements for Windows:

Multiple Windows OSes are supported on PHP 5.5+, but 7.2.0+ users cannot use Windows 2008 or Windows Vista.Visual C Runtime (CRT).Visual Studio 2012, 2015, 2017, or Microsoft Visual C++ Redistributable for Visual Studio 2019, depending on your PHP version.

Lastly, there are no prerequisites for macOS because PHP comes bundled with the system. We’ll explain how to enable it below.

Where to download PHP

If you need to tải về 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 lead lớn accidentally installing malware.

PHP downloads page

If you’re downloading for a Windows machine, look for the “Windows downloads” liên kết in each version of PHP & make sure you’re installing the proper files.

You can also install older versions of PHP, but this is not recommended unless you know what you’re doing, as they expose your server to bugs & major security flaws.

If you’re running a Linux distribution, you usually don’t need to get the files through the website, and you should use the command line. We’ll go over that in detail below.

Which PHP Version Should I Use?

If you’ve clicked that tải về link above, you’re likely looking at all those files and feeling overwhelmed. Which PHP version is the right one?

Generally speaking, if you’re starting a brand new project where compatibility issues aren’t a problem, you should get the latest stable version of PHP.

It is sometimes possible to tải về beta versions of PHP, which are even newer, but these are often buggy & only released lớn help 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, but that means new incompatibilities with older features. If you need to vị something specific that{s not supported on the latest PHP version, you can use an older version, but you should stick only with the currently supported versions.

If you’re not sure, then use the latest version of PHP.

Take note that WordPress is only compatible with certain versions of PHP. It technically supports PHP versions starting at 5.6.20+, but these are quite old và thus not recommended. Versions 7.2 to 7.4 are currently the best-supported versions for WordPress.

PHP version 8 is also compatible, but currently, this is very new, & not all plugins work properly. If you’re worried about compatibility issues, stick with PHP version 7.4. You can read our PHP benchmarks post to lớn see how various PHP CMSes and frameworks perform on different PHP versions.

How khổng lồ Install PHP on Linux

Before starting, you should be familiar with the Terminal và how khổng lồ operate Unix-like OSes in general. Generally, these command line codes should work on any Linux distribution that uses the normal syntax in the Terminal, but we’ve left some notes below for specific OSes.

First, you should make sure your packages are up to lớn date, so run this Linux command in the Terminal.

sudo apt-get update && sudo apt-get upgradeNow you’re ready lớn install PHP. The command to bởi vì so is effortless & straightforward.

sudo apt-get install php

Installing PHP via terminalThis will install the latest version of PHP along with several extensions. You can use this code khổng lồ see which version you have.