{"id":4148,"date":"2018-06-15T10:55:50","date_gmt":"2018-06-15T10:55:50","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2018\/06\/15\/installing-lemp-stack-on-centos7\/"},"modified":"2021-07-16T15:27:25","modified_gmt":"2021-07-16T19:27:25","slug":"installing-lemp-stack-on-centos7","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/","title":{"rendered":"Installing LEMP-Stack on CentOS7"},"content":{"rendered":"<p>This guide will show you the steps needed to install a basic <strong>LEMP<\/strong> stack on your Non-cPanel server running CentOS. All the commands shown will need to be run as root on your server via SSH.<\/p>\n<h2> Installing LEMP Stack<\/h2>\n<p><a name=\"\"><\/a><\/p>\n<ol class=\"article_list\">\n<li> Connect to your server as the root user via SSH.<\/li>\n<li> Before installing we need to ensure your packages and repositories are up to date by running the following command. You will be prompted to continue after it has finished checking for updates by pressing y (yes) or n (no), Hit y and then enter to continue.\n<p class=\"cli\"><span style=\"color: #00E000;\">yum update<\/span><\/p>\n<\/li>\n<li> NGINX uses port 80 for non-SSL traffic and 443 for SSL traffic. Both of these ports need to be open in the firewall. Run the following three commands to open them.\n<p class=\"cli\"><span style=\"color: #00E000;\">service firewalld start<br>\nfirewall-cmd \u2013permanent \u2013zone=public \u2013add-service=http<br>\nfirewall-cmd \u2013permanent \u2013zone=public \u2013add-service=https<br>\nfirewall-cmd \u2013reload   <\/span><\/p>\n<\/li>\n<li> Install NGINX by running the following command, You will be prompted to continue, Press y for yes and hit enter.\n<p class=\"cli\"><span style=\"color: #00E000;\">yum install nginx<\/span><\/p>\n<p>      After the install has finished you need to start the service by running the command below.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">systemctl start nginx<\/span><\/p>\n<\/li>\n<li> Installing MariaDB(MySQL), MariaDB is the recommended service for MySQL currently included in the CentOS repositories.\n<p class=\"cli\"><span style=\"color: #00E000;\">yum install mariadb-server mariadb<\/span><\/p>\n<p>       Once installed start the service by running the command below.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">systemctl start mariadb<\/span><\/p>\n<p>       The default install of MariaDB contains settings and users for testing that are not secure, To secure the installation run the command below. You will be asked if you want to set a root password for MariaDB, You should press y and hit enter to continue, You will then be prompted to set a password for MariaDB, Ensure this password is set to a strong password. After setting the password you will get more yes or no prompts, Just hit enter until you have completed the prompts. You will see the message \u201cinstallation should now be secure. Thanks for using MariaDB!\u201d When complete.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">mysql_secure_installation<\/span><\/p>\n<\/li>\n<li> Install PHP and some common extensions for PHP by running the following command. You may be prompted to press y and enter again.\n<p class=\"cli\"><span style=\"color: #00E000;\">yum install php70u php70u-mcrypt php70u-mbstring php70u-mysqlnd php70u-ioncube-loader php70u-soap php70u-common php70u-tidy php70u-pecl-imagick php70u-pspell php70u-pdo php70u-bcmath php70u-cli php70u-pear php70u-enchant php70u-xml php70u-pspell php70u-pear php70u-enchant php70u-xml php70u-pspell php70u-fpm php-70fpm<\/span><\/p>\n<\/li>\n<li> Once PHP has been installed we need to configure it for NGINX. To do this you will need to open \/etc\/php-fpm.d\/www.conf:<br>\nFind the line that says \u201clisten =\u201d and change the line to look like the entry below.<p><\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">listen = \/var\/run\/php-fpm\/php-fpm.sock<\/span><\/p>\n<p>      Next find the lines \u201clisten.owner\u201d and \u201clisten.group\u201d and change them to match the entry below.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">listen.owner = nginx      listen.group = nginx<\/span><\/p>\n<p>      Finally find the lines with \u201cuser\u201d and \u201cgroup\u201d and change them to match the entry below.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\"> user = nginx      group = nginx<\/span><\/p>\n<p>      Now that we have configured PHP-FPM we can start it by running the command below.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">systemctl start php-fpm<\/span><\/p>\n<\/li>\n<li> We now need to configure NGINX to use PHP to proccess PHP files using PHP-FPM. To do so you will need to open the file \/etc\/nginx. Once opened you will need to find the section that starts with \u201cserver {\u201d and make it match the configuration below\n<pre><span style=\"color: #00E000;\">server {     listen       80;     server_name  domain_name_or_IP;      root   \/usr\/share\/nginx\/html;     index index.htm index.html index.php;      location \/ {         try_files $uri $uri\/ =404;     }     error_page 404 \/404.html;     error_page 500 502 503 504 \/50x.html;     location = \/50x.html {         root \/usr\/share\/nginx\/html;     }      location ~ \\.php$ {         try_files $uri =404;         fastcgi_pass unix:\/var\/run\/php-fpm\/php-fpm.sock;         fastcgi_index index.php;         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;         include fastcgi_params;     } } <\/span>\n<\/pre>\n<\/li>\n<\/ol>\n<p>Once you have made the changes you need to restart NGINX using the command below.<\/p>\n<p class=\"cli\"><span style=\"color: #00E000;\">service nginx restart<\/span><\/p>\n<pre><code>&lt;li&gt; Now we need to test PHP to ensure its working, You can run the following command to place a PHP info page in your document root.\n<\/code><\/pre>\n<p class=\"cli\"><span style=\"color: #00E000;\">echo  \u201c&lt;?php phpinfo();\u201d &gt; \/usr\/share\/nginx\/html\/phpinfo.php<\/span><\/p>\n<p>After running that command browse to https:\/\/yourservers_IP\/phpinfo.php. You should receive a page showing your PHP configuration information.\n<\/p>\n<li> To ensure your services start automatically on reboot we need to enable them in Systemd(The software that manages services by default on CentOS). Run the following commands.\n<p class=\"cli\"><span style=\"color: #00E000;\">systemctl enable mariadb.service<br>\nsystemctl enable nginx<br>\nsystemctl enable php-fpm <\/span><\/p>\n<\/li>\n<p>Congratulations, You should now have a working <strong>LEMP<\/strong> stack.<\/p>\n<div style=\"clear:both;\"><\/div>\n<p><img class=\"std_ss\" style=\"float: right; margin: 15px 15px 15px 15px;\" width=\"200\"><\/p>\n\n\n<p>Learn more from our <a href=\"https:\/\/www.inmotionhosting.com\/support\/product-guides\/cloud-server\/\">Cloud Server Hosting Product Guide<\/a>.<\/p>\n\n\n<div class=\"jumbotron\"><p>Experience full control over your server environment and deploy the best operating and management systems that fit your needs with our reliable <a href=\"https:\/\/www.inmotionhosting.com\/cloud-vps\">Cloud VPS Hosting<\/a>!<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This guide will show you the steps needed to install a basic LEMP stack on your Non-cPanel server running CentOS. All the commands shown will need to be run as root on your server via SSH. Installing LEMP Stack Connect to your server as the root user via SSH. Before installing we need to ensure<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\"> Read More ><\/a><\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4307],"tags":[],"class_list":["post-4148","post","type-post","status-publish","format-standard","hentry","category-ssh"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Installing LEMP-Stack on CentOS7 | InMotion Hosting<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Installing LEMP-Stack on CentOS7 | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"This guide will show you the steps needed to install a basic LEMP stack on your Non-cPanel server running CentOS. All the commands shown will need to be run as root on your server via SSH. Installing LEMP Stack Connect to your server as the root user via SSH. Before installing we need to ensure Read More &gt;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-15T10:55:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-16T19:27:25+00:00\" \/>\n<meta name=\"author\" content=\"Kyle McClammy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kyle McClammy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\"},\"author\":{\"name\":\"Kyle McClammy\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/8c49132ed3eeb8593005b332e002c8b5\"},\"headline\":\"Installing LEMP-Stack on CentOS7\",\"datePublished\":\"2018-06-15T10:55:50+00:00\",\"dateModified\":\"2021-07-16T19:27:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\"},\"wordCount\":663,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"SSH and Root Access\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\",\"name\":\"Installing LEMP-Stack on CentOS7 | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2018-06-15T10:55:50+00:00\",\"dateModified\":\"2021-07-16T19:27:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Installing LEMP-Stack on CentOS7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/8c49132ed3eeb8593005b332e002c8b5\",\"name\":\"Kyle McClammy\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/kylem\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Installing LEMP-Stack on CentOS7 | InMotion Hosting","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/","og_locale":"en_US","og_type":"article","og_title":"Installing LEMP-Stack on CentOS7 | InMotion Hosting","og_description":"This guide will show you the steps needed to install a basic LEMP stack on your Non-cPanel server running CentOS. All the commands shown will need to be run as root on your server via SSH. Installing LEMP Stack Connect to your server as the root user via SSH. Before installing we need to ensure Read More >","og_url":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2018-06-15T10:55:50+00:00","article_modified_time":"2021-07-16T19:27:25+00:00","author":"Kyle McClammy","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Kyle McClammy","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/"},"author":{"name":"Kyle McClammy","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/8c49132ed3eeb8593005b332e002c8b5"},"headline":"Installing LEMP-Stack on CentOS7","datePublished":"2018-06-15T10:55:50+00:00","dateModified":"2021-07-16T19:27:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/"},"wordCount":663,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["SSH and Root Access"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/","url":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/","name":"Installing LEMP-Stack on CentOS7 | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2018-06-15T10:55:50+00:00","dateModified":"2021-07-16T19:27:25+00:00","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/server\/ssh\/installing-lemp-stack-on-centos7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Installing LEMP-Stack on CentOS7"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/8c49132ed3eeb8593005b332e002c8b5","name":"Kyle McClammy","url":"https:\/\/www.inmotionhosting.com\/support\/author\/kylem\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=4148"}],"version-history":[{"count":7,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4148\/revisions"}],"predecessor-version":[{"id":78405,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4148\/revisions\/78405"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=4148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=4148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=4148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}