LEMP is a complete package to run any web application on a server. LEMP signifies the Linux, Nginx, MySQL and Php. Nginx is used as the web-server for hosting of an application where as MySQL is used as systematic data storage of application & Php is popular server side scripting language which is used for web development as well bridging the gap between application and the database.
Step 1. Open your EC2 Terminal and update your Packages.
# apt-get update
Step 2. Install Nginx Webserver.
# apt-gt install nginx
Step 3. Every virtual host needs its own configuration file in the /etc/nginx/sites-available/ directory. Create the file for example.com, called /etc/nginx/sites-available/example.com, with the following content. Make sure to replace example.com with your own domain name.
# vim /etc/nginx/sites-available/example.com
server { listen 80; server_name www.example.com example.com; access_log /usr/share/nginx/www/example.com/logs/access.log; error_log /usr/share/nginx/www/example.com/logs/error.log;
location / { root /usr/share/nginx/www/example.com/public_html; index index.html index.htm; } }
Step 4. Restart Nginx.
# service nginx restart
Step 5. Now direct your browser to http://ip or www.example.com and you should see the Nginx page like this.
Step 6. Install Php-fpm for nginx.
# apt-get install php5-cli php5-fpm php5 php5-common php5-mysql -y
Step 7. Configure php for Nginx.
# vim /etc/nginx/sites-available/example.com
server { listen 80; server_name www.example.com example.com; access_log /usr/share/nginx/www/example.com/logs/access.log; error_log /usr/share/nginx/www/example.com/logs/error.log; location / { root /usr/share/nginx/www/example.com/public_html; index index.html index.htm; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # fastcgi_pass 127.0.0.1:9000; # # With php5-fpm: fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } }
Step 8. The document root of the Nginx webserver is /usr/share/nginx/www. Now We will now create PHP file (index.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.
<?php phpinfo(); ?>
Step 9. Use following commands to enable the site.
# ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled
Step 10. Restart Nginx.
# service nginx restart
Step 11. Finish up by visiting your php info page.The page should look like this.
or
http://www.example.com/index.php
Step 12. Install mysql-server in your Machine by running bellow command from your terminal.
# apt-get install mysql-server -y
Step 13. Specify New password for Mysql root user.
Note: Confirm Password for Mysql root user.