Tag Archives: PHP

How to Easily Check & Update the PHP Version of Your WordPress Site

NICK SCHÄFERHOFF-JANUARY 9, 2018

All websites are running on code. In the old days, it was pure HTML, today it’s usually a mix of that plus CSS and JavaScript.

However, that’s only once they are loaded. On the server, a different programming language is likely running the scene, especially if you have a WordPress website. We are, of course, talking about PHP.

Most of the things you see on both the front and back end of your WordPress site exist thanks to PHP. You don’t only find it in your page templates, it also makes up the files that build the WordPress dashboard.

php-code-in-wordpress-dashboard-file

The same is true for any themes and plugins you may have installed. In short, without PHP your WordPress website would not exist.

Because this programming language is so central to the WordPress platform, today we want to talk about something that many of us deal with too rarely: how to update the PHP version of your site.

What, you didn’t know that was even part of running a website? That’s exactly why this post exists. In it you will learn a little more about PHP as a language and why it’s important to run the latest version, how to check your site’s PHP and how to upgrade it safely.

Ready to get a little nerdy? Then let’s dive right into it.

A Short Overview of PHP as a Programming Language

Just so you know what we are talking about, let’s first dive into what PHP is exactly.

First of all, it’s a programming language that is open source and thus (like WordPress) free to use. That might also contribute to the fact that PHP is one of the most popular languages for web development. It not only runs the scenes behind WordPress but is also a part of Facebook and other popular sites. However, you can use it for other purposes as well.

who-uses-php

Source: James Titcumb

A second important thing about PHP is that it’s a server-side programming language. That means, it is processed on the machine whose hard drive it lies on. That is opposed to client-side languages like JavaScript, where all the work happens in the browser of the person requesting to see your site.

However, that also means that any problems with site performance that stem from PHP are yours to fix. Your visitors can have the fastest computer in the world, however, if your server is low on resources, that’s not gonna make much of a difference. Which brings us to the next part.

Why Update the PHP Version of Your Site?

Because PHP is so important to WordPress, it’s also a central part of site performance. After all, PHP is basically the middle man pulls the correct data from your database, wraps it in HTML and CSS and then delivers it as a finished site to the visitor’s browser. If the middleman is slow, so is everything else.

Updates Mean Improvements

For that reason, the programming language is constantly being improved upon. It has seen quite a bunch of versions throughout the years.

To run WordPress, your server needs at least PHP 5.2.4. However, by now the official recommendation is that you run PHP 7 or higher (the current version is PHP 7.1).

That’s because, just like WordPress, new versions of PHP bring a lot of improvements with them. As it progresses, the languages gets more secure, faster, leaner, less resource hungry and just overall better. In fact, just the jump from PHP 5.6 to PHP 7 was a great leap forward.

PHP 7 is the Best One Yet

One of the main improvements PHP 7 offers to WordPress users is increased speed. Benchmarks show the new version to be up to twice as fast as its predecessor.

php-7-benchmarks-update-php-version

As a consequence, your server is able to deliver your website to more visitors while doing less work (by the way, there are more things you can do to speed up WordPress). In addition to that, the new version makes code easier to read (and thus support).

Furthermore, PHP 7 has gotten a lot better at handling errors. It is now able to resolve script problems without necessarily having to terminate the entire process. That’s good news to those site visitors who don’t like to deal with faulty websites (hint: that’s all of them).

Finally, PHP 7 has seen improvements in terms of security that make applications built with it harder to hack (if that ever does happen, learn how to recover from a hacked WordPress site).

Older Versions are No Longer Supported

In addition to the above, the lifetime of older PHP versions is running out. Active support for version 5.6 ended at the beginning of 2017. Security support will only be provided until the end of 2018.

Convinced yet? And those are just the cliff notes. There’s more awesome stuff that has improved in PHP 7 that you can learn about here. However, how do you figure out which PHP version your site is currently running on? I’m glad you asked.

How to Check Your WordPress Site’s PHP Version

If you want to know which version of PHP currently powers your WordPress site, you have several ways to find out. Let’s go over them real quick.

1. Check Your Hosting Management Panel

Your first option is to check with your provider. In the back end of your hosting account, there’s likely a menu called PHP Settings, PHP Version Manager or something similar. From here, you can check which PHP version your site(s) are using.

Most often you are also able to upgrade to another version here (more on that below) and do things like edit PHP.ini. The latter is an important file that allows you to make changes to server functionality.

2. Use a WordPress Plugin

Of course, in the WordPress ecosphere, you also have plugins that can do the same for you. One of the easiest to use is Display PHP Version.

Pretty much all you have to do is install the plugin and activate it. You will then be able to see the current PHP version under At a Glance in the WordPress dashboard.

display-php-version-wordpress-plugin

If it turns out that your server is already running the latest version, there’s nothing to do but smile happily and move on with your day (or maybe send your provider’s sysadmins a box of chocolates).

However, if you have never dealt with this issue before, chances are good that the PHP version is not up to date. In that case, we will show you how to upgrade it safely in the following.

Of course, that requires that your provider offers the option to switch. If not, maybe it’s time to find new hosting?

How to Upgrade PHP Safely

As cool as PHP 7 is, there are some risks involved with upgrading. That mostly means the possibility that you have code on your site (meaning in WordPress core, themes, plugins, and scripts) that is not compatible with the new version.

If that is the case, when you make the switch, all or parts of your site might break or at least show faulty behavior. That’s why it’s important to check this kind of thing beforehand and we will show you how below.

Quick note: the process laid out here is how to upgrade your live site. However, an even better idea is to create a local copy of your site and run through it once on your computer. That way, you reduce the chance of running into any nasty surprises even further.

1. Back Up and Update Everything

As mentioned, problems with upgrading PHP usually stem from older code that is no longer compatible with the newest version. The best solution: upgrade your site.

The WordPress community is a strong advocate for using the latest version of PHP. For that reason, core, plugin, and theme developers make sure their work jive with it.

Consequently, the first step to make sure site doesn’t produce problems is to keep your site up to date. That’s something you should do either way for security reasons.

So, back up your site and then click the upgrade button wherever necessary. Do it now, I’ll wait.

2. Use a Plugin to Check for Compatibility Issues

Done? Cool, then let’s continue.

Even with up-to-date WordPress and extensions, there is no guarantee that everything will go over smoothly. Thankfully, you don’t have to just have to hope for the best. Instead, you can test for incompatibility issues beforehand. How? With a plugin of course.

WP Engine has released a free plugin in the WordPress directory, for just this purpose. It checks all the code on your site and reports any possible issues.

To use it, you first have to install it on your site in the usual way. When it’s active, there will be a new menu item under Tools called PHP Compatibility. Here, just choose the PHP version you want to upgrade to. Then select whether to scan only your active plugins and themes or all extensions on your site.

update-php-version-safely-with-php-compatibility-checker

Start the scan. When done, the plugin will present you with a list of errors and warnings for your site. It will even tell you the file name and line number where it encountered them.

From here, you can take action to replace faulty plugins or themes or find a different kind of solution (such as asking the developer to update their work). The plugin will also make suggestions.

By the way, if you have a plugin that is up to date but still flagged as incompatible, it might also be a false positive. WP Engine provides list of plugins known to be flagged for compatibility issues when there aren’t any. So, take that into account.

4. Upgrade PHP

Once made sure that your site is, by all accounts, able to handle the switch, it’s time to actually make it.

There are several ways of doing that. One is via SSH commands. However, if you know how to do this, you are probably not reading this article. Consequently, we won’t be going over it. However, if you still want to learn about upgrading your server’s PHP version via SSH, you can do so here.

We will go the easier way, which is to make the switch via the admin dashboard of your hosting provider. For example, in cPanel (which, by the way, is also based on PHP) it’s as easy as finding the menu item PHP Version Manager, navigating to your site’s location, picking the version you want to change to and hitting Save.

upgrade-php-version-in-cpanel

Source: SiteGround

If your host is running Plesk, you can find out how to upgrade PHP here. Unfortunately, for other admin panels, you will have to do your own search. Should you be unable to find any such option, your host might have disabled it. In that case, you need to get in touch with your provider.

5. Check Your Site

Once you have upgraded, the last thing to do is go back to your site’s front end and have a look around. Check every page to see if everything looks as it should and that parts of your site aren’t disabled or similar. Also, test the plugins you are using as well as theme features. However, if you have taken the precautions mentioned above, it’s very unlikely that there was a problem.

