How to serve PHP through uWSGI on Fedora 21 using systemd & firewalld

uWSGI is a great multi-featured application server and can be configured to serve pretty much anything.  In this article, we'll configure it to serve PHP on Fedora 21.

Let's create a directory out of which we'll be serving the PHP files:

       mkdir -p /var/www

Then, we need to install uWSGI and its PHP plugin, which will automatically install the PHP dependencies.

       yum install uwsgi uwsgi-plugin-php uwsgi-plugin-http

Now for the uWSGI configuration, we're gonna listen on the standard port 80, set the project directory, and the date for PHP and some other miscellaneous settings.

Here's what the ´/etc/phpu.ini´ should look like:

       plugins = http,0:php
       http = :80
       master = true
       master-as-root = true
       uid = uwsgi
       gid = uwsgi
       project_dir = /var/www
       chdir = %(project_dir)
       check-static = %(project_dir)
       static-skip-ext = .php
       static-skip-ext = .inc
       static-index = index.html
       php-docroot = %(project_dir)
       php-allowed-ext = .php
       php-allowed-ext = .inc
       php-index = index.php
       php-index =
       php-set = date.timezone=America/Chicago
       processes = 16
       cheaper = 2

And of course, we want to make it easy to manage so we're gonna turn it into a service called ´phpu´.  Since Fedora 21 uses systemd, here's the unit file  ´/etc/systemd/system/phpu.service´ we're going to use for this service:


       ExecStart=/usr/sbin/uwsgi --ini /etc/phpu.ini


Next, we'll reload the systemd daemon to pick up our new file and enable and start the service:

       systemctl daemon-reload
       systemctl enable phpu
       systemctl start phpu

Let's create an ´/var/www/info.php´ file to test and make sure our service is running:

       <?php phpinfo(); ?>

And we should be able to use curl or wget to see the output:

       curl localhost/info.php

Optionally, we can open port 80 to the public and make it accessible to the Big Bad Internet:

       firewall-cmd --zone=public --add-port=80/tcp --permanent
       firewall-cmd --reload
Posted in
Last update:
2016-04-04 14:31
Average rating:0 (0 Votes)