How to install WordPress on Linux
Installing WordPress on Linux can be a bit intimidating for those who are new to the process, but with the right steps and tools, it can be quite simple. In this article, we will go over the steps to install WordPress on a Linux server using Ubuntu as an example.
Before you begin, you’ll need to have the following prerequisites:
- A Linux server running Ubuntu 20.04 or later.
- A web server (such as Apache or Nginx) installed on your server.
- PHP 7.4 or later and a database server (such as MySQL or MariaDB) installed and configured on your server.
Step 1: Install LAMP stack
The first step is to set up the LAMP stack (Linux, Apache, MySQL, and PHP) on your server. You can do this by running the following command:
sudo apt-get install lamp-server^
During the installation, you will be prompted to create a root password for MySQL. Make sure to choose a strong and secure password.
Step 2: Create a MySQL Database and User
The next step is to create a database and a user for your WordPress installation. You can do this by logging in to the MySQL command-line interface by running the following command:
mysql -u root -p
You will be prompted to enter the root user’s password. Once logged in, you can create a new database and user by running the following commands:
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
Make sure to replace ‘password’ with a strong and secure password for your new user.
Step 3: Download and Install WordPress
The next step is to download and install WordPress. You can do this by visiting the official website and downloading the latest version of WordPress or by running the following command:
wget https://wordpress.org/latest.tar.gz
This command will download the latest version of WordPress to your server in a compressed (tar.gz) format. Once the download is complete, extract the files by running the following command:
tar -xvzf latest.tar.gz
You will then need to move the extracted files to the appropriate directory for your web server, which is /var/www/html for Apache and /usr/share/nginx/html for Nginx. For example, if you’re using Apache, you can run the following command to move the files:
sudo mv wordpress /var/www/html/
Step 4: Configure Apache or Nginx
You will now need to configure your web server to serve the WordPress files. If you are using Apache, you can do this by creating a new virtual host configuration file.
sudo nano /etc/apache2/sites-available/wordpress.conf
and add the following contents:
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/wordpress
ServerName example.com
<Directory /var/www/html/wordpress>
AllowOverride All
</Directory>
</VirtualHost>
If you are using Nginx, you will need to create a new server block configuration file and make sure it points to your WordPress installation. You can do this by creating a new file in the /etc/nginx/sites-available/ directory and adding the following contents:
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Make sure to replace example.com with your actual domain name and to check the path of the root and location of fastcgi_pass
Step 5: Configure WordPress
Once you’ve configured your web server, you can now access the WordPress installation by visiting your domain name or IP address in a web browser. You should be directed to the WordPress setup page, where you will be prompted to provide your database details and create an admin account.
You will need to provide the following information:
- Database name: wordpress
- User name: wpuser
- Password: (the password you set for the wpuser in step 2)
- Database host: localhost
- Table prefix: (you can leave this as the default value wp_ )
Fill out the form and then click submit. After that, you will be prompted to run the WordPress installation script and you can simply press “Run the installation” button.
You will then be asked to provide some basic information about your site, such as the site title, admin username and password. Once you’ve provided all of the required information, click on the “Install WordPress” button and wait for the installation to complete.
Wrapping up
And that’s it! WordPress should now be installed and configured on your Linux server. You can now access the admin dashboard by visiting your domain name or IP address followed by /wp-admin and logging in with the admin account you created during the installation process.
Please note that this is just a simple guide on how to install WordPress on Linux using Ubuntu, and there are many other ways to install and configure WordPress. Also, it’s always a good idea to secure your installation using SSL, using security plugins and keeping your system and WordPress updated.