WordPress is a popular content management system that allows you to create and manage your own website with ease. It’s a flexible and powerful tool that can be used for blogs, business websites, and even e-commerce. In this tutorial, we will guide you through the process of installing WordPress on Ubuntu 18.04 with Nginx .
Nginx is a high-performance web server and reverse proxy. It’s known for its high performance, stability, rich feature set, simple configuration, and low resource consumption. Ubuntu 18.04, also known as Bionic Beaver, is a long-term support release from Canonical. This combination provides a stable and secure platform for your WordPress site.
Before we start, make sure you have a fully qualified domain name and a server with Ubuntu 18.04 installed. You should also have SSH access to your server and basic familiarity with command line. This tutorial assumes that you have already installed Nginx on your server. If you haven’t, please refer to our guide on installing Nginx server on Ubuntu 18.04.
Step 1: Update Your System
First, log in to your server via SSH. Once you’re logged in, it’s a good practice to update your system packages to their latest versions. You can do this by running the following commands:
sudo apt update sudo apt upgrade
Step 2: Install MySQL
WordPress uses MySQL to manage and store site and user information. Ubuntu 18.04 includes MySQL in its default repositories, so it can be installed using the apt package manager. Run the following command to install MySQL:
sudo apt install mysql-server
During the installation, you will be asked to set a password for the MySQL root user. Make sure to choose a strong password.
After the installation is complete, run the following command to secure your MySQL installation:
sudo mysql_secure_installation
You will be asked a series of questions. It’s recommended to answer “Y” (yes) to all of them.
Step 3: Create a MySQL Database and User for WordPress
Next, you need to create a MySQL database and user for your WordPress installation. First, log in to the MySQL shell:
sudo mysql -u root -p
Enter the root password you set during the MySQL installation. Once you’re in the MySQL shell, run the following commands to create a database and user:
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; EXIT;
Replace “wordpress” with the name you want to use for your database, “wordpressuser” with the username you want to use, and “password” with a strong password.
Step 4: Install PHP
WordPress is written in PHP, so you need to install PHP and some PHP extensions. Ubuntu 18.04 includes PHP in its default repositories, so it can be installed using the apt package manager. Run the following command to install PHP and necessary extensions:
sudo apt install php-fpm php-mysql php-curl php-gd php-intl php-mbstring php-soap php-xml php-xmlrpc php-zip
Step 5: Configure Nginx to Serve WordPress
Next, you need to configure Nginx to serve your WordPress site. First, navigate to the Nginx sites-available directory:
cd /etc/nginx/sites-available/
Then, create a new configuration file for your WordPress site:
sudo nano wordpress
In the file, paste the following configuration:
server { listen 80; server_name your_domain; root /var/www/html/wordpress; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } location ~ /\.ht { deny all; } }
Replace “your_domain” with your domain name. Save and close the file.
Next, create a symbolic link to this file in the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
Then, test the Nginx configuration to make sure there are no syntax errors:
sudo nginx -t
If the test is successful, restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 6: Download and Install WordPress
Now, you’re ready to download and install WordPress. First, navigate to the /tmp directory and download the latest WordPress package:
cd /tmp curl -LO https://wordpress.org/latest.tar.gz
Then, extract the package and move the WordPress files to your web root directory:
tar xzvf latest.tar.gz sudo cp -a /tmp/wordpress/. /var/www/html/wordpress
Next, set the correct permissions for the WordPress directory:
sudo chown -R www-data:www-data /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress
Step 7: Complete the WordPress Installation Through the Web Interface
Finally, you can complete the WordPress installation through the web interface. Open your web browser and navigate to your domain:
http://your_domain
You will be greeted by the WordPress installation wizard. Follow the prompts, enter the database information you created earlier, and complete the installation.
Congratulations! You have successfully installed WordPress on Ubuntu 18.04 with Nginx!
Commands Mentioned:
- sudo apt update – Updates the list of available packages and their versions.
- sudo apt upgrade – Installs newer versions of the packages you have.
- sudo apt install – Installs a package.
- sudo mysql_secure_installation – Improves the security of your MySQL installation.
- CREATE DATABASE – Creates a new MySQL database.
- GRANT ALL – Gives a MySQL user full permissions on a database.
- FLUSH PRIVILEGES – Reloads the grant tables in the MySQL database, enabling changes to take effect.
- EXIT – Exits the MySQL shell.
- sudonano – Opens a file in the nano text editor.
- sudo ln -s – Creates a symbolic link to a file.
- sudo nginx -t – Tests the Nginx configuration for syntax errors.
- sudo systemctl restart nginx – Restarts the Nginx service.
- curl -LO – Downloads a file from a URL.
- tar xzvf – Extracts a tar.gz file.
- sudo cp -a – Copies files and directories.
- sudo chown -R – Changes the owner of a file or directory.
- sudo chmod -R – Changes the permissions of a file or directory.
FAQ
-
Why do I need to use Nginx with WordPress?
Nginx is known for its high performance, stability, and low resource consumption. It can handle a large number of concurrent connections, making it a good choice for high-traffic WordPress sites.
-
What is the role of MySQL in a WordPress installation?
MySQL is a database management system. WordPress uses MySQL to store all its data, including your website content, user profiles, and customizations.
-
Why do I need to update my system packages before installing WordPress?
Updating your system packages ensures that you have the latest security patches and bug fixes. This can help protect your server from vulnerabilities and improve its performance.
-
What is the purpose of the sudo command?
The sudo command allows you to run commands with the security privileges of another user, by default the superuser. It’s used when performing operations that require higher privileges, such as installing software or changing system configurations.
-
What is the role of PHP in a WordPress installation?
WordPress is written in PHP, a popular scripting language for web development. PHP is used to generate dynamic page content, work with databases, handle cookies, and manage sessions, among other tasks. Without PHP, WordPress would not be able to function.
Conclusion
Installing WordPress on Ubuntu 18.04 involves several steps, but the process is straightforward when you follow them in order. This tutorial has guided you through updating your system, installing MySQL and PHP, creating a MySQL database and user for WordPress, configuring Nginx to serve your WordPress site, downloading and installing WordPress, and finally completing the WordPress installation through the web interface.
By following these steps, you can set up a robust and high-performance WordPress site on your own server. This gives you full control over your site and allows you to customize it to your needs. Whether you’re setting up a personal blog, a business website, or an e-commerce store, WordPress is a versatile and powerful tool that can help you create the perfect site.
Remember, maintaining a website involves more than just setting it up. You need to keep your server and WordPress installation updated, monitor your site’s performance, and ensure it’s secure.
Hope this guide has been helpful in setting up your WordPress site.
Happy web hosting!
1 Comment
Thanks for your nice guidance. I’m a rookie and i completely follow this guide to install wordpress on a virtual machine. however, when I try to open the domain (which is my localhost), it always comes out the default nginx page, not the wordpress page, could you help me solve this problem?