HostiServer
2025-04-02 08:37:00
Everything you need to know about setting up a PHP server
Is your site loading slowly? Customers won't wait — they'll go to competitors. Let's fix this together! Imagine: you launched a project, but delays are scaring visitors away. We'll show you how to configure your PHP server so that it runs quickly and reliably. Now let's see how proper PHP server setup solves these problems.
Why bother with a PHP server?
PHP is the engine of your site. Without it, WordPress, Laravel or other platforms won't run. And if the server performs poorly, it affects everything — from speed to security.
Why is this important:
- A slow site scares away customers and worsens your Google rankings.
- Cyber threats are more relevant than ever today — without protection, you're at risk.
- As your project grows, the server must handle the load. For example, one of our clients launched an online store on WooCommerce. When its traffic increased, the server couldn't cope with the load. We optimized PHP and boosted the site speed by 70%.
We have helped over 600 clients optimize their sites — and we'll share our experience with you.
Which environment to choose for PHP?
First, decide where to run your PHP code. Here are the main options:
Local tools
- XAMPP: Simple to use, works on Windows, Linux, macOS..
- WAMP: Convenient for Windows and WordPress projects.
- Laragon: Lightweight and fast for testing.
⚠️ Warning: Local tools are only for testing. For live sites, you need reliable hosting like Hostiserver.
Built-in PHP server
For a quick test:
php -S localhost:8000
And it works!
Production environment
- Apache: Easy to configure, compatible with PHP.
- Nginx: Fast and efficient for large projects.
Now let's move on to the installation.
How to install a web server on Ubuntu: step-by-step guide
Want to have control over the server? Here's how to do it on Ubuntu.
Installing Apache
Step by step:
- Update packages:
sudo apt update
- Install Apache:
sudo apt install apache2
- Add PHP:
sudo apt install libapache2-mod-php
Don't forget to restart the server:
sudo systemctl restart apache2
Installing Nginx
Step by step:
- Update packages:
sudo apt update
- Install Nginx:
sudo apt install nginx
- Add PHP-FPM:
sudo apt install php-fpm
Don't forget to restart the server:
sudo systemctl restart nginx
📌 Tip: Nginx with PHP-FPM handles high traffic well — ideal for popular sites.
How to configure PHP for maximum performance
PHP is the foundation of your server. Let's break it down step by step.
Installing PHP
On Ubuntu:
sudo apt install php php-cli php-fpm
On Windows:
Step by step:
- Download the ZIP from https://www.php.net/downloads.php.
- Extract it to
C:\PHP. - Add its path to the environment variables.
Configuring php.ini
Here are the basic settings:
memory_limit = 256M
max_execution_time = 60
upload_max_filesize = 50M
post_max_size = 50M
error_reporting = E_ALL & ~E_NOTICE
Example: For a store with large photos, we raised upload_max_filesize to 100M — and uploading became seamless. For WooCommerce with lots of images, we recommend increasing memory_limit to 512M.
Connecting to the database
Install MySQL:
sudo apt install mysql-server
Start MySQL:
sudo systemctl start mysql
Connect PHP:
connect_error) {
die("Connection failed: " . $connection->connect_error);
}
echo "Everything works!";
?>
Checking the server
Create info.php in /var/www/html/:
<?php
phpinfo();
?>
Open http://localhost/info.php. If you see details about PHP, everything is working.
Securing the server
Here are 5 steps to secure it:
Disable potentially dangerous functions
In php.ini:
disable_functions = exec,shell_exec
- We recommend disabling functions like exec, shell_exec, passthru, system and others that could pose a threat.
- Protect confidential files
For Apache:
<Files "config.php"> Order Allow,Deny Deny from all </Files>For Nginx:
location ~* ^/config\.php$ { deny all; } - Add HTTPS
Install SSL through your hosting provider.
- Update PHP
Check for updates on https://www.php.net.
- Block threats
Fail2Ban automatically stops suspicious IP addresses.
Advantage: During an attack on one of our clients, Fail2Ban blocked over 200 password-guess attempts in 24 hours.
Besides Fail2Ban, install UFW (Uncomplicated Firewall) for even better protection against unwanted requests.
Once the server is secured, it's time to think about performance.
Improving performance
Reducing load times significantly improves UX and SEO. Here's how:
OPcache
opcache.enable=1 opcache.memory_consumption=128
OPcache stores compiled PHP code in memory so it doesn't have to be processed again — this speeds up the site. Personally, we always recommend it for sites with heavy load — it really saves you from freezes.
Gzip
Compress pages on Apache or Nginx.
CDN
A CDN (Content Delivery Network) speeds up loading of static files, like images and videos.
When using a CDN, don't forget to enable automatic browser-level caching — this speeds up page loads even more.
Caching
Caching stores data in fast memory, reducing request processing time. Use Memcached or Redis.
One client with a WordPress store increased load speed by 60% thanks to OPcache and Memcached. Another client with a blog reduced server response time by 40% thanks to Cloudflare's CDN.
Configuring a PHP server is about speed, security, and flexibility. With the right approach, your site will run without a hitch. Need help? Our servers at Hostiserver are optimized for high speed — the configuration is already done for you. Just launch your site and enjoy stable performance!
FAQ
- How to update PHP without site downtime?
- Test the new version on a local server, then deploy via a staging environment. For example, one of our clients switched from PHP 7.4 to PHP 8.1 on a staging server, then applied these changes to the main site without any issues.
- Which PHP settings are best for WooCommerce?
- Increase
memory_limitto 512M andmax_execution_timeto 120 to handle large catalogs.
- Why is speed important for SEO?
- Google prefers sites that load quickly.
- How does Hostiserver help?
- We provide optimized servers and 24/7 support.