LEMP

How to Install Nginx, MySQL, PHP (LEMP) stack on Ubuntu 16.04

NGINX Car by Walker Cahall

NGINX Car by Walker Cahall

Verified and Tested 03/3/15

Introduction

This how-to will show you how to install LEMP on a Ubuntu 16.04 cloud server. LEMP is a web service stack that consists of a Linux operating system, Nginx (pronounced “engine-x”), MySQL, and PHP. The main difference between LAMP and LEMP is that LAMP uses Apache, and LEMP uses Nginx. LEMP has been gaining popularity in the last few years because it excels in speed and scalability.

Prerequisites

A server with Ubuntu 16.04 installed.  If you do not have a server, consider cloud hosting from Atlantic.Net – we even offer specialized cloud hosting like HIPAA-compliant cloud storage solutions.

Installing LEMP on a Ubuntu 16.04  Cloud Server

First we want to make sure that your server is up to date by running the commands:

sudo apt update
sudo apt upgrade

Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:

sudo apt remove apache2*

Followed by:

sudo apt autoremove

 

Installing Nginx on Ubuntu 16.04

To install Nginx, use the command:

sudo apt install nginx

When it asks “Do you want to continue?”, hit Enter.

Start the Nginx service with the following command:

sudo service nginx start

We can now test Nginx by going to your hostname or IP address in your browser’s address bar. If you do not know your server’s IP address, you can run the following command:

ifconfig

You should get a result similar to the image below.

An example of ifconfig showing the IP address 172.20.6.154

An example of ifconfig showing the IP address 172.20.6.154

In our example, 192.168.0.192 is the IP address. So in our browser we would go to http://192.168.0.192.

You should see a web page that looks like the image below.

This example is the default nginx web page on Ubuntu 16.04

This example is the default nginx web page on Ubuntu 16.04

Now that Nginx is installed, we can move on to installing MySQL.

Installing MySQL on Ubuntu 16.04

Install MySQL with the command:

sudo apt install mysql-server

When it asks “Do you want to continue?”, hit Enter.

Shortly after, a screen similar to the image below will appear.  You need enter a password for your MySQL root user. It should be a strong password.

Insert your secure password for your new MySQL root password

Insert your secure password for your new MySQL root password

Hit enter to continue. Once you have hit enter, a new screen will appear prompting you to re-enter the password you just picked.

Retype your MySQL password

Retype your MySQL password

Now that MySQL is installed we need to do the MySQL secure installation by running the command:

sudo mysql_secure_installation

Enter your MySQL root password. When it asks “Change the root password?”, type “N” followed by Enter. The rest of the questions are up to you. For standard installations, you can hit Enter for the defaults. It will look similar to the code box below.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

 

Now that MySQL is installed, we can now install PHP.

Installing PHP on Ubuntu 16.04

Install PHP with the following command:

sudo apt install php php-fpm php7.0-mysql

When it asks “Do you want to continue?”, hit Enter.

For Nginx to work with PHP correctly, we need to edit an Nginx configuration file. In this how-to, we are going to use a simple Nginx config file.

First, we need to move the original configuration file to a new file name. Run the command:

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

Using a text editor of your choice, we are going to make a file called default in /etc/nginx/sites-available. For nano use the command:

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

Copy the following into your text editor:

