This tutorial explains how to setup a new WordPress
website on your CentOS and Ubuntu servers.
Prerequisites: Before installing your WordPress
website you will need to install some additional services:
- Additional repositories:
Apache2
web server – tutorial here.MySQL
(MariaDB
) database – tutorial here.PHP
– tutorial here.
After Apache2
, MySQL
and PHP
have been installed, you will need to install the php-gd
and php-mysql
(for PHP 5.x) / php-mysqlnd
(for PHP 7.x) PHP extensions
. More about PHP extension
installation here.
On CentOS
systems:
sudo yum install php-gd php-mysql -y
Restart Apache2
for changes to take effect:
sudo systemctl restart httpd
On Ubuntu
systems:
sudo apt-get install php-gd php-mysql -y
Restart Apache2
for changes to take effect:
sudo systemctl restart apache2
Preparation have been completed. Now you will need to setup the and configure the database for your WordPress
website and setup the actual website files.
1. Create the database and user for your WordPress website
First you need to setup the database for your WordPress
website.
Log into the MySQL database using the following command:
mysql -u root -p
Create a new database for your WordPress
website (where “wordpress
” is the name of the database) by running the following query:
CREATE DATABASE wordpress;
Create the database user, which will control the database of your WordPress
website (where “wordpressuser
” is the user name and “password
” is the password for this user) by running the following query:
CREATE USER wordpressuser@localhost IDENTIFIED BY ‘password’;
Technically, the root user can be used as well, however, it is common practice to create different database users and separate their privileges to databases.
Grant the newly created user privileges to use your WordPress
database by running the following query:
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY ‘password’;
Apply the newly implemented privilege changes by running the following query:
FLUSH PRIVILEGES;
You can now exit the database by running the following command:
exit;
2. Install your WordPress website files
Download and unzip your WordPress
website files in your webroot
directory:
cd /var/www/html/ && wget http://wordpress.org/latest.tar.gz && tar xzf latest.tar.gz
Move your WordPress
website files from the /var/www/html/wordpress
folder to the /var/www/html/
folder:
mv -R /var/www/html/wordpress/* /var/www/html/
Remove the leftover empty directory:
rm -Rf /var/www/html/wordpress
You also need to add a folder for your WordPress
website to store uploaded files by running the following command:
mkdir /var/www/html/wp-content/uploads
3. Configure your WordPress installation
Create the wp-config.php
configuration file from the wp-config-sample.php
file:
cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
Fill in the database name, database user name and password details:
nano /var/www/html/wp-config.php
Note: nano
is a simple text editor. It might not be installed by default on your system. You can install in by running the following command:
On CentOS systems:
sudo yum install nano -y
On Ubuntu Systems:
sudo apt-get install nano -y
Set the proper file ownership of the /var/www/html/
folder and its contents:
On CentOS systems:
chown -R apache:apache /var/www/html/*
On Ubuntu systems:
chown -R www-data:www-data /var/www/html/*
4. Finishing touches
Open your website in your browser by entering your domain name or server IP address and fill in the requested username and password details and complete the installation.
Example: http://<your_domain_or_ip_address>/
Log into your new website by adding wp-admin
at the end of your website URL
.
Example: http://<your_domain_or_ip_address>/wp-admin/
Pingback: How to fix WordPress permalink problem with mod_rewrite? - Tiny Tumbleweed