And that’s it. Congratulations! You just successfully upgraded PHP for your WordPress site.

Summing Up

PHP is the glue that holds WordPress together. For that reason, it’s important to keep it up to date. This will also allow you to profit from increased speed and security.

Above, you have learned about PHP and why it is important to upgrade. We have talked about how you can find out which version your site is running and how to prepare it for updating. Plus, we have told you how to implement said upgrade via your hosting management panel.

If you have followed along good job! Your site is now ready for the future.

Have you updated PHP for your WordPress site? Which version were you running before? Did you have any issues? Let us know in the comments section below!

Nick Schäferhoff

5f069a6cacb95c3811aa06a1884d3a5dNick Schäferhoff is an entrepreneur, online marketer, and professional blogger from Germany. He found WordPress when he needed a website for his first business and instantly fell in love. When not building websites, creating content or helping his clients improve their online business, he can most often be found at the gym, the dojo or traveling the world with his wife. If you want to get in touch with him, you can do so via Twitter or through his website.

PHP

Dari Wikipedia bahasa Indonesia, ensiklopedia bebas

PHP: Hypertext Preprocessor adalah bahasa skrip yang dapat ditanamkan atau disisipkan ke dalam HTML. PHP banyak dipakai untuk memprogram situs web dinamis. PHP dapat digunakan untuk membangun sebuah CMS.

Opera Snapshot_2018-01-16_132453_id.wikipedia.org

Sejarah PHP


Pada awalnya PHP merupakan kependekan dari Personal Home Page (Situs personal). PHP pertama kali dibuat oleh Rasmus Lerdorf pada tahun 1995. Pada waktu itu PHP masih bernama Form Interpreted (FI), yang wujudnya berupa sekumpulan skrip yang digunakan untuk mengolah data formulir dari web.

Selanjutnya Rasmus merilis kode sumber tersebut untuk umum dan menamakannya PHP/FI. Dengan perilisan kode sumber ini menjadi sumber terbuka, maka banyak pemrogram yang tertarik untuk ikut mengembangkan PHP.

Pada November 1997, dirilis PHP/FI 2.0. Pada rilis ini, interpreter PHP sudah diimplementasikan dalam program C. Dalam rilis ini disertakan juga modul-modul ekstensi yang meningkatkan kemampuan PHP/FI secara signifikan.

Pada tahun 1997, sebuah perusahaan bernama Zend menulis ulang interpreter PHP menjadi lebih bersih, lebih baik, dan lebih cepat. Kemudian pada Juni 1998, perusahaan tersebut merilis interpreter baru untuk PHP dan meresmikan rilis tersebut sebagai PHP 3.0 dan singkatan PHP diubah menjadi akronim berulang PHP: Hypertext Preprocessing.

Pada pertengahan tahun 1999, Zend merilis interpreter PHP baru dan rilis tersebut dikenal dengan PHP 4.0. PHP 4.0 adalah versi PHP yang paling banyak dipakai pada awal abad ke-21. Versi ini banyak dipakai disebabkan kemampuannya untuk membangun aplikasi web kompleks tetapi tetap memiliki kecepatan dan stabilitas yang tinggi.

Pada Juni 2004, Zend merilis PHP 5.0. Dalam versi ini, inti dari interpreter PHP mengalami perubahan besar. Versi ini juga memasukkan model pemrograman berorientasi objekke dalam PHP untuk menjawab perkembangan bahasa pemrograman ke arah paradigma berorientasi objek. Server web bawaan ditambahkan pada versi 5.4 untuk mempermudah pengembang menjalankan kode PHP tanpa menginstall software server.

Versi terbaru dan stabil dari bahasa pemograman PHP saat ini adalah versi 7.0.16 dan 7.1.2 yang resmi dirilis pada tanggal 17 Februari 2017.

Sintaksis Dasar 


Pembatas

