Installing WordPress with Nginx on Ubuntu Linux
This tutorial will show you all the steps required to install WordPress with Nginx on Ubuntu Linux.
This tutorial was tested on Ubuntu 18.04.
1. Install Nginx on Ubuntu Linux
Use the Ubuntu APT command to install the Nginx server.
# apt-get update
# apt-get install nginx
Edit the nginx.conf configuration file.
Add client_max_body_size to the HTTP section.
Configure the maximum upload size to 32 Megabytes.
# vi /etc/nginx/nginx.conf
Here is the file with our configuration.
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
client_max_body_size 32M;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Restart the Nginx web server manually.
# service nginx restart
# service nginx status
Verify the Nginx service status.
● nginx.service – A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-12-29 04:29:22 UTC; 1h 17min ago
Docs: man:nginx(8)
Process: 2233 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status
Process: 2221 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exite
Main PID: 2238 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─2238 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2239 nginx: worker process
The Nginx web server was installed successfully.
2. Install MySQL on Ubuntu Linux
WordPress requires a database system to store all its configuration.
Use the Ubuntu APT command to install the MySQL server.
# apt-get update
# apt-get install mysql-server mysql-client
Use the following command to access the MySQL service console.
# mysql -u root -p
On the MySQL console, you need to perform the following tasks:
• Create a database named wordpress.
• Create a MySQL user account named wordpress.
• Give full control over the wordpress database to the wordpress user.
CREATE DATABASE wordpress CHARACTER SET UTF8 COLLATE UTF8_BIN;
CREATE USER ‘wordpress’@’%’ IDENTIFIED BY ‘kamisama123’;
GRANT ALL PRIVILEGES ON wordpress.* TO ‘wordpress’@’%’;
FLUSH PRIVILEGES;
quit;
3. Add PHP support to Nginx
Nginx needs an external program to add PHP support.
Use the Ubuntu APT command to install the PHP required packages.
# apt-get update
# apt-get install php7.2-fpm
Use the following command to install the required PHP modules.
# apt-get install php7.2-xml php7.2-curl php7.2-gd php7.2-mbstring php7.2-readline
# apt-get install php7.2-bz2 php7.2-zip php7.2-json php7.2-opcache
Find the location of the PHP configuration file on your system.
Edit the php.ini configuration file.
# updatedb
# locate php.ini
# vi /etc/php/7.2/fpm/php.ini
Your PHP version may not be the same as ours.
Your PHP configuration file location may not be the same as ours.
Here is the file with our configuration.
file_uploads = On
max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
max_input_time = 60
max_input_vars = 4440
upload_max_filesize = 32M
Edit the Nginx default website configuration file.
# vi /etc/nginx/sites-available/default
Here is the original file, before our configuration.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
Here is the new file with our configuration.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
Verify if your Nginx configuration file has no error.
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart the PHP service.
Restart the Nginx service.
# service php7.2-fpm restart
# service nginx restart
4. Install WordPress on Ubuntu Linux
After finishing the MySQL and the Apache configuration, we can start the WordPress installation.
Download the WordPress latest version and extract the package.
# cd /tmp
# wget https://wordpress.org/latest.tar.gz
# tar -zxvf latest.tar.gz
Move the WordPress folder inside your Apache root drive directory.
Give the www-data user full control over the WordPress directory and its files.
# mv wordpress /var/www/html/
# chown www-data.www-data /var/www/html/wordpress/* -R
Create and edit the WordPress configuration file wp-config.php.
# cd /var/www/html/wordpress
# mv wp-config-sample.php wp-config.php
# vi wp-config.php
Edit the MySQL database connection information located on the wp-config.file.
As an example, here is the file with our configuration.
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘wordpress’);
define(‘DB_PASSWORD’, ‘kamisama123’);
define(‘DB_HOST’, ‘localhost’);
define(‘DB_CHARSET’, ‘utf8’);
define(‘DB_COLLATE’, ”);
Configuring WordPress on Ubuntu Linux
Open your browser and enter the IP address your web server plus /wordpress.
In our example, the following URL was entered in the Browser:
• http://200.200.200.200/wordpress
The WordPress installation wizard will be presented.
On the next screen you will have to enter your website information.
On the next screen, you will receive the confirmation of your WordPress installation.
Click on the Login button and enter the administrator account and password.
After a successful login, The WordPress dashboard will be displayed.
Leave A Comment
You must be logged in to post a comment.