How to Install WordPress on Linux Server

WordPress is a free and open-source content management system (CMS) which uses PHP and MySQL. WordPress is a freely available web tool that you can use to create beautiful websites. It was released on May 27, 2003, by Matt Mullenweg and Mike Little. You can refer to the link given below for complete details of WordPress. So, let us understand, how to install WordPress on Linux (Centos instance).

How to Install WordPress?

Pre-requisites

WordPress community recommends Apache or Nginx as the most robust and featured server for running WordPress, but any server that supports PHP and MySQL can also be used.

Here, in this tutorial, we will install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 6 with the above prerequisites.

Let us now understand each of them one by one.

So, what is LAMP?

LAMP stack stands for Linux, Apache, MySQL, and PHP. It.is a group of open source software used to run dynamic websites and servers.This setup requires a user who has root privileges, so we need to create a pseudo user first.

Creating a “pseudo” User

Step1: Login to root and add a new user

useradd acadgild

passwd acadgild

Step 2: Provide root privileges to this user

visudo

Refer to the image given below to configure Acadgild by providing root privileges. Add the highlighted line below root line.

Step 3: Save it and restart the ssh services.

service sshd restart

LAMP Installation

Login to pseudo user which we have added recently with root privileges (that’s a must)

Step 1: Install Apache web server-

sudo yum install httpd -y

Step 2: Once installation gets over you can start Apache and its services.

sudo service httpd start

Note: To check if Apache is installed, open your browser with your domain name or server’s IP address (e.g. http://192.168.198.131). The page should display a static page like below:

Installing MySQL database

MySQL is an open-source relational database management system (RDBMS) for organizing data on a server.

Follows these commands to install MySQL:

sudo yum install mysql-server -y

sudo service mysqld start

Once it is done, you should set a root MySQL password. Follow this command to set it:

sudo mysql_secure_installation

Note: A prompt will ask you for your current root password as you have just installed MySQL, so leave it blank by pressing enter.

Configure MySQL according to your need. If you don’t want to go through all that, then allow all the prompts ( press ‘y’ for every prompt).

Installing PHP

PHP is a server-side scripting language, designed for web development. PHP is a powerful tool for making dynamic and interactive Web pages. It is also used as a general-purpose programming language.

Follow the below mentioned commands to install PHP:

sudo yum install php -y

Install php-mysql plugin into Linux server

sudo yum install php-mysql -y

Note: Press ‘y’ if the prompt comes up.

Now LAMP stack is configured on your instance.

Next, We need to set the ‘httpd’ and ‘mysqld’ processes to run automatically every time the Linux server restarts. We don’t need to do for php because it will run automatically once Apache starts.

sudo chkconfig httpd on

sudo chkconfig mysqld on

sudo service httpd restart

Once you have the prerequisite software, you can start installing WordPress!

Installing WordPress

Step 1: First, download WordPress from below link:

wget http://wordpress.org/latest.tar.gz

Step 2: Unzip the compressed file into the desired location.

tar -xvzf latest.tar.gz

Step 3: Creating MySQL User and database for WordPress-

Login to MySQL Shell:

mysql -u root -p

A prompt will ask for MySQL root password, which we have created earlier.

Now, We need a database and an user in that database.

create database wp_db;

Output: Query OK, 1 row affected (0.00 sec)

create user wp_user;

Set password to this user:

Set password for wp_user=password("password");

Now, provide all privileges to this new user.

grant all privileges on wp_db.* to wp_user identified by 'password';

Query OK, 0 rows affected (0.00 sec)

Note: This is important to provide all privileges to this user else WordPress will not be able to start.

At last, refresh MySQL:-

Flush privileges;

Query OK, 0 rows affected (0.00 sec)

exit

WordPress configuration

List all to see the WordPress directory:

ls

Copy wp-config-sample.php to wp-config.php

Open wp-config.php, update the database, user, and its password

vi wp-config.php

Find the section that contains the fields given below and modify in the correct name for the database, username, and password.

Save it.

Copy this WordPress directory into Server

sudo cp -r ~/wordpress/* /var/www/html

Download php-gd, if the form does require a specific php module to run and is not yet installed on your server.

sudo yum install php-gd -y

Next restart Apache services.

sudo service httpd restart

WordPress Installation

Once all the above are in place and installed, go to browser setting and type server’s IP address or domain name(hostname) of the server(Linux). WordPress online installation page will come up. Access the page by adding /wp-admin/install.php to your site’s domain or IP address (e.g. http://192.168.198.131/wp-admin/install.php) or simply type your domain name. WordPress installation page will come up automatically. Refer the below screenshot:

Fill out the form accordingly to your need. E.g. your site title, username, password, email and other entries.

Click to install.

WordPress is now installed to your Linux instance (Centos Server).

Now, Login using username and password. A screen as shown below will get displayed: