# How to Install PHP on Arch Linux

> URL: https://www.atlantic.net/dedicated-server-hosting/how-to-install-php-on-arch-linux/ | Published: 2022-12-04 | Updated: 2024-04-19 | Author: Hitesh Jethva

PHP is an acronym for “PHP: Hypertext Preprocessor”. It is a widely-used, open-source scripting language used to develop Static websites or Dynamic websites or Web applications. With PHP, you can manage dynamic content, databases, session tracking, and more. It is an interpreted language means you don’t need compilation.

In this post, we will show you how to install PHP on Arch Linux.

## Step 1 – Configure Repository

By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirrorlist configuration file:

```
nano  /etc/pacman.d/mirrorlist
```

Remove all lines and add the following lines:

```
## Score: 0.7, United States
Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.8, United States
Server = http://lug.mtu.edu/archlinux/$repo/os/$arch
Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.9, United Kingdom
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
## Score: 1.5, United Kingdom
Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch
Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch
## Score: 6.6, United States
Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch
## Score: 6.7, United States
Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch
## Score: 6.8, United States
Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch
## Score: 7.1, India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
## Score: 10.1, United States
Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch
```

Save and close the file, then update all the package indexes with the following command:

```
pacman -Syu
```

## Step 2 – Add PHP Repository

By default, Arch Linux provides PHP version 8.0 in the default repository, so if you want to install multiple PHP versions then you will need to add the PHP repository to your server.

To add the PHP repository, edit the Pacman configuration file:

```
nano /etc/pacman.conf
```

Add the following lines:

```
[home_el_archphp_Arch]
Server = https://download.opensuse.org/repositories/home:/el:/archphp/Arch/$arch
```

Save and close the file, then run the following command to store the PHP key and fingerprint variables:

```
key=$(curl -fsSL https://download.opensuse.org/repositories/home:el:archphp/Arch/$(uname -m)/home_el_archphp_Arch.key)
fingerprint=$(gpg --quiet --with-colons --import-options show-only --import --fingerprint <<< "${key}" | awk -F: '$1 == "fpr" { print $10 }')
```

Next, initialize the key with the following command:

```
pacman-key --init
```

Next, add the key and fingerprint with the following command:

```
pacman-key --add - <<< "${key}"
pacman-key --lsign-key "${fingerprint}"
```

Finally, update the repository with the following command:

```
pacman -Syy
```

You will get the following output:

```
:: Synchronizing package databases...
 core                                                     156.8 KiB  2.89 MiB/s 00:00 [#################################################] 100%
 extra                                                   1719.6 KiB  56.0 MiB/s 00:00 [#################################################] 100%
 community                                                  7.0 MiB  62.1 MiB/s 00:00 [#################################################] 100%
 home_el_archphp_Arch                                     367.3 KiB   311 KiB/s 00:01 [#################################################] 100%
```

## Step 3 – Install PHP 7.3

To install PHP version 7.3, run the following command:

```
pacman -Ss php73
```

After the installation, verify the PHP version using the following command:

```
php73 --version
```

You will get the following output:

```
PHP 7.3.33 (cli) (built: Oct  7 2022 16:41:34) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.33, Copyright (c) 1999-2018, by Zend Technologies
```

## Step 4 – Install PHP 7.4

If you want to install PHP version 7.4, run the following command:

```
pacman -S php7
```

After the installation, verify the PHP version using the following command:

```
php7 --version
```

You will get the following output:

```
PHP 7.4.30 (cli) (built: Jul  9 2022 06:35:35) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
```

## Step 5 – Install PHP 8.0

You can also install PHP version 8.0 by running the following command:

```
pacman -S php
```

After the successful installation, verify the PHP installation using the following command:

```
php --version
```

You should see the following output:

```
PHP 8.1.11 (cli) (built: Sep 29 2022 16:31:09) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies
```

## Conclusion

In this post, we explained how to install different PHP versions on Arch Linux. You can now easily install your preferred PHP version as per your requirement. You can choose one of our [dedicated server hosting](https://www.atlantic.net/dedicated-server-hosting/) from Atlantic.Net! to test the PHP installation.
