How To Install WordPress with Nginx on Ubuntu 15.10 & 14.04

WordPress is a free, open source a content-management system (CMS) and blogging tool based on PHP and MySQL. This tutorial will help you to install WordPress with Nginx on Ubuntu system.

Step 1 – Setup LEMP Stack

First we will add all required PPA to our system. Following commands will add PPA for Nginx, PHP5 and MySQL on your system.
$ echo "deb-src http://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx"  >> /etc/apt/sources.list $ echo "deb http://nginx.org/packages/mainline/ubuntu/ `lsb_release -cs` nginx" >> /etc/apt/sources.list $ sudo apt-get install python-software-properties $ sudo add-apt-repository -y ppa:ondrej/mysql-5.5 $ sudo add-apt-repository ppa:ondrej/php5 
and now use following commands to install Nginx web server, PHP5 with PHP5-FPM and MySQL server.
$ curl http://nginx.org/keys/nginx_signing.key | apt-key add - $ sudo apt-get update $ sudo apt-get install nginx php5 php5-fpm  mysql-server php5-mysql 

Step 2 — Configure PHP-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features.
$ sudo nano /etc/php5/fpm/php.ini 
un-comment cgi.fix_pathinfo=1 line and set value to 0.
cgi.fix_pathinfo=0 
Now set the listen parameter in /etc/php5/fpm/pool.d/www.conf configuration file. Here you can use php5-fpm socket to work or start php5-fpm server on any port as service. We are going to use it as service.
$ sudo nano /etc/php5/fpm/pool.d/www.conf 
Now make changes in configuration file as below. Commend listen with socket file and enable it as service
#listen = /var/run/php5-fpm.sock listen = 127.0.0.1:9000 

Step 3 — Download and Configure WordPress

Download latest WordPress archive file from its official website using following command.
$ wget http://wordpress.org/latest.tar.gz 
Extract archive in document root of you domain and update permissions on files.
$ tar xzf latest.tar.gz $ sudo mv wordpress /var/www/example.com $ sudo chown -R apache.apache /var/www/example.com $ sudo chmod -R 755 /var/www/example.com 

Step 4 — Create MySQL Database and User

After extracting WordPress codebase, Let’s create a mysql database and user account for configuring WordPress. Use following set of command to do it
$ mysql -u root -p Enter password:  mysql> CREATE DATABASE wp_db; mysql> GRANT ALL ON wp_db.* to 'wp_user'@'localhost' IDENTIFIED BY '_secret_password_'; mysql> FLUSH PRIVILEGES; mysql> quit 

Step 5 — Configure Nginx VirtualHost

Finally do the configuration of Nginx server block (Virtual Host). For this example we are creating a new configuration file for our domain example.com.
$ sudo nano /etc/nginx/conf.d/example.com.conf 
and make changes as below.
server {         listen   80;          root /var/www/example.com;         index index.php index.html;         server_name  example.com www.example.com;          location / {                 try_files $uri $uri/ /index.php?q=$request_uri;         }          error_page 404 /404.html;         error_page 500 502 503 504 /50x.html;         location = /50x.html {               root /usr/share/nginx/www;         }          location ~ .php$ {                 try_files $uri =404;                 fastcgi_pass 127.0.0.1:9000;                 fastcgi_index index.php;                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                 include fastcgi_params;         } } 
After installing all services on your system, start all required services.
$ sudo service nginx restart $ sudo service php5-fpm restart 

Step 6 — Start WordPress Web Installer

WordPress provides a web installer for easy to setup WordPress without editing files manually. After completing above steps just point your browser to your domain. Fill the database details and click “Submit
wordpress-setup-3
After submitting database details, click on “Run the Install
wordpress-setup-4
Install WordPress Button
  • Blog Title
  • Username of admin account (for security do not use as “admin”)
  • Admin password ( twice )
  • Email ID
wordpress-setup-5
After completing above step, You have installed WordPress successfully, Now you will get WordPress success installation message.
wordpress-setup-6
Congratulation’s! You have successfully installed WordPress with LEMP Stack on your Ubuntu system.

Thanks for Visit Here

Comments