{"id":17510,"date":"2015-08-18T15:03:02","date_gmt":"2015-08-18T20:03:02","guid":{"rendered":"https:\/\/secure.rosehosting.com\/blog\/?p=17510"},"modified":"2022-12-09T05:34:06","modified_gmt":"2022-12-09T11:34:06","slug":"how-to-install-lemp-linux-nginx-mysql-php-fpm-on-a-debian-8-vps","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-install-lemp-linux-nginx-mysql-php-fpm-on-a-debian-8-vps\/","title":{"rendered":"How to install LEMP (Linux, Nginx, MySQL & PHP-FPM) on a Debian 8 VPS"},"content":{"rendered":"
In this article we will walk you through the steps on how to install LEMP (Linux, Nginx, MySQL and PHP-FPM) on a Debian 8 VPS<\/a>. We will be using our SSD 1 Linux VPS<\/a> hosting plan for this tutorial.<\/p>\n UPDATE THE SYSTEM<\/strong><\/p>\n Make sure your server is fully up to date using:<\/p>\n INSTALL NGINX<\/strong><\/p>\n To install Nginx on your Debian 8 server, you need to execute the following command:<\/p>\n After the installation is complete, you can start Nginx with:<\/p>\n Enable Nginx to start on boot:<\/p>\n Possible issues:<\/strong><\/p>\n If during the Nginx installation you encounter error such as:<\/p>\n then, you can fix this by opening the default Nginx configuration file and comment the listen [::]:80 default_server;<\/strong><\/em> line. Enter the below command:<\/p>\n Locate the listen [::]:80 default_server;<\/strong><\/em> line and comment it by putting # in front of the line. Restart Nginx for the changes to take effect and run the install Nginx command so the package manager finishes the Nginx configuration:<\/p>\n Verify that Nginx is running by opening a web browser and visiting your server IP address (http:\/\/server_ip) . You should get the Nginx welcome page like the one below:<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n INSTALL MYSQL<\/strong><\/p>\n Now let’s install MySQL. Issue the following:<\/p>\n During the installation, you will be asked to enter a password for the MySQL root user. Do not enter an easy to crack password. It should contain at least 8 characters mixed with upper and down cases.<\/p>\n Now that MySQL is installed, we recommend you to do the MySQL secure installation by running:<\/p>\n Enter your root password and answer with ‘n’ when you are asked to change your MySQL root password. Below is the entire procedure that you can follow:<\/p>\n Enable MySQL to start on boot:<\/p>\n INSTALL PHP-FPM<\/strong><\/p>\n Install PHP-FPM by running the underneath command:<\/p>\n Next step you need to do is to modify the Nginx configuration file. But to avoid looking for lines that need to be edited or commented out through the default Nginx file, let’s rename the file and create a new one. The below command do exactly that:<\/p>\n Now, that you have a new default file opened, paste the following content:<\/p>\n Save and exit the file.<\/p>\n Now, let’s make a simple PHP page test. Create a PHP info page so you can check your PHP version, modules activated etc…<\/p>\n Create a file, let’s call it info.ph<\/strong><\/em>p into the \/var\/www\/html<\/strong><\/em> directory:<\/p>\n Paste the following into the file:<\/p>\n Restart Nginx for the changes to take effect:<\/p>\n Now, open your favorite web browser and navigate to http:\/\/your_server_ip_address\/info.php . You will be welcomed by a web page similar to the one below:<\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n <\/p>\n That’s it. You have successfully installed the LEMP <\/strong>stack on your Debian 8 VPS<\/a>.<\/p>\n Of course you don\u2019t have to do any of this if you use one of our Linux VPS Hosting<\/a> services, in which case you can simply ask our expert Linux admins to install the LEMP stack for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n PS.<\/span> If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":" In this article we will walk you through the steps on how to install LEMP (Linux, Nginx, MySQL and PHP-FPM) … <\/p>\n
\nA LEMP stack is a synonym of LEMP server or LEMP web server. It refers to a set-up which includes Linux, Nginx, MySQL (MariaDB) and PHP.<\/p>\n
\nREQUIREMENTS<\/strong><\/p>\n# apt-get update && apt-get upgrade<\/pre>\n
# apt-get install nginx<\/pre>\n
# systemctl start nginx<\/pre>\n
# systemctl enable nginx<\/pre>\n
dpkg: error processing package nginx (--configure):\r\ndependency problems - leaving unconfigured\r\nProcessing triggers for systemd (215-17+deb8u1) ...\r\nErrors were encountered while processing:\r\nnginx-full\r\nnginx\r\nE: Sub-process \/usr\/bin\/dpkg returned an error code (1)<\/pre>\n
# vim \/etc\/nginx\/sites-available\/default<\/pre>\n
# systemctl restart nginx\r\n\r\n# apt-get install nginx<\/pre>\n
# apt-get install mysql-server<\/pre>\n
# mysql_secure_installation<\/pre>\n
Setting the root password ensures that nobody can log into the MySQL\r\nroot user without the proper authorisation.\r\n\r\nYou already have a root password set, so you can safely answer 'n'.\r\n\r\nChange the root password? [Y\/n] n\r\n... skipping.\r\n\r\nBy default, a MySQL installation has an anonymous user, allowing anyone\r\nto log into MySQL without having to have a user account created for\r\nthem.\u00a0 This is intended only for testing, and to make the installation\r\ngo a bit smoother.\u00a0 You should remove them before moving into a\r\nproduction environment.\r\n\r\nRemove anonymous users? [Y\/n] y\r\n... Success!\r\n\r\nNormally, root should only be allowed to connect from 'localhost'.\u00a0 This\r\nensures that someone cannot guess at the root password from the network.\r\n\r\nDisallow root login remotely? [Y\/n] y\r\n... Success!\r\n\r\nBy default, MySQL comes with a database named 'test' that anyone can\r\naccess.\u00a0 This is also intended only for testing, and should be removed\r\nbefore moving into a production environment.\r\n\r\nRemove test database and access to it? [Y\/n] y\r\n- Dropping test database...\r\nERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist\r\n... Failed!\u00a0 Not critical, keep moving...\r\n- Removing privileges on test database...\r\n... Success!\r\n\r\nReloading the privilege tables will ensure that all changes made so far\r\nwill take effect immediately.\r\n\r\nReload privilege tables now? [Y\/n] y\r\n... Success!\r\n\r\nCleaning up...\r\n\r\n\r\nAll done!\u00a0 If you've completed all of the above steps, your MySQL\r\ninstallation should now be secure.\r\n\r\nThanks for using MySQL!<\/pre>\n
# systemctl enable mysql<\/pre>\n
# apt-get install php5-fpm php5-mysql<\/pre>\n
# mv \/etc\/nginx\/sites-available\/default \/etc\/nginx\/sites-available\/default.old\r\n\r\n# vim \/etc\/nginx\/sites-available\/default<\/pre>\n
server {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 listen\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 80;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 server_name\u00a0 your_website_name.com;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 root \/var\/www\/html;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 index index.php index.html index.htm index.nginx-debian.html;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location \/ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try_files $uri $uri\/ =404;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 error_page 404 \/404.html;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 error_page 500 502 503 504 \/50x.html;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location = \/50x.html {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 root \/var\/www\/html;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 location ~ \\.php$ {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 try_files $uri =404;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_pass unix:\/var\/run\/php5-fpm.sock;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_index index.php;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 include fastcgi_params;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n}<\/pre>\n
# vim \/var\/www\/html\/info.php<\/pre>\n
<?php\r\nphpinfo();\r\n?><\/pre>\n
# systemctl restart nginx<\/pre>\n