PHP hanya mengeksekusi kode yang ditulis dalam pembatas sebagaimana ditentukan oleh dasar sintaks PHP. Apapun di luar pembatas tidak diproses oleh PHP (meskipun teks PHP ini masih mengendalikan struktur yang dijelaskan dalam kode PHP. Pembatas yang paling umum adalah “<?php” untuk membuka dan “?>” Untuk menutup kode PHP.Tujuan dari pembatas ini adalah untuk memisahkan kode PHP dari kode di luar PHP, seperti HTML,Javascript.

Variabel

Variabel diawali dengan simbol dolar $. Pada versi php PHP 5 diperkenalkan jenis isyarat yang memungkinkan fungsi untuk memaksa mereka menjadi parameter objek dari class tertentu, array, atau fungsi. Namun, jenis petunjuk tidak dapat digunakan dengan jenis skalar seperti angka atau string. Contoh variabel dapat ditulis sebagai $nama_variabel.

Penulisan fungsi, penamaan kelas, nama variabel adalah peka akan huruf besar (Kapital) dan huruf kecil . Kedua kutip ganda “” dari string memberikan kemampuan untuk interpolasi nilai variabel ke dalam string PHP. PHP menerjemahkan baris sebagai spasi, dan pernyataan harus diakhiri dengan titik koma ;.

Komentar

PHP memiliki 3 jenis sintaks sebagai komentar pada kode yaitu tanda blok / * * / , komentar 2 baris // Serta tanda pagar # digunakan untuk komentar satu baris. Komentar bertujuan untuk meninggalkan catatan pada kode PHP dan tidak akan diterjemahkan ke program.

Fungsi

Ratusan fungsi yang disediakan oleh PHP serta ribuan lainnya yang tersedia melalui berbagai ekstensi tambahan. fungsi-fungsi ini didokumentasikan dalam dokumentasi PHP. Namun, dalam berbagai tingkat pengembangan, kini memiliki berbagai konvensi penamaan. Sintaks fungsi adalah seperti di bawah ini:

function tampilkan($data=“”) // Mendefenisikan fungsi, “tampilkan” adalah nama sebuah fungsi
//Diapit oleh tanda kurung kurawal
if($data) return $data; else returnTidak ada data‘; // Melakukan proses pengolahan data, contohnya melalui kondisi

echo tampilkan(“isi halaman“) // Menjalankan fungsi

Contoh Program


Membuat Sebuah Halaman Web PHP

Sebuah Halaman web yang ditulis menggunakan Bahasa Pemograman PHP adalah sebagai berikut:

<?php
echoHalo dunia“;
?>

Program bilangan Fibonacci

Berikut ini adalah contoh program yang relatif lebih kompleks yang ditulis dengan menggunakan PHP. Contoh program ini adalah program untuk menampilkan 20 bilangan pertama dari deret bilangan Fibonacci.terdapat beberapa variable atau sintax. seperti function. itu merupakan bagian dari javascript.

<?php
function fibonacci_seq( $panjang ) {
for( $l = array(0,1), $i = 2, $x = 0; $i < $panjang; $i++ ) {
$l[] = $l[$x++] + $l[$x];
}
return $l;
}

fibonacci_seq(20);
// Angka “20” dapat diganti sesuai keinginan
?>

Kelebihan PHP Dari Bahasa Pemrograman Lain


Beberapa kelebihan PHP dari bahasa pemrograman web, antara lain:

  1. Bahasa pemrograman PHP adalah sebuah bahasa script yang tidak melakukan sebuah kompilasi dalam penggunaannya.
  2. Web Server yang mendukung PHP dapat ditemukan di mana – mana dari mulai apache, IIS, Lighttpd, hingga Xitami dengan konfigurasi yang relatif mudah.
  3. Dalam sisi pengembangan lebih mudah, karena banyaknya milis – milis dan developer yang siap membantu dalam pengembangan.
  4. Dalam sisi pemahamanan, PHP adalah bahasa scripting yang paling mudah karena memiliki referensi yang banyak.
  5. PHP adalah bahasa open source yang dapat digunakan di berbagai mesin (Linux, Unix, Macintosh, Windows) dan dapat dijalankan secara runtime melalui console serta juga dapat menjalankan perintah-perintah system.

Tipe data


PHP memiliki 8 tipe data, yaitu:

  1. Boolean
  2. Integer
  3. Float/ Double
  4. String
  5. Array
  6. Object
  7. Resource
  8. NULL