Menu

Install WordPress with Nginx on Ubuntu 15.10 & 14.04WordPress is a free and open-source content management system (CMS) based on PHP and MySQL.WordPress is installed on a web server, which either is part of an Internet hosting service or is a network host itself; the first case may be on a service like WordPress.com, for example, and the second case is a computer running the software package WordPress.org.


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

Example:-
root@ip-172-31-27-102:~# sudo apt-get install python-software-properties
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  python-software-properties
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 19.6 kB of archives.
After this operation, 138 kB of additional disk space will be used.
Get:1 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ trusty-updates/universe python-software-properties all 0.92.37.7 [19.6 kB]
Fetched 19.6 kB in 0s (0 B/s)
Selecting previously unselected package python-software-properties.
(Reading database ... 51150 files and directories currently installed.)
Preparing to unpack .../python-software-properties_0.92.37.7_all.deb ...
Unpacking python-software-properties (0.92.37.7) ...
Setting up python-software-properties (0.92.37.7) ...
root@ip-172-31-27-102:~# sudo add-apt-repository -y ppa:ondrej/mysql-5.5
gpg: keyring `/tmp/tmpmlk2941t/secring.gpg' created
gpg: keyring `/tmp/tmpmlk2941t/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpmlk2941t/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

$ sudo add-apt-repository -y ppa:ondrej/mysql-5.5


Example : - 
root@ip-172-31-27-102:~# sudo add-apt-repository -y ppa:ondrej/mysql-5.5
gpg: keyring `/tmp/tmpmlk2941t/secring.gpg' created
gpg: keyring `/tmp/tmpmlk2941t/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpmlk2941t/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

$ sudo add-apt-repository ppa:ondrej/php5

Example : -
root@ip-172-31-27-102:~# sudo add-apt-repository ppa:ondrej/php5
 This PPA contains latest PHP 5.5 packaged for Ubuntu 14.04 LTS (Trusty).

You can get more information about the packages at https://deb.sury.org

If you need other PHP versions use:
  PHP 5.4: ppa:ondrej/php5-oldstable (Ubuntu 12.04 LTS)
  PHP 5.5: ppa:ondrej/php5 (Ubuntu 14.04 LTS)
  PHP 5.6: ppa:ondrej/php5-5.6 (Ubuntu 14.04 LTS - Ubuntu 16.04 LTS)
  PHP 5.6 and PHP 7.0: ppa:ondrej/php (Ubuntu 14.04 LTS - Ubuntu 16.04 LTS)

BUGS&FEATURES: This PPA now has a issue tracker: https://deb.sury.org/pages/bugreporting.html

PLEASE READ: If you like my work and want to give me a little motivation, please consider donating: https://deb.sury.org/pages/donate.html

WARNING: add-apt-repository is broken with non-UTF-8 locales, see https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:

# apt-get install -y language-pack-en-base
# LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php5
 More info: https://launchpad.net/~ondrej/+archive/ubuntu/php5
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpq141jr43/secring.gpg' created
gpg: keyring `/tmp/tmpq141jr43/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpq141jr43/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ondřej Surý" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
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 -


Example : - 
root@ip-172-31-27-102:~# curl http://nginx.org/keys/nginx_signing.key | apt-key add -
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1559  100  1559    0     0  11066      0 --:--:-- --:--:-- --:--:-- 11056
OK

$ sudo apt-get update
$ sudo apt-get install nginx php5 php5-fpm  mysql-server php5-mysql
Set Mysql Password ...


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 office web using following command.
$ wget http://wordpress.org/latest.tar.gz

root@ip-172-31-27-102:/var/www/html# wget http://wordpress.org/latest.tar.gz
--2016-02-16 12:20:04--  http://wordpress.org/latest.tar.gz
Resolving wordpress.org (wordpress.org)... 66.155.40.250, 66.155.40.249
Connecting to wordpress.org (wordpress.org)|66.155.40.250|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://wordpress.org/latest.tar.gz [following]
--2016-02-16 12:20:05--  https://wordpress.org/latest.tar.gz
Connecting to wordpress.org (wordpress.org)|66.155.40.250|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7099520 (6.8M) [application/octet-stream]
Saving to: ‘latest.tar.gz’

100%[=============================================================================================================================>] 7,099,520   11.6MB/s   in 0.6s

2016-02-16 12:20:05 (11.6 MB/s) - ‘latest.tar.gz’ saved [7099520/7099520]

root@ip-172-31-27-102:/var/www/html#
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
After submitting database details, click on “Run the Install
Install WordPress Button
  • Blog Title
  • Username of admin account (for security do not use as “admin”)
  • Admin password ( twice )
  • Email ID

After completing above step, You have installed WordPress successfully, Now you will get WordPress success installation message.

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top