A web server, PHP, and a database in one sitting; the boring, dependable kind of stack.
Steps
You need root or sudo access over SSH. Open ports 80 and 443 in your firewall if you run one (see our firewall article). Point your domain's A record at YOUR.IP.ADDRESS. This article uses nginx; Apache works too.
- Update the system. Debian or Ubuntu:
apt update && apt upgrade -y. AlmaLinux:dnf upgrade -y. Install the stack.
- Debian or Ubuntu:
apt install nginx mariadb-server php-fpm php-mysql -y - AlmaLinux:
dnf install nginx mariadb-server php-fpm php-mysqlnd -y
- Debian or Ubuntu:
- Start everything and enable it at boot. On AlmaLinux:
systemctl enable --now nginx mariadb php-fpm. On Debian and Ubuntu the PHP service name includes a version (such asphp8.4-fpm), so find it first withsystemctl list-units | grep fpm, then runsystemctl enable --now nginx mariadb php8.4-fpmwith your version in place of 8.4. - Secure the database with
mariadb-secure-installation(older systems call itmysql_secure_installation). Answer its prompts: you can accept the default for switching to unix_socket authentication, set a root password if you want one, remove anonymous users, disallow remote root login, and remove the test database. Tell nginx to pass
.phpfiles to PHP-FPM. Edit your site's server block (Debian and Ubuntu:/etc/nginx/sites-available/default; AlmaLinux:/etc/nginx/conf.d/). On Debian the stock file has the PHP block commented out, so uncomment it or add a block like this one. Runls /run/php/to see your socket's real name.``
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.4-fpm.sock; }``On AlmaLinux, use
include fastcgi_params;and the socket path from your PHP-FPM pool file.- Test the config and reload:
nginx -t && systemctl reload nginx. - Create a test page:
echo '<?php phpinfo();' > /var/www/html/info.php. Visithttp://YOUR.IP.ADDRESS/info.php(http, not https, until you add a certificate), then delete it withrm /var/www/html/info.php. It reveals a lot about your server. - Create a database and user for your app: run
mysql, thenCREATE DATABASE appdb;,CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'a-strong-password';, andGRANT ALL ON appdb.* TO 'appuser'@'localhost';.
If it didn't work
- If
aptsays "Network is unreachable" for a mirror, just run the command again. nginx -tnames the file and line of any config error.journalctl -u nginx -n 50shows why a service refused to start. On AlmaLinux with SELinux enforcing, checkausearch -m avc -ts recent.- Smart VPS is self-managed, so application setup is yours, but open a ticket under Technical Support if the VPS itself seems at fault.