Home > CMS Tutorial > WordPress > Building a VPS with WordPress on a LEMP Stack

Building a VPS with WordPress on a LEMP Stack

William Shakespeare
Release: 2025-02-16 13:18:12
Original
552 people have browsed it

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:

  • Affordable WordPress hosting.
  • Performance matching managed hosting solutions.
  • Control over your server environment.

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.

  1. Create a DigitalOcean account at https://www.php.cn/link/1be9573be51135cd5be1e191f44e09f8.

  2. Create a Droplet (VPS) using these recommended settings:

    • Hostname: A descriptive name (e.g., your company name).
    • Image: Ubuntu 14.04 x64 (default).
    • Size: The $5/month option (512 MB RAM, 1 CPU, 20 GB SSD, 1000 GB transfer) is a good starting point.
    • Region: Choose a region close to your target audience.
    • Backups: Enable this for data protection.

    Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack

  3. Note the IP address and root password (sent via email).

Building a VPS with WordPress on a LEMP Stack

Accessing Your VPS via SSH:

  • Windows: Use PuTTY. Enter the IP address, select SSH, and connect. Accept the security alert. Log in as root using the emailed password.
  • macOS: Use Terminal. Execute ssh root@<ip_address></ip_address>. Accept the server key and enter your password.

Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack

Change the root password immediately for enhanced security.

Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack

Installing and Configuring the LEMP Stack:

  1. Update the package manager: sudo apt-get update
  2. Install the LEMP stack: sudo apt-get install nginx mysql-server php5-fpm php5-mysql php5-curl php5-gd php5-cgi
  3. Configure MySQL: Set a strong root password, remove anonymous users, disallow remote root login, remove the test database, and reload privilege tables using 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.
  4. Configure PHP: Edit /etc/php5/fpm/php.ini and set cgi.fix_pathinfo=0.
  5. Configure nginx: Replace the default nginx configuration (/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.
  6. Create a non-root user for WordPress (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.
  7. Restart the server: reboot

Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack

Installing WordPress:

  1. Download and install WordPress using cd /usr/share/nginx; wget http://wordpress.org/latest.tar.gz; tar xfz latest.tar.gz; mv wordpress/* ./; rm latest.tar.gz; rmdir wordpress.
  2. Set appropriate file permissions: sudo chmod g w /usr/share/nginx -R; sudo chown -R wordpress:www-data /usr/share/nginx
  3. Access the WordPress installation via your browser using the server's IP address. Complete the installation process.

Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack Building a VPS with WordPress on a LEMP Stack

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template