This guide shows how to cost-effectively host small WordPress sites using a self-managed VPS and a LEMP stack, achieving performance comparable to managed WordPress hosting. While managed services like WP Engine offer convenience, they can be expensive (starting around $30/month). This approach offers a viable alternative for users comfortable with basic server administration.
Key Benefits:
Setting up Your DigitalOcean VPS:
This tutorial uses DigitalOcean, but Linode, Vultr, and others are equally suitable. The steps are largely the same regardless of provider.
Create a DigitalOcean account at https://www.php.cn/link/1be9573be51135cd5be1e191f44e09f8.
Create a Droplet (VPS) using these recommended settings:
Note the IP address and root password (sent via email).
Accessing Your VPS via SSH:
root
using the emailed password.ssh root@<ip_address></ip_address>
. Accept the server key and enter your password.
Change the root password immediately for enhanced security.
Installing and Configuring the LEMP Stack:
sudo apt-get update
sudo apt-get install nginx mysql-server php5-fpm php5-mysql php5-curl php5-gd php5-cgi
sudo mysql_install_db
, sudo mysql_secure_installation
. Create a dedicated WordPress database and user (e.g., wordpress
database, wordpress
user) with a strong password. The command mysql -u root -p
will allow you to interact with the mysql command line./etc/php5/fpm/php.ini
and set cgi.fix_pathinfo=0
./etc/nginx/sites-available/default
) with a configuration tailored for WordPress, ensuring you replace domain.com
with your actual domain name. The provided configuration includes gzip compression and caching for static assets.sudo adduser wordpress
) and add it to the www-data
group (sudo usermod -a -G wordpress www-data
). Change the PHP-FPM user to wordpress
in /etc/php5/fpm/pool.d/www.conf
.reboot
Installing WordPress:
cd /usr/share/nginx; wget http://wordpress.org/latest.tar.gz; tar xfz latest.tar.gz; mv wordpress/* ./; rm latest.tar.gz; rmdir wordpress
.sudo chmod g w /usr/share/nginx -R; sudo chown -R wordpress:www-data /usr/share/nginx
Post-Installation: Regularly update WordPress, themes, and plugins. Use strong passwords, security plugins, backups, and performance monitoring for optimal security and performance. Multiple WordPress sites can be hosted on a single VPS using nginx virtual hosts. The FAQ section addresses common questions about security, optimization, and troubleshooting.
The above is the detailed content of Building a VPS with WordPress on a LEMP Stack. For more information, please follow other related articles on the PHP Chinese website!