{"id":3092,"date":"2016-10-07T16:24:26","date_gmt":"2016-10-07T20:24:26","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=3092"},"modified":"2017-04-19T15:57:04","modified_gmt":"2017-04-19T19:57:04","slug":"setup-lamp-centos-7","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/","title":{"rendered":"How to Setup a Basic LAMP Stack on CentOS 7"},"content":{"rendered":"<p>The Linux, Apache, MySQL and PHP (LAMP) stack is a versatile application environment. Resource use and configuration is minimal, making it a prime candidate for commodity hosting environments. Deployment is easy, and ranges from making simple in-place edits to full virtualization and containerization. Developers are familiar with LAMP, and it is simple to gain and acquire talent to build and launch LAMP-based applications and sites. This guide will deploy a secure and capable LAMP stack on the CentOS 7 operating system.<\/p>\n<h2>Getting Started<\/h2>\n<p>Before you begin, make sure you have the following:<br \/>\n\u2022 1 server (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Server<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Server<\/a>) running a fresh installation of CentOS 7<\/p>\n<p>At this guide&#8217;s conclusion, this server will be capable of hosting one or more LAMP-based sites.<\/p>\n<h2>Tutorial<\/h2>\n<p>Let&#8217;s go. Start by updating all the installed packages on your server. This will apply all current bugfixes and security patches. When complete, reboot so the new server environment is active. Perform this step regularly to keep your system updated and secure.<\/p>\n<p><code>yum update -y &amp;&amp; shutdown -r now<\/code><\/p>\n<p>We&#8217;ll begin by installing the Apache web server. Apache will both serve up your content and interpret PHP scripts. This is easier to reason about than other solutions, which split PHP execution into separate processes.<\/p>\n<p><code>yum install httpd<\/code><\/p>\n<p>Now we start the Apache server.<\/p>\n<p><code>systemctl start httpd.service<\/code><\/p>\n<p>We must also enable it to start on boot, otherwise it will not launch automatically when the system restarts.<\/p>\n<p><code>systemctl enable httpd.service<\/code><\/p>\n<p>Next we&#8217;ll install the database. Instead of MySQL, we&#8217;ll use MariaDB. MariaDB is a drop-in MySQL replacement that is backwards-compatible with MySQL and all of its tooling. It includes a number of additional storage engines and scalability features that make it a better fit for large-scale database use.<\/p>\n<p>Start by installing the mariadb package.<\/p>\n<p><code>yum install mariadb-server mariadb<\/code><\/p>\n<p>Again, we&#8217;ll start the server itself.<\/p>\n<p><code>systemctl start mariadb<\/code><\/p>\n<p>We now need to set the MySQL root password, which is needed for administering databases and permissions. When asked for your current root password, simply press enter. Keep this password in a secure place, as you&#8217;ll need it whenever adding or modifying databases.<\/p>\n<p><code>mysql_secure_installation<\/code><\/p>\n<p><code class=\"gris\">Set root password? [Y\/n]<br \/>\nNew password:<br \/>\nRe-enter new password:<br \/>\nPassword updated successfully!<br \/>\nReloading privilege tables..<br \/>\n... Success!<br \/>\nBy default, a MariaDB installation has an anonymous user, allowing anyone<br \/>\nto log into MariaDB without having to have a user account created for<br \/>\nthem. This is intended only for testing, and to make the installation<br \/>\ngo a bit smoother. You should remove them before moving into a<br \/>\nproduction environment.<br \/>\nRemove anonymous users? [Y\/n] y<br \/>\n... Success!<br \/>\nNormally, root should only be allowed to connect from 'localhost'. This<br \/>\nensures that someone cannot guess at the root password from the network.<br \/>\nDisallow root login remotely? [Y\/n] y<br \/>\n... Success!<br \/>\nBy default, MariaDB comes with a database named 'test' that anyone can<br \/>\naccess. This is also intended only for testing, and should be removed<br \/>\nbefore moving into a production environment.<br \/>\nRemove test database and access to it? [Y\/n] y<br \/>\n- Dropping test database...<br \/>\n... Success!<br \/>\n- Removing privileges on test database...<br \/>\n... Success!<br \/>\nReloading the privilege tables will ensure that all changes made so far<br \/>\nwill take effect immediately.<br \/>\nReload privilege tables now? [Y\/n] y<br \/>\n... Success!<br \/>\nCleaning up...<br \/>\nAll done! If you've completed all of the above steps, your MariaDB<br \/>\ninstallation should now be secure.<br \/>\nThanks for using MariaDB!<\/code><\/p>\n<p>You can now enable MariaDB to start on boot.<\/p>\n<p><code>systemctl enable mariadb.service<\/code><\/p>\n<p>Next we install the PHP runtime. We&#8217;ll begin by installing the base package needed by all PHP scripts.<\/p>\n<p><code>yum install php php-mysql<\/code><\/p>\n<p>With PHP installed, Apache must be restarted so it integrates with the newly-installed runtime.<\/p>\n<p><code>systemctl restart httpd.service<\/code><\/p>\n<p>PHP is an incredibly modular language. Chances are high that you&#8217;ll need a number of extensions to deploy or develop PHP apps. Many of these modules are packaged for CentOS. Here we show how to use Yum to find and install the php-gd module. Use this for any modules your PHP site requires.<\/p>\n<p><code>yum search php-<\/code><br \/>\n<code class=\"gris\">php-bcmath.x86_64 : A module for PHP applications for using the bcmath library<br \/>\nphp-cli.x86_64 : Command-line interface for PHP<br \/>\nphp-common.x86_64 : Common files for PHP<br \/>\nphp-dba.x86_64 : A database abstraction layer module for PHP applications<br \/>\nphp-devel.x86_64 : Files needed for building PHP extensions<br \/>\nphp-embedded.x86_64 : PHP library for embedding in applications<br \/>\nphp-enchant.x86_64 : Enchant spelling extension for PHP applications<br \/>\nphp-fpm.x86_64 : PHP FastCGI Process Manager<br \/>\nphp-gd.x86_64 : A module for PHP applications for using the gd graphics library<br \/>\nphp-intl.x86_64 : Internationalization extension for PHP applications<br \/>\nphp-ldap.x86_64 : A module for PHP applications that use LDAP<br \/>\nphp-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling<br \/>\nphp-mysql.x86_64 : A module for PHP applications that use MySQL databases<br \/>\n......<\/code><\/p>\n<p><code>yum install php-gd -y<\/code><\/p>\n<p>We&#8217;re almost done. Let&#8217;s test the installation to ensure everything is working.<\/p>\n<p><code>cd \/var\/www\/html<\/code><\/p>\n<p>In CentOS, the document root directory is \/var\/www\/html. All of your PHP scripts must be located here by default in order to be run by Apache.<\/p>\n<p>To test, we&#8217;ll create a PHP info file at index.php. This will use a simple function call to display lots of information about your PHP environment. More fundamentally, it will ensure that Apache is executing PHP scripts. The file should be called index.php.<\/p>\n<p><code>nano index.php<\/code><\/p>\n<p><code>&lt;?php<br \/>\nphpinfo();<br \/>\n?&gt;<\/code><\/p>\n<p>To test your environment, access your server at http:\/\/your_ip. If that doesn&#8217;t work, try http:\/\/your_ip\/index.php. If all goes well, you&#8217;ll see lots of PHP diagnostic details about the environment and loaded modules.<\/p>\n<h2>Conclusion<\/h2>\n<p>You now have a flexible environment into which you can deploy any number of PHP sites. Simply upload a PHP application, follow its installation instructions, and easily run blogs, wikis or other powerful tools and services. If you found this article helpful, feel free to share it with your friends and let us know in the comments below! <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>The Linux, Apache, MySQL and PHP (LAMP) stack is a versatile application environment. Resource use and configuration is minimal, making it a prime candidate for commodity hosting environments. Deployment is easy, and ranges from making simple in-place edits to full virtualization and containerization. Developers are familiar with LAMP, and it is simple to gain and<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-3092","post","type-post","status-publish","format-standard","hentry","category-web-hosting","operating_system-centos-7"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Setup a Basic LAMP Stack on CentOS 7 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will walk you through the setup of a basic LAMP (Linux, Apache, MySQL and PHP) on your CentOS 7 server. Read now !\" \/>\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.globo.tech\/learning-center\/setup-lamp-centos-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Setup a Basic LAMP Stack on CentOS 7 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will walk you through the setup of a basic LAMP (Linux, Apache, MySQL and PHP) on your CentOS 7 server. Read now !\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-07T20:24:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-19T19:57:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/\",\"name\":\"How to Setup a Basic LAMP Stack on CentOS 7 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-10-07T20:24:26+00:00\",\"dateModified\":\"2017-04-19T19:57:04+00:00\",\"author\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will walk you through the setup of a basic LAMP (Linux, Apache, MySQL and PHP) on your CentOS 7 server. Read now !\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.globo.tech\/learning-center\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Setup a Basic LAMP Stack on CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\/\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Setup a Basic LAMP Stack on CentOS 7 - Globo.Tech","description":"This tutorial will walk you through the setup of a basic LAMP (Linux, Apache, MySQL and PHP) on your CentOS 7 server. Read now !","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.globo.tech\/learning-center\/setup-lamp-centos-7\/","og_locale":"en_US","og_type":"article","og_title":"How to Setup a Basic LAMP Stack on CentOS 7 - Globo.Tech","og_description":"This tutorial will walk you through the setup of a basic LAMP (Linux, Apache, MySQL and PHP) on your CentOS 7 server. Read now !","og_url":"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/","og_site_name":"Globo.Tech","article_published_time":"2016-10-07T20:24:26+00:00","article_modified_time":"2017-04-19T19:57:04+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/","url":"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/","name":"How to Setup a Basic LAMP Stack on CentOS 7 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-10-07T20:24:26+00:00","dateModified":"2017-04-19T19:57:04+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will walk you through the setup of a basic LAMP (Linux, Apache, MySQL and PHP) on your CentOS 7 server. Read now !","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/setup-lamp-centos-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to Setup a Basic LAMP Stack on CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=3092"}],"version-history":[{"count":1,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3092\/revisions"}],"predecessor-version":[{"id":3094,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/3092\/revisions\/3094"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=3092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=3092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=3092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}