About Blog Contact
 
 

RSS

Thu, Sep 26, 2019
3 min read

How to install PHP 7.3 and Nginx on Ubuntu 19.04

Add repositories to get the latest versions

First we will add two new repositories to our apt sources list.

1sudo add-apt-repository ppa:ondrej/nginx
2sudo add-apt-repository ppa:ondrej/php

Install required packages

In this step we will install all the required packages. When using Nginx it is common, to use PHP's FastCGI process manager (php-fpm). Maybe you don't need all the php extensions, but this set is pretty common.

1sudo apt install nginx php7.3-fpm php7.3-common php7.3-curl php7.3-intl php7.3-gd php7.3-dev php7.3-json php7.3-mbstring php7.3-mysql php7.3-opcache php7.3-soap php7.3-sqlite3 php7.3-xml php7.3-zip

Configure Nginx to serve a specific domain

First lets have a look at the configuration conventions of Nginx. You can find the default configuration in /etc/nginx/sites-available/default . Additionally it is symlinked to /etc/nginx/sites-enabled/default . Through this symlink the configuration file will be recognized by Nginx at startup and reload. This means configuration changes are not recognized while runtime.
Lets add a new configuration file for our domain. The domain name in the file means nothing to Nginx but it is a convention to name it like the domain it configures.

1sudo touch /etc/nginx/sites-available/christlieb.eu.conf

Use you favorite text editor to paste in the following content. Any section is described by the comment above it.

1# The server directive says Nginx that this is a new server configuration
2server {
3 # This has to be the domain you want to use
4 server_name christlieb.eu;
5 # This is the document root
6 root /var/www/christlieb.eu/current/public;
7 # This is the file which gets loaded by default. index.html gets loaded if there is no index.php
8 index index.php index.html;
9
10 # This configuration prevent the logger to log not found favicon
11 location = /favicon.ico {
12 log_not_found off;
13 access_log off;
14 }
15
16 # Same as favicon but for robots.txt
17 location = /robots.txt {
18 allow all;
19 log_not_found off;
20 access_log off;
21 }
22
23 # This says the Nginx server to rewrite any requests which do not access a valid file to rewrite on to the index.php
24 location / {
25 try_files $uri $uri/ /index.php?$args;
26 }
27
28 # This gets all requests from the location above and sends them to the php-fpm socket which will execute the php
29 location ~ \.php$ {
30 include fastcgi.conf;
31 fastcgi_intercept_errors on;
32 fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
33 }
34
35 # This says that all files with the given endings should be cached by the client
36 location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
37 expires max;
38 log_not_found off;
39 }
40
41}
1ln -s /etc/nginx/sites-available/christlieb.eu.conf /etc/nginx/sites-enabled/christlieb.eu.conf

As said above we need to symlink the file into the sites-available directory.
To test the configuration execute sudo nginx -t . The output should be something like the following.

1nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2nginx: configuration file /etc/nginx/nginx.conf test is successful

Now we can calmly reload the Nginx configuration with suco service nginx reload.

Test the setup

To test the setup we will create a index.php file with a phpinfo() call.

1mkdir -p /var/www/christlieb.eu/current/public
2echo "<?php phpinfo();" > /var/www/christlieb.eu/current/public/index.php

Now open the browser and point to you your domain, You will see a php info page.

Legal Notice  |   Privacy  |   RSS  |   © 2026 christlieb.eu