Setting Up Phusion Passenger on Ubuntu 22.04 (Jammy Jellyfish) with Apache webserver
Tags: phusion, passenger, flask, python
Published: 2023-07-29 00:39:20

This is a guide to setup Phusion Passenger, an open source web application server. It handles HTTP requests, manages processes and resources, and enables administration, monitoring and problem diagnosis.  It also makes setting up Flask so easy.  Flask is a popular and lightweight web framework for Python which I will discuss how to setup in another post.

This post is part of a series for the following technology stack combo : Ubuntu + Apache + Python + Flask + ReactJS


### Preparing Ubuntu 22.04

First, update the package managent cache by using apt-get to install packages.  It is also recommended to upgrade so we do that like so.
```
sudo apt-get update
sudo apt-get upgrade
```
We also need to install apache web server.
```
apt-get install -y apache2
```


### Install Phusion Passenger packages

The installation procedure below is specific to Ubuntu Jammy and Apache web server.

```
# Install our PGP key and add HTTPS support for APT
sudo apt-get install -y dirmngr gnupg apt-transport-https ca-certificates curl
curl https://oss-binaries.phusionpassenger.com/auto-software-signing-gpg-key.txt | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/phusion.gpg >/dev/null

# Add our APT repository
sudo sh -c 'echo deb https://oss-binaries.phusionpassenger.com/apt/passenger jammy main > /etc/apt/sources.list.d/passenger.list'
sudo apt-get update

# Install Passenger + Apache module
sudo apt-get install -y libapache2-mod-passenger
```

### Enable Passenger Apache module
For Apache to work with Passenger, you need to enable the Passenger Apache module and restart Apache to apply the newly enabled module.

```
sudo a2enmod passenger 
sudo apache2ctl restart
# Or you can also restart Apache using the following
sudo service apache2 restart
```
### Validate and check installation
It is recommended to validate your passenger installation to check if installation was successful.

```
sudo /usr/bin/passenger-config validate-install
```
After running the above command, you should see the following:
```
What would you like to validate?
Use <space> to select.
If the menu doesn't display correctly, press '!'

 ‣ ⬢  Passenger itself
 ‣ ⬢  Apache

-------------------------------------------------------------------------

 * Checking whether this Passenger install is in PATH... ✓
 * Checking whether there are no other Passenger installations... ✓  
 * Checking whether Apache is installed... ✓
 * Checking whether the Passenger module is correctly configured in Apache... ✓ 
```
If an error occurs, try to install the following and re-run “validate-install”:

```
sudo apt-get install apache2-dev
sudo /usr/bin/passenger-config validate-install
```
Otherwise if any of the checks do not pass, please follow the 
suggestion which will be prompted by validate-install script.

### Check if Apache has started the Passenger core processes.
Run the following command and check if both Apache processes as well as Passenger processes are running.
```
sudo /usr/sbin/passenger-memory-stats
```
The above should have the output similar to the following:
```
Version: 6.0.18
Date   : 2023-07-28 22:37:04 +0000

---------- Apache processes -----------
PID    PPID   VMSize     Private  Name
---------------------------------------
12217  1      75.6 MB    0.7 MB   /usr/sbin/apache2 -k start
12236  12217  1188.5 MB  1.0 MB   /usr/sbin/apache2 -k start
12237  12217  1188.4 MB  0.9 MB   /usr/sbin/apache2 -k start
### Processes: 3
### Total private dirty RSS: 2.60 MB


-------- Nginx processes --------

### Processes: 0
### Total private dirty RSS: 0.00 MB


----- Passenger processes -----
PID    VMSize    Private  Name
-------------------------------
12219  294.6 MB  2.4 MB   Passenger watchdog
12222  849.3 MB  4.2 MB   Passenger core
### Processes: 2
### Total private dirty RSS: 6.57 MB
```
The output should show both Apache and Passenger running process without any issues.

This is my very fisrt post and my intention is to make this as my own reference incase I forget some details of the installation process. I hope this will help other developers as well.