What’s LEMP?
LEMP are Linux, Nginx, MySQL, and PHP.
What’s Nginx?
Nginx is an open source web server that runs very fast and uses fewer system resources. You will not see the difference between Apache and Nginx when the site has low traffic. However, when in heavy load, you will see the difference between Nginx and Apache
Previously we had instructions on installing LAMP (Linux, Apache, MySQL, PHP) on Ubuntu. This article will guide you to install LEMP on Ubuntu.
Step to Step install LEMP on Ubuntu
First, you need a fresh Ubuntu server. It’s not installed anything. On this guide, we are using Ubuntu 12.04 64bit and Putty for SSH login to the server.
1. Update Apt-Get
sudo apt-get update
2. Install MySQL
sudo apt-get install mysql-server php5-mysql
During installation, you will have to install root MySQL password
After installing MySQL, activate by the command:
sudo mysql_install_db
Complete installation
sudo /usr/bin/mysql_secure_installation
Enter the root password
Enter current password for root (enter for none): OK, successfully used password, moving on...
Then the actions such as reset password, delete the anonymous user … This is your setup
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...
MySQL installation file path: /etc/my.cnf
3. Install Nginx
sudo apt-get install nginx
Run Nginx
sudo service nginx start
At this point, you can directly access the IP / domain to see if Nginx is active or not
4. Install PHP
sudo apt-get install php5-fpm
5. Customize PHP
Customize php.ini
sudo nano /etc/php5/fpm/php.ini
Find the line cgi.fix_pathinfo = 1 (press Ctrl + W in nano editor), remove the accent; at the beginning and replace 1 = 0
cgi.fix_pathinfo=0
Save (Ctrl + O, Enter) and exit (Ctrl + X)
Custom php5-fpm
sudo nano /etc/php5/fpm/pool.d/www.conf
Find the line listen = 127.0.0.1:9000 and replace 127.0.0.1:9000 with /var/run/php5-fpm.sock.
listen = /var/run/php5-fpm.sock
Save and exit.
Restart php-fpm
sudo service php5-fpm restart
6. Customize Nginx
Open the default virtual host file
sudo nano /etc/nginx/sites-available/default
Find and change the settings as shown below. Note that newer versions of Ubuntu use ‘htm’ instead of ‘www’ so you need to adjust the settings accordingly.
[...] server { listen 80; root /usr/share/nginx/www; index index.php index.html index.htm; server_name example.com; location / { try_files $ u $ you / /index.php?$args; } 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 127.0.0.1:9000 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; } } [...]
Some changes:
- Add index.php
- Change server_name to the domain
- Edit the path to suit the permalink of the WP
- Resize the content in the “location ~ \ .php $ {“
Save and exit.
7. Create PHP info file
Create php.info file
sudo nano /usr/share/nginx/www/info.php
Add content
<?php phpinfo(); ?>
Save and exit
Resume Nginx
sudo service nginx restart
Finished, you can now view the Nginx and PHP-fpm settings by visiting: HTTP: //youripaddress/info.php
8. Install phpMyAdmin
sudo apt-get install phpmyadmin
When phpMyAdmin asks you to select the server (apache or lighttpd), select any one.
Tạo symbolic link
sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/www
The mcrypt extension is missing when running phpMyAdmin
Mở php.ini file
sudo nano /etc/php5/fpm/php.ini
Find the Dynamic Extensions section and add the following line to the end
extension=mcrypt.so
Restart php5-fpm
sudo service php5-fpm restart
Restart Nginx
sudo service nginx restart
Now you can access phpMyAdmin via http://youripaddress/phpmyadmin
Need helps, please leave a comment.