server {
        listen       80;
        server_name  your_site_name.com;
        root /usr/share/nginx/html;
        index index.php index.html;

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

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

In nano, to exit and save, hit Ctrl+x , type “y”, and then Enter.

Since we made changes to the configuration file, we need to restart Nginx, by running the command:

sudo service nginx restart

We are now going to make a simple PHP page to test.

Using a text editor of your choice, we are going create a file called info.php in /usr/share/nginx/html/.

sudo nano /usr/share/nginx/html/info.php

Copy the following into your text editor.

<?php
phpinfo();
?>

In your browser, you can go to http://Your-Hostname/info.php or http://Your-IP-Address/info.php. As above, in this example, we would use http://192.168.0.192/info.php.

You should see a web page similar to the one below.

An example of the info.php web page

An example of the info.php web page

Once you are done testing, it is a good idea to remove the info.php file, since it may give a potential attacker information that can be used to craft a specific attack against your server. To do that run the command:

sudo rm /usr/share/nginx/html/info.php

Congratulations, you have installed LEMP on Ubuntu 16.04. Thank you for following this how-to. Please check back for more updates, or take a look at our how-to on Installing WordPress on Ubuntu 16.04!


How to Install Nginx, MySQL, PHP (LEMP) stack On a Debian 8.3 Cloud Server

Brendan Bonner January 13, 2016 by under VPS Hosting 0 Comments
NGINX Car by Walker Cahall

NGINX Car by Walker Cahall

Verified and Tested 8/26/16

Introduction

This how-to will show you how to install LEMP on a Debian 8.3 cloud server. LEMP is a web service stack that consists of a Linux operating system, NGINX, MySQL, and PHP. The main difference between LAMP and LEMP is that LAMP uses Apache and LEMP uses NGINX. LEMP has been gaining popularity within the last few years because it excels in speed and scalability.

Prerequisites

A server with Debian 8.2 installed.  If you do not have a server,  please consider an SSD Cloud VPS from Atlantic.Net.

Installing LEMP on a Debian 8.3 Cloud Server

First we want to make sure that your server is up to date by running the command:

apt-get update
apt-get upgrade

Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:

apt-get remove apache2*

Followed by:

apt-get autoremove

Installing Nginx on Debian 8.3

To install Nginx use the command:

apt-get install nginx

When it asks “Do you want to continue? ”  Hit enter.

Start the Nginx service with the following command:

service nginx start

We can now test Nginx, by going to your hostname or IP address in your browsers address bar. If you do not know your IP address you can run the following command:

ifconfig

You should get a result similar to the image below.

An example of ifconfig that shows the IP address of 192.168.0.2

An example of ifconfig that shows the IP address of 192.168.0.2

 

In our example, 192.68.0.2 is the IP address. So in our browser we would go to http://192.68.0.2

You should see a web page that looks like the image below.

This is the default webpage when installing Nginx on Debian 8

This example is the default Nginx web page on Debian 8.3

 

Now that Nginx is installed, we can move on to installing MySQL.

Installing MySQL on Debian 8.3

Install MySQL with the command:

apt-get install mysql-server

When it asks “Do you want to continue?” hit enter.

Shortly after, a screen similar to the image below will appear.  You need enter a password for your MySQL root user. It should be a strong password.

Insert your own secure password for your new MySQL root passwod

Insert your secure password for your new MySQL root password

 

Hit enter to continue. Once you have hit enter, a new screen will appear prompting you to re-enter the password you just picked.

Re-enter your new root password.

Re-enter your new root MySQL password.

 

Now that MySQL is installed we need to do the MySQL secure installation by running the command:

mysql_secure_installation

Enter your MySQL root password. When it asks “Change the root password?” Type N followed by enter. The rest of the questions are up to you. For standard installations, you can hit enter for the defaults.

An example of the mysql_secure_install

An example of the mysql_secure_install

 

Now that MySQL is installed we can now install PHP.

Installing PHP on Debian 8.3

Install PHP with the following command:

apt-get install php5 php5-fpm php5-mysql

When it asks “Do you want to continue?” hit enter.

For Nginx to work with PHP correctly, we need to edit a Nginx configuration file. In this how to, we are going to place a simple Nginx config file.

First we need to moved the original to a new file name, run the command:

mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

Using a text editor of your choice, we are going to make a file called default in /etc/nginx/sites-available. For nano use the command:

nano /etc/nginx/sites-available/default

Copy the following into your text editor:

server {
        listen       80;
        server_name  your_site_name.com;
        root /var/www/html;
        index index.php index.html index.htm index.nginx-debian.html;

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

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

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

In nano to exit and save, hit ctrl+x and type y and then enter.

We are now going to make a simple PHP page to test.

Using a text editor of your choice, we are going make a file called info.php in /var/www/html

nano /var/www/html/info.php

Copy the following into your text editor.

<?php
phpinfo();
?>

Since we made changes to the conf files, we need to restart Nginx, by running the command:

service nginx restart

In your browser, you can go to http://Your-Hostname/info.php or http://Your-IP-Address/info.php

You should see a web page similar to the one below.

An example of what your info.php file should look like

An example of what your info.php file should look like

Congratulations you have installed LEMP on Debian 8.3. Thank you for following this How-To! Check back for more updates, and take a look at our how-to Installing WordPress on Debian 8. Atlantic.Net offers expert technical support and services like Managed Cloud Hosting and popular one-click install applications like cPanel Cloud Hosting.


How to Install CodoForum software on Ubuntu with Nginx

Jason Mazzota December 23, 2015 by under VPS Hosting 0 Comments
Verified and Tested 12/23/15

Introduction

This walkthrough will take you through a base installation of CodoForum on an Ubuntu server that has Nginx as the web application and MySQL and PHP installed. At this time, the current download of CodoForum is 3.4.build-19 .

Prerequisites

An Ubuntu server with LEMP (Nginx, PHP, and MySQL ) installed. Use our Ubuntu LEMP guide, if needed. We also offer Nginx with Ubuntu as part of our One-Click Applications on our Cloud Service under the application name LEMP Cloud Hosting.  If you do not have a server already, you may try one of our fast SDD VPS Servers.

Read More


Thoughts from the Creator of LEMP Stack

The LAMP stack is still the king as far as open-source development bundles go, but LEMP has quickly gained ground over the last few years. Let’s learn more about this increasingly popular web development stack.

  • What is a LEMP Stack?
  • A Look at its Components
  • More on Nginx and its Users
  • Thoughts from Igor Sysoev
  • Nginx vs. Apache in the Real World
  • One-Click LEMP Stack Hosting

What is a LEMP Stack?

In 1998, tech reporter Michael Kunze wrote an article for the German magazine Computertechnik, demonstrating how a developer can work with free open-source software instead of using proprietary systems. In that piece, Kunze became a rock star in the open-source community for being the first person to introduce the concept of LAMP.

Read More


How to Install LEMP using Atlantic.Net’s One-Click Application

Jose Velazquez November 16, 2015 by under VPS Hosting 0 Comments
NGINX Car by Walker Cahall

NGINX Car by Walker Cahall

Verified and Tested 10/31/15

Introduction

Atlantic.Net is actively working towards providing an exceptional customer experience for everyone, whether you are Tech savvy or not, we want to simplify our services so you can be up and running in no time. This is where the One-Click application installation comes into place. Atlantic.Net is working to ensure that all of the most popular applications are available to you at the click of a button.

In this how-to we will walk you through Atlantic.Net’s LEMP one-click VPS hosting install.  As of now, we offer the LEMP One-click installation runs on an Ubuntu 14.04 LTS Operating System.

Prerequisites

The only requirement that you need to accomplish this task is a valid or active Atlantic.Net cloud account. If you do not have one, please sign up here.

Installing LEMP via Atlantic.Net’s One-Click Install

First we need to log into the Cloud Portal here: https://cloud.atlantic.net and select Add Server.

Click on Add Server

Click on Add Server

You will now be prompted to type a server name (in this case our server will be named “One Click LEMP”), and then you will select the location where you want your server created. If you don’t know which location to use, we recommend selecting the one that is closest to your geographical area to ensure the best performance.

Server name and server location

Server name and server location

Then, you will need to click on Applications and then select LEMP. You should see that it will change the icon to LEMP on Ubuntu 14.04.

LEMP application selected

LEMP application selected

Once done, you will need to select the size that you want to create. For this tutorial, an XS server was selected.

Server size selected

Server size selected

Finally, you before you create the server there are two optional add-ons to choose from: SSH Key and Enable Backups.Atlantic.Net highly recommends using both of these features to help improve security and to ensure that all of your server data is backed up.

Once you’ve decided to go with the add-ons or not, you may proceed with the clicking Create Server.

Create Server selected

Create Server selected

You will then see your servers information like the following image. You should receive a copy of this information in your email. Make sure to store your server connection details in a safe place!

Server created and server credentials

Server created and server credentials

Once you’ve received an email stating your server is available you can use an SSH client to access the server, or you can use our Atlantic.Net VNC Console from within your Cloud Panel.  For this tutorial, we are using PUTTY – a free open source SSH client that can be downloaded here. Once your in, you will see the following Welcome message on your terminal session.

Your servers Welcome message with MySQL Credentials

Your servers Welcome message with MySQL Credentials

Now, that the installation is complete we can begin testing out our LEMP components. Since we’re already in the command line, Let us test MYSQL with the following command which will confirm that it is running.

mysql status
MySQL status

MySQL status

Then, we will test Nginx by going to your web browser and typing http://YOUR.IP.ADD.RESS you should see the following screen.

Nginx verification page online

Nginx verification page online

Finally, we can test PHP by completing the following steps. We must create a test PHP file which can be accomplished with the following command:

nano /usr/share/nginx/html/test.php

You will then paste the following PHP script in the empty document and then save your file.

<?php
phpinfo();
?>

 

OK! Finally, test PHP by going to your web browser and typing http://YOUR.IP.ADD.RESS/test.php you should see the following screen.

PHP verification page online

PHP verification page online

Remove the test.php file with the following command:

Note: It is always a good idea to remove your phpinfo file as a hacker could use it to attack you.

 rm /usr/share/nginx/html/test.php

What Next?

Congratulations! You have just installed LEMP using Atlantic.Net’s One-Click Install. Thank you for following along in this How-To and feel free to check back with us for latest updates.


A Tale of Stack-Worthiness: The Rise of Nginx

Nginx has accrued increasingly impressive market share in recent years. What’s its story?

  • WordPress Developer Switches to LEMP
  • Nginx is Not Slowing its Pace
  • How the Web is Being Won
  • Growth of Nginx & LEMP to Fuel Your Own Project

WordPress Developer Switches to LEMP

The LAMP stack (open source development environment using Linux, Apache, MySQL, and PHP) has always been incredibly popular among developers, but in the past few years, that has started to change. What people are starting to use instead is called a LEMP stack, which replaces the Apache web server with a Russian little-engine-that-could competitor, Nginx (pronounced “Engine X” – hence the E in LEMP). Keep in mind that the code for Nginx is free, open-source, and is identified by the official site as both NGINX and nginx.

Read More


How to Install LEMP on Ubuntu 15.10 (Linux, Nginx, MySQL and PHP)

Verified and Tested 10/26/15

Introduction

This how-to will go through the process of installing at LEMP stack on Ubuntu 15.10. LEMP is very similar to LAMP, with one significant difference, you are installing NGINX instead of Apache. NGINX development has focused on performance, which is why many are beginning to migrate to NGINX web servers and away from Apache. This guide will still be using MySQL and PHP.

Prerequisites

A server with Ubuntu 15.10 installed.

Installing LEMP on a Ubuntu 15.10 Cloud Server

First we want to make sure that your server is up to date by running the commands:

sudo apt-get update

Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:

sudo apt-get remove apache2*

Followed by:

sudo apt-get autoremove

 

Installing Nginx on Ubuntu 15.10

To install Nginx, use the command:

sudo apt-get install nginx

Hit Enter, when it asks,”Do you want to continue?”

Start the Nginx service with the following command:

sudo service nginx start

Verify that NGINX is working by opening your browser and entering your IP address or hostname.

Don’t know your IP address? No problem, run the following command:

ifconfig

You will get an output similar to the one below. Next to eth0 we can see that the inet addr is 192.168.0.192. That is your IP address.

This is an example of ifconfig that shows the IP address of 192.168.0.192

This is an example of ifconfig that shows the IP address of 192.168.0.192

So in our browser we would go to http://192.168.0.192.

Once you have entered your IP address or Hostname, you should get a web page similar to the following.

This is an example of the default web page for NGINX on Ubuntu 15.10

This is an example of the default web page for NGINX on Ubuntu 15.10

Now that Nginx is installed, we can move on to installing MySQL.

Installing MySQL on Ubuntu 15.10

Install MySQL with the command:

sudo apt-get install mysql-server

Hit Enter, when it asks,”Do you want to continue?”

During the install, a screen similar to the one below will pop up. You need to create a MySQL root password. Choose a password of your choice, It should be a strong password.

Set a secure password for the MySQL root password

Set a secure password for the MySQL root password

Hit enter to continue. Once you have hit enter, a new screen will appear prompting you to re-enter the password you just picked.

Reenter your MySQL root password

Reenter your MySQL root password

MySQL is now installed, but we add some basic security by running the MySQL secure installation:

sudo mysql_secure_installation

It will first prompt you to enter your MySQL root password, which you can do so.  After it will ask you to “Change the root password?”, type N and then press Enter. The rest of the question you can hit Enter for the defaults unless there are certain things you would like to keep open.

This is an example of the MySQL secure installation

This is an example of the MySQL secure installation

Now that MySQL is installed, we can now install PHP.

Installing PHP on Ubuntu 15.10

Install PHP with the following command:

sudo apt-get install php5 php5-fpm php5-mysql

Hit Enter, when it asks, “Do you want to continue?”

To get Nginx to work with PHP correctly, we need to make changes to the Nginx configuration file. This guide we will be using a simple Nginx config file.

First, we are going to move the original configuration file to a new filename. Run the command:

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

Next using a text editor of your choice, we are going to make a file called default in /etc/nginx/sites-available. For nano use the command:

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

Copy the following into your text editor:

server {
        listen       80;
        server_name  your_site_name.com;
        root /usr/share/nginx/html;
        index index.php index.html;

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

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

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

In nano, to exit and save, hit Ctrl+x , Ytype , and then Enter.

Since we made changes to the configuration file, we need to restart Nginx, by running the command:

sudo service nginx restart

To test PHP, we are going to create a file called info.php.

Using a text editor of your choice, create info.php in /usr/share/nginx/html/.

sudo nano /usr/share/nginx/html/info.php

Copy the following into your text editor.

<?php
phpinfo();
?>

In your browser, you can go to http://Your-Hostname/info.php or http://Your-IP-Address/info.php. As above, in this example, we would use http://192.168.0.192/info.php.

You should get a web page that shows the version of PHP among other things, it will look like the image below.

This is an example of the PHP.info page on Ubuntu 15.10

This is an example of the PHP.info page on Ubuntu 15.10

Now that we verified that the info.php is working, it is a good idea to remove it as it gives a potential attacker information that can be used to craft a particular attack against your server. To do that run the command:

sudo rm /usr/share/nginx/html/info.php

Congratulations, you have installed LEMP on Ubuntu 15.10. Thank you for following this how-to. Please check back for more updates, or learn more about our reliable HIPAA-compliant cloud storage solutions.



How to Configure NGINX on a CentOS 6.7 Server

Daniel Foster September 22, 2015 by under VPS Hosting 0 Comments
NGINX Car by Walker Cahall

NGINX Car by Walker Cahall

Verified and Tested 04/10/2015

Introduction

This how-to will help you install and configure NGINX so you can run high traffic websites while maintaining the high level of performance your customers expect. We are also going to install additional software in order to get the most out of NGINX, so this guide will also include installation and configuration of MySQL, PHP-APC, and PHP-FPM.

Why NGINX? There’s a long back and forth debate over whether you should use Apache or NGINX, and while the overall performance of the two web server platforms is roughly the same, NGINX’s event-based processing model shines by being simple, lightweight and simply better at handling large amounts of concurrent hits for static content without overly taxing your server hardware.

Read More


How to Install LEMP (Nginx, MySQL, PHP) on Centos 6.7

Jose Velazquez August 17, 2015 by under VPS Hosting 0 Comments
NGINX Car by Walker Cahall

NGINX Car by Walker Cahall

Verified and Tested 08/17/15

Introduction

In this How-To, we will walk you through the LEMP install on your CentOS 6.7 Server. LEMP is a software bundle that is made up of four parts (Linux, Nginx, MySQL, and PHP). This how-to will be using CentOS 6.7 which was released on August 7th, 2015, Nginx version 1.0.15, MySQL version 5.1.73 and php-fpm using PHP version 5.3.3.

Prerequisites

A server with CentOS 6.7 already installed. If you do not have a CentOS 6.7 server, you can get a reliable virtual private SSD server from Atlantic.Net and be up and running in under 30 seconds!

Installing EPEL in CentOS 6.7 for LEMP

In this how to we are going to install the Fedora epel release to quickly install Nginx. Run the following command to install EPEL:

sudo yum install epel-release

Installing and Configuring NGINX in CentOS 6.7 for LEMP

Install NGINX with the following command:

sudo yum install nginx

Start the NGINX service with the following command:

sudo /etc/init.d/nginx start

Configure NGINX to start when the system is rebooted:

sudo chkconfig nginx on

You will now have NGINX installed on your server. This can be verified by typing in the following with your IP ADDRESS on your browser. Also, all configuration files are provided on the page.

We can now verify Apache is working by opening your browser and entering the URL http://your-server's-address. you should get a blue Nginx test page similar to the image below.

Note: If you do not know your IP address, run the following command:

sudo ip addr show eth0
An example of running the command: ip addr show eth0 and getting 192.168.100.10 for the IP address.

An example of running the command: ip addr show eth0 and getting 192.168.100.10 for the IP address.

In our example we would put http://192.168.100.10 into our browser’s address bar.

 

Sample Nginx Default Webpage

Sample Nginx Default Webpage

Installing and Configuring MySQL on CentOS 6.7 for LEMP

Install MySQL with the following command to begin the install:

sudo yum install mysql-server

Start the service with the following command:

sudo service mysqld start

Set root MySQL password with the following command:

sudo /usr/bin/mysql_secure_installation

Note: You will be prompted with a series of questions. Just type Y for yes on all of them, see the screen shot below:

Sample my_secure_installation output.

Sample my_secure_installation output.

Configure MySQL to start when the system is rebooted:

sudo chkconfig mysqld on

 

Installing and Configuring php-fpm on CentOS 6.7 for LEMP

Install php-fpm with the following command:

sudo yum install php-fpm php-mysql

Start the php-fpm service with the following command:

sudo service php-fpm restart

Make sure php-fpm starts on boot with the following command:

sudo chkconfig php-fpm on

Using your favorite editor, edit the file /etc/php-fpm.d/www.con  and change user and group from apache to nginx. It should look similar to the block below.

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

Now we need to make some changes to the Nginx configuration file so that php-fpm works correctly with Nginx. Using your favorite editor, edit the file /etc/nginx/conf.d/default.conf and carry out the following changes or copy the following block below into your conf file.

1) Add the index.php to the index location

2) Change the root location to /usr/share/nginx/html

3) Uncomment the Pass PHP scripts to FastCGI section.

4) Change the fastcgi_param  SCRIPT_FILENAME  to use /usr/share/nginx/html$fastcgi_script_name

#
# The default server
#
server {
    listen       80 default_server;
    server_name  _;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

 

Create a test PHP file in the following directory with the following command:

sudo vi /usr/share/nginx/html/info.php

Insert the following code in the space then save and exit:

<?php
phpinfo();
?>

Restart apache so all the changes take effect:

sudo service nginx restart

Test your page in your browser with the following hyperlink changed with yourIP address:
http://YOUR.IP.ADD.RESS/info.php

Sample info.php

Sample info.php

You should removed the info.php file as it could be used against you by an attacker. Delete it with the following command:

sudo rm /usr/share/nginx/html/info.php

Congratulations! You have just installed LEMP on your CentOS 6.7 Server. Thank you for following along in this How-To! Check back with us for any new updates and browse our scalable VPS hosting solutions for any sized business.


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources