How to Install PHP 7.3 on an Arch Linux Webserver
source link: https://www.vultr.com/docs/how-to-install-php-7-3-on-an-arch-linux-webserver
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Using a Different System?
Prerequisites
- A Vultr server running up to date Arch Linux (see this article.)
- A running webserver, either Apache or Nginx
Sudo access.
- Commands required to be ran as root are prefixed by
#
. The recommended way to run commands as root is to, as a regular user, prefix each of them withsudo
.
- Commands required to be ran as root are prefixed by
- Have a text editor installed, and be familiar with it, such as vi, vim, nano, emacs or a similar editor
Install PHP 7.3 On Your Webserver
Install PHP and FastCGI for PHP:
# pacman -S php-fpm
Visit PHP's timezone list
Set your timezone. For example, if you chose the category "America" and wanted to use "New_York", edit /etc/php/php.ini
and set the following:
date.timezone = America/New_York
Start FastCGI for PHP, and make it start after every boot:
# systemctl enable --now php-fpm
Configure PHP for your webserver.
For Apache
Create the file /etc/httpd/conf/extra/php-fpm.conf
, with the following contents. Make sure to copy this exactly as-is; a common error is putting spaces around the pipe character, but this is not a shell command, and there can be no spaces:
DirectoryIndex index.php index.html
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php-fpm/php-fpm.sock|fcgi://localhost/"
</FilesMatch>
Allow Apache to use FastCGI by editing /etc/httpd/conf/httpd.conf
, and add the following to the end of the LoadModule list:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
To allow using .php
files on all websites hosted by Apache, edit /etc/httpd/conf/httpd.conf
, and add this to the end. If you're running multiple host directories; for example, virtual hosts, or separate HTTP/HTTPS directories; and you want to only allow .php
files on some of them, edit their configuration files. Within the VirtualHost
block, add the following:
Include conf/extra/php-fpm.conf
Finally, restart Apache:
# systemctl restart httpd
For Nginx
Allow Nginx to use FastCGI for PHP by creating the file /etc/nginx/php.conf
with the following contents:
# Correctly handle request like /test.php/foo/blah.php or /test.php/
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
try_files $uri $document_root$fastcgi_script_name =404;
# Mitigate <nowiki>https://httpoxy.org/</nowiki> vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Allow Nginx to use FastCGI by editing /etc/nginx/nginx.conf
, and to every server block you want to use PHP with, add the following. Alternatively, if you are using virtual hosts, edit each host's configuration file:
location ~ \.php$ {
root /usr/share/nginx/html/;
include php.conf;
}
Restart Nginx:
# systemctl restart nginx
Test PHP
Within the appropriate directory, create test.php
with the following contents:
<?php phpinfo(); ?>
In a web browser, visit http://YOUR-SERVER-WEB-ADDRESS-OR-IP/test.php
, and you will see a webpage with your PHP version and configuration.
Remember to delete the test.php
test file you just created.
Want to contribute?
You could earn up to $600 by adding new articles
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK