Free tools Windows power users keep installed
One-click scans. No signup required.
The shortest reliable path is Ubuntu 24.04 LTS, Apache2, and PHP’s Apache module: update the server, install php with libapache2-mod-php, verify execution with a temporary phpinfo() page, then replace it with your application. Add database extensions only if the application needs them. Ubuntu also supports nginx with PHP-FPM when you need a separate FastCGI PHP service.
Need a server to try this on? Antihost offers Linux VPS plans with NVMe storage, full root access and a 14-day free trial.
What you will build
This guide takes a fresh Ubuntu Server installation to a working PHP page that can be reached through a hostname or domain. The main procedure uses Apache2 because Ubuntu provides a direct PHP module package for it. The final sections explain the nginx and PHP-FPM design, optional databases, release differences, and the security work required before exposing the site publicly.
As an Amazon Associate I earn from qualifying purchases.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minuteUbuntu describes PHP as a general-purpose language suited to web development because PHP scripts can be embedded in HTML. Installing Ubuntu alone does not install PHP: PHP, the web-server integration, and any application-specific extensions are separate packages.
Requirements and capacity
Access and software prerequisites
- A supported Ubuntu Server installation with SSH access for remote administration.
- A non-root administrative account that can use
sudo. Keep direct root logins out of the normal workflow. - A domain name or hostname if the site must be reachable publicly. A private test server can be reached by its internal hostname or address instead.
- A database service only when the application requires persistent data. A simple PHP page does not need MySQL or PostgreSQL.
Ubuntu 24.04 LTS baseline
Ubuntu’s published minimums for 24.04 LTS amd64 are operating-system baselines, not a promise that a busy PHP application will perform well:
#1 Best Overall
| Installation image | Minimum RAM | Minimum storage |
|---|---|---|
| ISO installation | 1.5 GB | 5 GB |
| Cloud image | 1 GB | 4 GB |
Ubuntu suggests 3 GB or more of RAM and 25 GB or more of storage for a more useful installation. Application code, logs, uploads, a database, backups, and traffic can require substantially more capacity, so treat those figures as a starting point rather than a sizing recommendation for production.
Confirm the Ubuntu release before copying commands
Package names, default PHP versions, service names, and configuration paths can change between Ubuntu releases. Check the server first:
lsb_release -a
If that command is unavailable, inspect /etc/os-release. The commands below are written for Ubuntu 24.04 LTS. On another release, confirm the package and service names in that release’s documentation before proceeding.
Choose Apache or nginx before installing PHP
Ubuntu supports both Apache2 and nginx. The choice changes how the web server hands a request to PHP.
| Decision point | Apache2 with PHP module | nginx with PHP-FPM |
|---|---|---|
| PHP connection | Apache loads libapache2-mod-php and executes PHP through its module. |
nginx passes PHP requests to PHP-FPM, PHP’s FastCGI Process Manager. |
| Initial installation | Direct for a beginner using Ubuntu’s PHP module package. | Requires nginx, a PHP-FPM package, and matching FastCGI configuration. |
| Configuration model | Apache virtual-host configuration plus enabled modules. | nginx server block plus an FPM socket or listener and an FPM pool. |
| Isolation and tuning | Uses Apache’s PHP-module process model; tuning follows the Apache deployment. | Separates the web server from PHP workers; pool sizing and socket/listener settings become part of operations. |
| Best fit | A small site, a first deployment, or an application whose instructions target Apache. | A design that already standardizes on nginx, FastCGI, or separately managed PHP workers. |
Neither architecture is universally faster. Base the decision on the application or CMS compatibility, the process model you need, and the team’s existing operational experience. If you are starting from a blank Ubuntu server and want the fewest moving parts, follow the Apache path below.
Build the site with Apache2
1. Update the operating system
Connect over SSH with your administrative account, then update package metadata and installed packages:
Recommended Free Tools
sudo apt update && sudo apt upgrade
Run this before installing application packages and continue to apply regular security updates. Ubuntu also documents unattended-upgrades for automatically applying appropriate security updates; decide whether its policy fits your server’s change-control requirements.
Rank #2
2. Install Apache2 and PHP
If Apache2 is not already installed, install it from Ubuntu’s packages. Then install PHP and the Apache integration package:
sudo apt install php libapache2-mod-php
The php package provides the PHP runtime, while libapache2-mod-php connects that runtime to Apache. This is enough to execute ordinary PHP files through the Apache document root.
3. Add only the extensions your application needs
Do not install every available PHP extension by default. Match packages to the application’s requirements:
| Package | Use |
|---|---|
php-cli |
Running PHP scripts from the command line, including maintenance scripts and framework commands that support CLI execution. |
php-cgi |
CGI execution when that architecture is specifically required. |
php-mysql |
Connecting PHP applications to MySQL. |
php-pgsql |
Connecting PHP applications to PostgreSQL. |
For example, a MySQL-backed application needs the PHP MySQL extension as well as a running database service. A PostgreSQL application needs the PostgreSQL extension instead. A page that only renders HTML or processes data without persistence may need none of these database packages.
4. Check that Apache’s PHP module is enabled
Inspect /etc/apache2/mods-enabled/ and confirm that the PHP module configuration files are present. If they are missing, enable the module supplied by the installed PHP package with Ubuntu’s a2enmod utility, using the module name associated with the PHP version on this server. Version suffixes are release-dependent, so do not copy a suffix from a different Ubuntu installation.
Restart Apache after changing module configuration:
sudo systemctl restart apache2.service
If Apache does not restart, read the service status and log output before changing files. A syntax error in a virtual-host or module configuration must be corrected before the service can start safely.
5. Verify PHP through the browser
Create a temporary file named phpinfo.php in the Apache document root with exactly this content:
<?php
phpinfo();
?>
Open http://hostname/phpinfo.php, replacing hostname with the server’s hostname. A PHP information page confirms that Apache is handing the file to PHP instead of returning the source code or downloading it.
Delete phpinfo.php immediately after the check. It exposes detailed configuration information that is useful for diagnosis but should not remain as a public endpoint.
6. Replace the diagnostic page with your application
Copy the application’s index.php and supporting files into the document root used by the site. If the application or framework specifies a public subdirectory, use that layout rather than exposing the entire project directory. Keep application code separate from directories that must be writable for uploads or generated files, following the framework or CMS’s deployment guidance.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
At this point, request the site’s normal URL rather than the diagnostic path. If the application has its own installer, complete that installer only after confirming that the required PHP extensions and database service are available.
Add a database only when the application needs one
PHP itself does not require a database. A brochure page, a small form that sends data elsewhere, or a script that reads static files can run without one. Install a database service when the application needs accounts, posts, orders, sessions, or other persistent records.
Choose the database supported by the application, then install the matching PHP extension. Ubuntu’s PHP package guidance names php-mysql for MySQL and php-pgsql for PostgreSQL. The extension lets PHP communicate with the selected database; it does not create the database, user, schema, backups, or access policy. Those remain application and database-administration tasks.
Rank #4
- Read the application’s required PHP and database versions before choosing packages.
- Keep database credentials out of files that can be downloaded or committed publicly.
- Back up both the application files and the database, and test that a backup can actually be restored.
Use nginx with PHP-FPM when that architecture fits
nginx is Ubuntu-supported, but it does not use Apache’s libapache2-mod-php module. The normal design is nginx in front and PHP-FPM behind it. PHP-FPM means PHP’s FastCGI Process Manager: nginx forwards a PHP request to an FPM socket or listener, and an FPM worker returns the generated response.
What the nginx setup must contain
- The nginx web server and a server block for the hostname.
- A PHP-FPM package matching the PHP version installed on the release.
- A FastCGI connection from the server block to the FPM socket or listener.
- A document-root and index configuration that sends PHP files to FPM while serving ordinary assets directly.
- An FPM pool configuration whose worker and socket settings suit the server’s resources.
Exact package names, socket paths, service names, and configuration locations vary by Ubuntu release and installed PHP version. Verify the installed FPM service name and socket on the server instead of assuming a path copied from another version. Choose this route when your application documentation, existing operations team, or deployment standard already uses nginx and FastCGI; otherwise, Apache’s module path is the simpler first deployment.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Make the deployment safe before publishing it
Use least privilege
Administer the machine with a normal account and use sudo only for administrative actions. Do not run the website or its maintenance tasks as root. Least privilege limits the damage if an application bug or stolen credential is used against the server.
Restrict network access
Use SSH for remote administration and restrict inbound traffic with a firewall such as ufw. Allow only the services the deployment actually needs. A public website normally needs web traffic; administration should remain limited to trusted sources where practical. Remove or disable services and packages that the site does not use, reducing the exposed attack surface.
Keep the operating system and PHP current
Run regular upgrades and decide whether Ubuntu’s unattended-upgrades service should apply security fixes automatically. Updating the operating system without updating application dependencies, or vice versa, can leave compatibility gaps, so test important changes before applying them to a production site.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Enable HTTPS before handling sensitive data
Put HTTPS in place before collecting passwords, payment information, or personal data. Ubuntu’s server documentation covers certificates and network security, but certificate issuance and renewal depend on the chosen domain, web server, and certificate authority. Treat TLS configuration as a required production task rather than assuming the HTTP test URL is suitable for real users.
Plan recovery, not just deployment
Back up application files and databases on a schedule appropriate to the site. Test restoration on a separate location so you know the backup contains usable data and that the application can be rebuilt. A backup that has never been restored is an assumption, not a recovery plan.
Remove diagnostics and development leftovers
Delete phpinfo.php, temporary archives, installer scripts, debug endpoints, and credentials used during setup. Confirm that upload directories contain only the files the application expects and that code directories are not writable unless the application explicitly requires it.
Troubleshoot the first request
The browser downloads PHP source or shows it as text
Apache is serving the file without handing it to PHP. Check that libapache2-mod-php is installed, that the PHP module configuration appears under /etc/apache2/mods-enabled/, and that Apache was restarted after enabling it. Do not leave the site public while source code is being exposed.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →The browser returns an Apache error page
Confirm that the requested file is inside the active document root and that the hostname reaches the intended virtual host. If you changed Apache configuration, inspect the service status and logs and correct syntax or path errors before retrying.
The PHP page loads but the application reports a missing extension
Install the specific extension named by the application, such as php-cli, php-mysql, or php-pgsql, then restart the relevant PHP-serving service. Avoid guessing at extension names when the application requires another module; verify the package available for the Ubuntu release.
The application cannot connect to its database
Check that the database service is installed and running, that the selected PHP database extension matches it, and that the application’s host, database name, user, and password are correct. A PHP extension alone does not create a database or grant access.
nginx returns a gateway or FastCGI error
Verify that the PHP-FPM service is installed and running, then compare the nginx server block’s socket or listener with the endpoint actually provided by the installed FPM service. Release-specific socket names are a common source of mismatches. Check both nginx and FPM logs after correcting the endpoint.
Ubuntu 24.04 LTS support horizon
Ubuntu 24.04 LTS is security-maintained for five years, through 31 May 2029, according to Canonical’s 2024 release notes. Ubuntu Pro and the Legacy add-on can extend coverage. The maintenance date does not freeze package versions: PHP defaults, service names, module names, and configuration paths can still differ across releases and updates. Record the release and installed PHP version when documenting the server so future administrators can reproduce the deployment accurately.
Production launch checklist
- Ubuntu release confirmed with
lsb_release -aor/etc/os-release. - System packages updated and an ongoing update policy chosen.
- Apache2 with
libapache2-mod-php, or nginx with a verified PHP-FPM service, selected deliberately. - Only application-required PHP extensions installed.
- Application files placed in the correct document root, with writable directories separated as the application recommends.
- Database installed only if required, with matching PHP extension and tested credentials.
- Non-root administration, SSH access, and firewall rules configured.
- Unneeded services and packages removed or disabled.
- HTTPS enabled before collecting sensitive information.
- Application and database backups created, with a restoration test completed.
phpinfo.phpand other diagnostic or installer files removed.
For a first PHP deployment on Ubuntu 24.04, Apache’s php plus libapache2-mod-php route minimizes moving parts. Once the page works, add only the extensions, database, HTTPS configuration, and operational controls that the application and its users require.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




