console.dir({"ID":81,"post_author":"1","post_date":"2016-04-03 15:57:48","post_date_gmt":"2016-04-03 22:57:48","post_content":"In this guide, we will quickly provide instructions on\u00a0how to install a LEMP stack on an Ubuntu 14.04 server on Digital Ocean. The Ubuntu operating system takes care of the first requirement.\r\n\r\nYou can signup for Digital Ocean\u00a0here\u00a0and deploy a SSD server in less than a minute.\r\n

Installing nginx\r\n
sudo apt-get update\r\nsudo apt-get install nginx\r\nNext, you'll want to check the web server to see if nginx is up and running. In your Digital Ocean panel grab the IP address of the droplet and enter it in to your browser. If everything went well you'll see the nginx welcome screen.\r\n

Install MySQL\r\nNow that we have the web server up, we need to install the MySQL database to store all the information for WordPress. To install MySQL type the command:\r\n
sudo apt-get install mysql-server\r\nIt's going to ask for you to create an admin password. Type in a strong password and keep it somewhere safe.\r\n\r\nNext type in:\r\n
sudo mysql_install_db\r\n
sudo mysql_secure_installation\r\nThese two commands will create the directory structure for MySQL and run a security script to remove some of the defaults and fake user data. You will be prompted for the password that you had created in the previous step. It will also ask you if you want to change your password. You\u00a0can skip this since you just created a new password.\r\n

Installing PHP\r\nOk, we're just about halfway done. We've installed the webserver, the database, and now all we've got left is to install PHP and WordPress. I promise, this rest will go about as quickly and simply as the first half.\r\n\r\nType this command to install PHP and php5-FPM:\r\n
sudo apt-get install php5-fpm php5-mysql\r\nNext, you'll need to edit the config files:\r\n
sudo nano \/etc\/php5\/fpm\/php.ini\r\nWhat you're going to edit is the link that contains 'cgi.fix_pathinfo'. You can scroll through the file or search for the line. You need to uncomment the line by removing the # and the setting the value to 0.\r\n
cgi.fix_pathinfo=0\r\nSave and close the file. To make the changes take effect, restart the services:\r\n
sudo service php5-fpm restart\r\n\r\n

Configuring nginx to use the PHP processor\r\nWe've got to edit the server block to use the PHP processor. To do this type this into the command line:\r\n
sudo nano \/etc\/nginx\/sites-available\/default\r\nEdit the file by making the following changes:\r\n
server {\r\n    listen 80 default_server;\r\n    listen [::]:80 default_server ipv6only=on;\r\n\r\n    root \/usr\/share\/nginx\/html;\r\n    index index.php index.html index.htm;\r\n\r\n    server_name server_domain_name_or_IP;\r\n\r\n    location \/ {\r\n        try_files $uri $uri\/ =404;\r\n    }\r\n\r\n    error_page 404 \/404.html;\r\n    error_page 500 502 503 504 \/50x.html;\r\n    location = \/50x.html {\r\n        root \/usr\/share\/nginx\/html;\r\n    }\r\n\r\n    location ~ \\.php$ {\r\n        try_files $uri =404;\r\n        fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\n        fastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\n        fastcgi_index index.php;\r\n        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;\r\n        include fastcgi_params;\r\n    }\r\n}\r\nTo apply the changes restart nginx:\r\n
sudo service nginx restart\r\n

Creating the MySQL Database the WordPress User\r\nFrom the console enter:\r\n
mysql -u root -p\r\nEnter a password for the root MySQL user when prompted.\r\n\r\nNext create a database, you can use any name of your choice, and it's advisable that you use something other than 'wordpress', but for this example we'll use it for simplicity.\r\n
CREATE DATABASE wordpress;\r\n\r\nNow we've got to create a user for the, again for the sake of simplicity we are going to use 'wordpressuser' and 'password', but you should absolutely use other values to decrease the chance someone can guess the username and password.\r\n
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';\r\nTo grant access for this user to the database type in the following command:\r\n
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;\r\n
FLUSH PRIVILEGES;\r\n
exit\r\nThat completes the database user creation for WordPress.\r\n

Download and Install WordPress\r\nGrab the latest version of Wordpress and extract the contents:\r\n
cd ~\r\nwget http:\/\/wordpress.org\/latest.tar.gz\r\n
tar xzvf latest.tar.gz\r\nInstall some other components we'll need:\r\n
sudo apt-get update\r\nsudo apt-get install php5-gd libssh2-php\r\n

Configure WordPress\r\nHead over the directory we extracted WordPress to:\r\n
cd ~\/wordpress\r\nCopy over the sample config file and rename it.\r\n
cp wp-config-sample.php wp-config.php\r\nEdit the new config file:\r\n
nano wp-config.php\r\nReplace the text in red with your unique values:\r\n
. . .\r\n\/\/ ** MySQL settings - You can get this info from your web host ** \/\/\r\n\/** The name of the database for WordPress *\/\r\ndefine('DB_NAME', 'wordpress');\r\n\r\n\/** MySQL database username *\/\r\ndefine('DB_USER', 'wordpressuser');\r\n\r\n\/** MySQL database password *\/\r\ndefine('DB_PASSWORD', 'password');\r\n. . .\r\n

Copy the files over to the document root\r\nWe're going to change the default location of where nginx stores it's document root from\u00a0\/usr\/share\/nginx\/html\/ to\u00a0\/var\/www\/html\/\r\n\r\nType the following in:\r\n
sudo mkdir -p \/var\/www\/html\r\n
sudo rsync -avP ~\/wordpress\/ \/var\/www\/html\/\r\n
cd \/var\/www\/html\/\r\nGrant nginx permissions to the directory.\r\n
sudo chown -R www-data:www-data \/var\/www\/html\/*\r\nCreate the uploads directory and grant access to nginx.\r\n
mkdir wp-content\/uploads\r\n
sudo chown -R www-data:www-data \/var\/www\/html\/wp-content\/uploads\r\n

Modify Nginx Server Blocks\r\nCopy the default block and create one for WordPress:\r\n
sudo cp \/etc\/nginx\/sites-available\/default \/etc\/nginx\/sites-available\/wordpress\r\nOpen the new file and make the following changes:\r\n
sudo nano \/etc\/nginx\/sites-available\/wordpress\r\n
server {\r\n        listen 80 default_server;\r\n        listen [::]:80 default_server ipv6only=on;\r\n\r\n        root \/var\/www\/html;\r\n        index index.php index.html index.htm;\r\n\r\n        server_name your_domain.com;\r\n\r\n        location \/ {\r\n                # try_files $uri $uri\/ =404;\r\n                try_files $uri $uri\/ \/index.php?q=$uri&$args;\r\n        }\r\n\r\n        error_page 404 \/404.html;\r\n\r\n        error_page 500 502 503 504 \/50x.html;\r\n        location = \/50x.html {\r\n                root \/usr\/share\/nginx\/html;\r\n        }\r\n\r\n        location ~ \\.php$ {\r\n                try_files $uri =404;\r\n                fastcgi_split_path_info ^(.+\\.php)(\/.+)$;\r\n                fastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\n                fastcgi_index index.php;\r\n                include fastcgi_params;\r\n        }\r\n}\r\nCopy the file over to the sites-enabled directory:\r\n
sudo ln -s \/etc\/nginx\/sites-available\/wordpress \/etc\/nginx\/sites-enabled\/\r\nRemove the old file:\r\n
sudo rm \/etc\/nginx\/sites-enabled\/default\r\nRestart the services:\r\n
sudo service nginx restart\r\nsudo service php5-fpm restart\r\nCongrats! That's it's all you've got to do is type in your domain name into a browser and configure the rest of your site.\r\n\r\nA few notes, if you're having issues with updating or installing plugins, you can read up on how to fix it here:\u00a0How To Configure Secure Updates and Installations in WordPress on Ubuntu\r\n

PHP-FPM: Socket vs TCP\/IP and sysctl tweaking\r\nDepending on if your having issues with your WordPress install resulting in the error screen when you visit the site and your getting errors like:\r\n
connect() to unix:\/var\/run\/php5-fpm.sock failed\r\nYou may want to give this a try. What are are about to do is use sockets instead of TCP\/IP.\r\n\r\nOpen PHP-FPM pool config file:\r\n
nano \/etc\/php5\/fpm\/pool.d\/www.conf\r\nUncomment\u00a0the following line by removing the semicolon:\r\n
;listen.backlog = 65536\r\nRestart the service:\r\n
service php5-fpm restart\r\n

Using TCP\/IP for FPM\r\n
nano \/etc\/php5\/fpm\/pool.d\/www.conf\r\nReplace the following line:\r\n
listen = \/var\/run\/php5-fpm.sock\r\nSo it reads:\r\n
listen = 127.0.0.1:9000\r\nUncomment line:\r\n
;listen.mode = 0660\r\nFind and uncomment:\r\n
;pm.max_requests = 500\r\nSave the changes and open the nginx virtual-host config file(s):\r\n
sudo nano \/etc\/nginx\/sites-enabled\/wordpress\r\nFind the line:\r\n
fastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\nReplace with:\r\n
fastcgi_pass 127.0.0.1:9000;\r\nSave the changes and restart the services:\r\n
service php5-fpm restart && service nginx restart\r\n

\r\n

Adding Swap The Fast Way\r\nIf your on the smallest droplet size running WordPress, your likely running fairly low on RAM. To help with this we can create a swap file that should help keep things running fairly smoothly until your ready to upgrade to a larger droplet size.\r\n

Creating a 4GB Swap File\r\nCreate the file:\r\n
sudo fallocate -l 4G \/swapfile\r\nEnable the swap file and set the correct permissions:\r\n
sudo chmod 600 \/swapfile\r\n
sudo mkswap \/swapfile\r\n
sudo swapon \/swapfile\r\n

Make the the Swap File Permanent\r\nWe created the file, enabled it, and told the system to use it, however if the system is restarted it will not use the swap by default to make the changes permanent, we've got to edit the following file:\r\n
sudo nano \/etc\/fstab\r\n\r\nGo to the bottom of the file and add the following line:\r\n
\/swapfile   none    swap    sw    0   0\r\n

Tweak the Swappiness\r\nLet's tweak how much of the swap the system uses:\r\n
sudo nano \/etc\/sysctl.conf\r\nInsert the following lines at the bottom of the file:\r\n
vm.swappiness=10\r\nvm.vfs_cache_pressure = 50\r\n\r\nSave your changes. You're all done!\r\n\r\n ","post_title":"How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 14.04 on DigitalOcean","post_excerpt":"","post_status":"publish","comment_status":"open","ping_status":"closed","post_password":"","post_name":"how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04-on-digitalocean","to_ping":"","pinged":"","post_modified":"2016-12-05 10:39:37","post_modified_gmt":"2016-12-05 18:39:37","post_content_filtered":"","post_parent":0,"guid":"http:\/\/www.eckmandesign.com\/blog\/?p=81","menu_order":0,"post_type":"post","post_mime_type":"","comment_count":"0","filter":"raw"});lang="en-US">  How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 14.04 on DigitalOcean - Eckman Design
		
	







	
	




How To Install Linux, nginx, MySQL, PHP (LEMP) stack on Ubuntu 14.04 on DigitalOcean

Wordpress DigitalOcean Nginx

In this guide, we will quickly provide instructions on how to install a LEMP stack on an Ubuntu 14.04 server on Digital Ocean. The Ubuntu operating system takes care of the first requirement.

You can signup for Digital Ocean here and deploy a SSD server in less than a minute.

Installing nginx

sudo apt-get update
sudo apt-get install nginx

Next, you’ll want to check the web server to see if nginx is up and running. In your Digital Ocean panel grab the IP address of the droplet and enter it in to your browser. If everything went well you’ll see the nginx welcome screen.

Install MySQL

Now that we have the web server up, we need to install the MySQL database to store all the information for WordPress. To install MySQL type the command:

sudo apt-get install mysql-server

It’s going to ask for you to create an admin password. Type in a strong password and keep it somewhere safe.

Next type in:

sudo mysql_install_db
sudo mysql_secure_installation

These two commands will create the directory structure for MySQL and run a security script to remove some of the defaults and fake user data. You will be prompted for the password that you had created in the previous step. It will also ask you if you want to change your password. You can skip this since you just created a new password.

Installing PHP

Ok, we’re just about halfway done. We’ve installed the webserver, the database, and now all we’ve got left is to install PHP and WordPress. I promise, this rest will go about as quickly and simply as the first half.

Type this command to install PHP and php5-FPM:

sudo apt-get install php5-fpm php5-mysql

Next, you’ll need to edit the config files:

sudo nano /etc/php5/fpm/php.ini

What you’re going to edit is the link that contains ‘cgi.fix_pathinfo’. You can scroll through the file or search for the line. You need to uncomment the line by removing the # and the setting the value to 0.

cgi.fix_pathinfo=0

Save and close the file. To make the changes take effect, restart the services:

sudo service php5-fpm restart

Configuring nginx to use the PHP processor

We’ve got to edit the server block to use the PHP processor. To do this type this into the command line:

sudo nano /etc/nginx/sites-available/default

Edit the file by making the following changes:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name server_domain_name_or_IP;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

To apply the changes restart nginx:

sudo service nginx restart

Creating the MySQL Database the WordPress User

From the console enter:

mysql -u root -p

Enter a password for the root MySQL user when prompted.

Next create a database, you can use any name of your choice, and it’s advisable that you use something other than ‘wordpress‘, but for this example we’ll use it for simplicity.

CREATE DATABASE wordpress;

Now we’ve got to create a user for the, again for the sake of simplicity we are going to use ‘wordpressuser’ and ‘password’, but you should absolutely use other values to decrease the chance someone can guess the username and password.

CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

To grant access for this user to the database type in the following command:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;
FLUSH PRIVILEGES;
exit

That completes the database user creation for WordPress.

Download and Install WordPress

Grab the latest version of WordPress and extract the contents:

cd ~
wget http://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz

Install some other components we’ll need:

sudo apt-get update
sudo apt-get install php5-gd libssh2-php

Configure WordPress

Head over the directory we extracted WordPress to:

cd ~/wordpress

Copy over the sample config file and rename it.

cp wp-config-sample.php wp-config.php

Edit the new config file:

nano wp-config.php

Replace the text in red with your unique values:

. . .
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');
. . .

Copy the files over to the document root

We’re going to change the default location of where nginx stores it’s document root from /usr/share/nginx/html/ to /var/www/html/

Type the following in:

sudo mkdir -p /var/www/html
sudo rsync -avP ~/wordpress/ /var/www/html/
cd /var/www/html/

Grant nginx permissions to the directory.

sudo chown -R www-data:www-data /var/www/html/*

Create the uploads directory and grant access to nginx.

mkdir wp-content/uploads
sudo chown -R www-data:www-data /var/www/html/wp-content/uploads

Modify Nginx Server Blocks

Copy the default block and create one for WordPress:

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress

Open the new file and make the following changes:

sudo nano /etc/nginx/sites-available/wordpress
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        server_name your_domain.com;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

Copy the file over to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

Remove the old file:

sudo rm /etc/nginx/sites-enabled/default

Restart the services:

sudo service nginx restart
sudo service php5-fpm restart

Congrats! That’s it’s all you’ve got to do is type in your domain name into a browser and configure the rest of your site.

A few notes, if you’re having issues with updating or installing plugins, you can read up on how to fix it here: How To Configure Secure Updates and Installations in WordPress on Ubuntu

PHP-FPM: Socket vs TCP/IP and sysctl tweaking

Depending on if your having issues with your WordPress install resulting in the error screen when you visit the site and your getting errors like:

connect() to unix:/var/run/php5-fpm.sock failed

You may want to give this a try. What are are about to do is use sockets instead of TCP/IP.

Open PHP-FPM pool config file:

nano /etc/php5/fpm/pool.d/www.conf

Uncomment the following line by removing the semicolon:

;listen.backlog = 65536

Restart the service:

service php5-fpm restart

Using TCP/IP for FPM

nano /etc/php5/fpm/pool.d/www.conf

Replace the following line:

listen = /var/run/php5-fpm.sock

So it reads:

listen = 127.0.0.1:9000

Uncomment line:

;listen.mode = 0660

Find and uncomment:

;pm.max_requests = 500

Save the changes and open the nginx virtual-host config file(s):

sudo nano /etc/nginx/sites-enabled/wordpress

Find the line:

fastcgi_pass unix:/var/run/php5-fpm.sock;

Replace with:

fastcgi_pass 127.0.0.1:9000;

Save the changes and restart the services:

service php5-fpm restart && service nginx restart

Adding Swap The Fast Way

If your on the smallest droplet size running WordPress, your likely running fairly low on RAM. To help with this we can create a swap file that should help keep things running fairly smoothly until your ready to upgrade to a larger droplet size.

Creating a 4GB Swap File

Create the file:

sudo fallocate -l 4G /swapfile

Enable the swap file and set the correct permissions:

sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Make the the Swap File Permanent

We created the file, enabled it, and told the system to use it, however if the system is restarted it will not use the swap by default to make the changes permanent, we’ve got to edit the following file:

sudo nano /etc/fstab

Go to the bottom of the file and add the following line:

/swapfile   none    swap    sw    0   0

Tweak the Swappiness

Let’s tweak how much of the swap the system uses:

sudo nano /etc/sysctl.conf

Insert the following lines at the bottom of the file:

vm.swappiness=10
vm.vfs_cache_pressure = 50

Save your changes. You’re all done!