Software & AppsOperating SystemLinux

How To Install PHP Without Apache Webserver

Ubuntu 13

In this comprehensive guide, we will walk you through the process of installing PHP without the Apache webserver. This can be particularly useful if you prefer to use a different web server, like Nginx, or if you want to use PHP for scripting and command-line interface (CLI) tasks.

What is PHP?

PHP is a popular server-side scripting language designed for web development. It is also used as a general-purpose programming language. PHP code is interpreted by a web server with a PHP processor module, which generates the resulting web page.

What is Apache?

Apache is the most widely used web server software. Developed and maintained by Apache Software Foundation, Apache is an open-source software available for free. It runs on 67% of all webservers in the world. It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules. Most WordPress hosting providers use Apache as their web server software. However, WordPress can run on other web server software as well.

Why Install PHP Without Apache?

While Apache is a powerful and flexible web server, it may not be necessary for all PHP applications. For example, if you’re developing a PHP command-line script or a small application that doesn’t require the full features of a web server, you can install PHP without Apache.

Moreover, some developers prefer to use other web servers like Nginx, which can be more performant and resource-efficient in certain scenarios. In these cases, you would install PHP and the web server separately.

Installing PHP Without Apache

Let’s get started with the installation process. We will be using Ubuntu for this guide, but the steps should be similar for other Linux distributions.

Step 1: Install PHP and PHP-CLI

First, open your terminal and run the following command to install PHP and its command-line interface (CLI):

sudo apt install php-cli

The sudo command allows you to run the following command as the superuser, which is necessary for installing software. apt is the package manager used by Ubuntu and other Debian-based distributions. install is the command to install a package, and php-cli is the package we’re installing.

This command will install PHP without any web server dependencies, allowing you to use PHP for scripting and command-line tasks.

Step 2: Install PHP-FPM (Optional)

If you also want to use PHP with a web server like Nginx, you can install PHP-FPM (FastCGI Process Manager) using the following command:

sudo apt install php-fpm

PHP-FPM allows PHP to work with web servers that support the FastCGI protocol, such as Nginx. FastCGI is a variation on the earlier Common Gateway Interface (CGI); it can handle more requests per second and is better suited for larger websites.

Step 3: Configure PHP

After installing PHP, it is recommended to set the date.timezone option in the PHP configuration files. This setting determines the default timezone used by all date/time functions in PHP.

Open the following files with a text editor:

sudo nano /etc/php/{version}/fpm/php.ini
sudo nano /etc/php/{version}/cli/php.ini

Replace {version} with the installed PHP version, such as 7.4.

In each file, search for the date.timezone directive and set it to your desired timezone. For example:

date.timezone = America/New_York

Save the files and exit the text editor.


By following these steps, you can install PHP without Apache webserver on Ubuntu and use it either as a command-line tool or with other web servers like Nginx. This gives you the flexibility to choose the tools that best fit your project’s needs.

Remember to always keep your PHP installation up-to-date to benefit from the latest features and security fixes. You can do this by regularly running sudo apt update and sudo apt upgrade in your terminal.

For more information on PHP and its configuration options, you can refer to the official PHP documentation.

Can I install PHP without Apache on Windows?

Yes, you can install PHP without Apache on Windows. The process may vary slightly from the instructions provided in this guide for Ubuntu. You can download the PHP Windows binaries from the official PHP website and follow the installation instructions provided.

Can I use PHP without a web server?

Yes, you can use PHP without a web server for scripting and command-line tasks. When you install PHP without Apache or any other web server, you can run PHP scripts directly from the command line or execute them as standalone scripts.

Can I install PHP-FPM without Nginx?

Yes, you can install PHP-FPM without Nginx. PHP-FPM is a separate component that allows PHP to work with web servers supporting the FastCGI protocol. While Nginx is a popular choice for using PHP-FPM, you can also configure PHP-FPM to work with other web servers like Apache or LiteSpeed.

How do I check the PHP version after installation?

To check the PHP version installed on your system, open your terminal and run the command php -v. This will display the PHP version and other related information.

How do I change the PHP configuration settings?

To change PHP configuration settings, you can edit the php.ini file. The location of this file may vary depending on your system. You can find the location by running the command php -i | grep 'php.ini'. Once you locate the file, open it with a text editor and modify the desired settings. Save the file and restart the PHP service for the changes to take effect.

Leave a Comment

Your email address will not be published. Required fields are marked *