L - Linux
E - Nginx (Pronounced Engine-X)
M - MySQL
P - PHP
Step 1 Log in to your Linux server with the root user. This has taken care of the 'L' of LEMP.
Step 2 Next we will update all the softwares to the latest versions
sudo apt-get update
Step 3 Install MySQL on the server with the following command :
sudo apt-get install mysql-server php5-mysql
You would be prompted to enter a password for your MySQL.
Once the installation is complete activate it using the following command :
sudo mysql_install_db
Next run the MySQL set up script :
sudo /usr/bin/mysql_secure_installation
You will be prompted to enter your password. Then you will be asked to change the root password, type N and move on.
For the rest of the options chose 'Y'.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
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] y
... 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] y
... 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] y
- Dropping test database...
... Success!
- 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] y
... Success!
Cleaning up...
Step 4 Install PHP
sudo apt-get install php5-fpm
Open www.conf file
sudo nano /etc/php5/fpm/pool.d/www.conf
Find the line
sudo nano /etc/php5/fpm/pool.d/www.conf
and change it to
listen = /var/run/php5-fpm.sock
Save the file and exit and restart php-fpm :
sudo service php5-fpm restart
Step 5 Install nginx
echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu $(lsb_release -sc) main" |
sudo tee /etc/apt/sources.list.d/nginx-stable.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
sudo apt-get update
sudo apt-get install nginx
You need to start nginx by typing :
sudo service nginx start
Step 6 Open up the default config file for Nginx
sudo nano /etc/nginx/sites-available/default
The Server block for the config file should have the following settings
server {
listen 80;
root /usr/share/nginx/www;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.html;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
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;
}
}
Restart Nginx
sudo service nginx restart