Installing PHP on Ubuntu VPS – Complete AVIOX Cloud Setup Guide

Installing PHP on Ubuntu VPS – Complete AVIOX Cloud Setup Guide

 

PHP is one of the most widely used scripting languages for web development. Whether you’re hosting WordPress, Laravel, or custom applications on AVIOX Cloud, you need a properly configured PHP environment to ensure smooth performance and secure execution. This guide covers the complete step-by-step process to install PHP on an Ubuntu VPS, configure PHP-FPM, add modules, optimize settings, and connect it to Apache or Nginx.

 

1. Preparing Your Ubuntu VPS on AVIOX Cloud

Before installing PHP, update your server:

 
sudo apt update && sudo apt upgrade -y

Install basic dependencies:

 
sudo apt install software-properties-common ca-certificates apt-transport-https -y

This ensures smooth package installation and compatibility with the latest PHP versions.


2. Adding the PHP Repository (Recommended)

Ubuntu’s default repository often contains older PHP versions. For the latest stable releases such as PHP 8.2 or 8.3, add the Ondřej PHP PPA:

 
sudo add-apt-repository ppa:ondrej/php -y sudo apt update

AVIOX Cloud VPS fully supports the latest PHP versions, offering improved performance and security.

 

3. Installing PHP and PHP-FPM

To install PHP-FPM (the recommended handler for modern setups):

 
sudo apt install php8.2 php8.2-fpm -y

If you prefer a different version, replace 8.2 with your desired number.

Check PHP version:

 
php -v

 

4. Installing Essential PHP Extensions

Most applications require specific modules to function correctly. AVIOX Cloud users typically install:

 
sudo apt install php8.2-mysql php8.2-cli php8.2-curl php8.2-xml \ php8.2-gd php8.2-mbstring php8.2-zip php8.2-intl php8.2-bcmath -y

Install additional modules if needed:

  • php-imagick – image processing

  • php-redis – Redis cache support

  • php-opcache – performance boost

You can check available modules:

 
apt search php8.2

 

5. Configuring PHP-FPM

The main config file:

 
/etc/php/8.2/fpm/php.ini

Open it:

 
sudo nano /etc/php/8.2/fpm/php.ini

Recommended performance tweaks:

 
memory_limit = 512M upload_max_filesize = 128M post_max_size = 128M max_execution_time = 300 

After changes, restart PHP-FPM:

 
sudo systemctl restart php8.2-fpm

 

6. Connecting PHP with Nginx (LEMP Setup)

If you’re using Nginx, edit your server block:

 
sudo nano /etc/nginx/sites-available/default

Add:

 
location ~ \.php$ {    include snippets/fastcgi-php.conf;    fastcgi_pass unix:/run/php/php8.2-fpm.sock; }

Test Nginx:

 
sudo nginx -t

Reload:

 
sudo systemctl reload nginx

 

7. Connecting PHP with Apache (LAMP Setup)

Apache integrates differently using libapache2-mod-php, but PHP-FPM is preferred for performance.

Enable PHP-FPM:

 
sudo a2enmod proxy_fcgi setenvif sudo a2enconf php8.2-fpm sudo systemctl restart apache2

Apache now uses PHP-FPM to process PHP files efficiently.

 

8. Testing PHP

Create a test PHP file:

 
sudo nano /var/www/html/info.php

Add:

 
<?php phpinfo(); ?> 

Visit:

 
http://your-server-ip/info.php

You should see the full PHP configuration page.

After verifying, delete it for security:

 
sudo rm /var/www/html/info.php

 

9. PHP Optimization for AVIOX Cloud VPS

✔ Enable OPcache

 
sudo apt install php8.2-opcache -y

Edit your ini file to enable caching:

 
opcache.enable=1 opcache.memory_consumption=256 opcache.interned_strings_buffer=16 opcache.max_accelerated_files=20000 

Restart PHP-FPM afterward.

 

✔ Adjust PHP-FPM Pool Settings

Edit pool configuration:

 
/etc/php/8.2/fpm/pool.d/www.conf

Set process manager:

 
pm = dynamic pm.max_children = 20 pm.start_servers = 4 pm.min_spare_servers = 4 pm.max_spare_servers = 10 

Adjust values based on your AVIOX Cloud VPS resources.

 

✔ Use Redis or Memcached (Optional but Recommended)

Caching improves PHP performance significantly.

Install Redis:

 
sudo apt install redis-server php8.2-redis -y

 

10. Keeping PHP Secure

Security should always be part of configuration.

✔ Disable unnecessary functions

In your php.ini:

 
disable_functions = exec,passthru,shell_exec,system

✔ Limit file uploads

✔ Run PHP-FPM under a dedicated user

✔ Enable a firewall (UFW)

✔ Update PHP regularly

AVIOX Cloud makes updates simple through SSH or automated package updates.

 

11. Final Thoughts

Installing PHP on your AVIOX Cloud Ubuntu VPS is straightforward and highly customizable. Whether you're hosting a large-scale application or a simple website, proper PHP installation and optimization are crucial. By combining PHP-FPM, essential extensions, caching, and security best practices, you’ll achieve excellent performance and stability for any PHP-powered website.


Share:


Leave a comment

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

Your experience on this site will be improved by allowing cookies Cookie Policy