{"id":5660,"date":"2015-02-05T23:25:55","date_gmt":"2015-02-05T15:25:55","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5660"},"modified":"2023-06-26T20:08:48","modified_gmt":"2023-06-26T20:08:48","slug":"how-to-install-lamp-on-centos-7","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-install-lamp-on-centos-7\/","title":{"rendered":"How to Install LAMP on CentOS 7 \/ RHEL 7"},"content":{"rendered":"<p>The LAMP stack, an acronym for Linux, Apache, MySQL\/MariaDB, and PHP, is a popular open-source software group that allows you to run a web server and host dynamic websites.<\/p>\n<p>In this guide, we will walk you through the process of installing the LAMP stack on CentOS 7, RHEL 7, or Oracle Linux 7. This tutorial is designed to be simple and easy to follow, even for beginners.<\/p>\n<p>By following these steps, you will be able to set up a web server and database server on your Linux operating system.<\/p>\n<h2>Step-by-Step Guide to Install LAMP on CentOS 7 \/ RHEL 7 \/ Oracle Linux 7<\/h2>\n<h3>Step 1: Install Apache Web Server, MariaDB Database, and PHP Packages<\/h3>\n<p>To install the web server, database, and PHP packages, you need to run the following command:<\/p>\n<pre>\r\nsudo yum install mariadb mariadb-server httpd php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap -y\r\n<\/pre>\n<h3>Step 2: Start Apache Web Server and MariaDB Database<\/h3>\n<p>After the installation, start the Apache web server and MariaDB database and set them to auto-start at boot with the following commands:<\/p>\n<pre>\r\nsudo systemctl start httpd.service\r\nsudo systemctl enable httpd.service\r\nsudo systemctl start mariadb\r\nsudo systemctl enable mariadb.service\r\n<\/pre>\n<h3>Step 3: Configure MariaDB Settings<\/h3>\n<p>To secure your MariaDB installation, run the following command and follow the prompts:<\/p>\n<pre>\r\nsudo mysql_secure_installation\r\n<\/pre>\n<p>This script will guide you through setting the root password, removing anonymous users, disallowing root login remotely, removing the test database, and reloading the privilege tables.<\/p>\n<pre>[root@centos7 ~]# sudo mysql_secure_installation\r\n\/usr\/bin\/mysql_secure_installation: line 379: find_mysql_client: command not found\r\n\r\nNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB\r\n      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!\r\n\r\nIn order to log into MariaDB to secure it, we'll need the current\r\npassword for the root user.  If you've just installed MariaDB, and\r\nyou haven't set the root password yet, the password will be blank,\r\nso you should just press enter here.\r\n\r\nEnter current password for root (enter for none):\r\nOK, successfully used password, moving on...\r\n\r\nSetting the root password ensures that nobody can log into the MariaDB\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 MariaDB installation has an anonymous user, allowing anyone\r\nto log into MariaDB without having to have a user account created for\r\nthem.  This is intended only for testing, and to make the installation\r\ngo a bit smoother.  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'.  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, MariaDB comes with a database named 'test' that anyone can\r\naccess.  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!  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\nAll done!  If you've completed all of the above steps, your MariaDB\r\ninstallation should now be secure.\r\n\r\nThanks for using MariaDB!\r\n<\/pre>\n<h3>Step 4: Access Your Server<\/h3>\n<p>You can now access your server using your IP address in the format http:\/\/IPaddress. Before proceeding to configure the virtual host, follow the instructions in the welcome.conf file:<\/p>\n<pre>\r\nvi \/etc\/httpd\/conf.d\/welcome.conf\r\n<\/pre>\n<h3>Step 5: Configure Apache Virtual Host<\/h3>\n<p>To configure the Apache Virtual Host, follow these steps:<\/p>\n<p>a. Create the DocumentRoot directory for your new domain:<\/p>\n<pre>\r\nmkdir -p \/var\/www\/html\/yourdomain\r\n<\/pre>\n<p>b. Create a vhost.conf file to place the Name-based virtual host. For example, if the default domain is centos7.yourdomain.local and you want to add a new virtual host www.yourdomain.local, which points at the same IP address, you would do the following:<\/p>\n<pre>\r\nvi \/etc\/httpd\/conf.d\/vhost.conf\r\n<\/pre>\n<p>Add the following lines to the file. Please note that \u201cNameVirtualHost *:80\u201d is no longer valid in Apache 2.4.x:<\/p>\n<pre>\r\n&lt;VirtualHost *:80&gt;\r\n DocumentRoot \/var\/www\/html\r\n ServerName centos7.yourdomain.local\r\n&lt;\/VirtualHost&gt;\r\n\r\n# for virtual domain\r\n&lt;VirtualHost *:80&gt;\r\n DocumentRoot \/var\/www\/html\/yourdomain\r\n ServerName www.yourdomain.local\r\n ServerAdmin webmaster@yourdomain.local\r\n ErrorLog logs\/www.yourdomain.local-error_log\r\n CustomLog logs\/www.yourdomain.local-access_log combined\r\n&lt;\/VirtualHost&gt;\r\n<\/pre>\n<h3>Step 6: Debug Apache Configuration<\/h3>\n<p>To debug your Apache configuration, use the following command:<\/p>\n<pre>\r\nhttpd -S\r\n<\/pre>\n<p>This will display the VirtualHost configuration, ServerRoot, Main DocumentRoot, Main ErrorLog, and other server details.<\/p>\n<pre>\r\nVirtualHost configuration:\r\ndefault server centos7.webhostinggeeks.local (\/etc\/httpd\/conf.d\/vhost.conf:2)\r\nport 80 namevhost centos7.webhostinggeeks.local (\/etc\/httpd\/conf.d\/vhost.conf:2)\r\nport 80 namevhost centos7.webhostinggeeks.local (\/etc\/httpd\/conf.d\/vhost.conf:2)\r\nport 80 namevhost www.webhostinggeeks.local (\/etc\/httpd\/conf.d\/vhost.conf:7)\r\nport 80 namevhost www.webhostinggeeks.local (\/etc\/httpd\/conf.d\/vhost.conf:7)\r\nServerRoot: \"\/etc\/httpd\"\r\nMain DocumentRoot: \"\/var\/www\/html\"\r\nMain ErrorLog: \"\/etc\/httpd\/logs\/error_log\"\r\nMutex proxy: using_defaults\r\nMutex authn-socache: using_defaults\r\nMutex default: dir=\"\/run\/httpd\/\" mechanism=default\r\nMutex mpm-accept: using_defaults\r\nMutex authdigest-opaque: using_defaults\r\nMutex proxy-balancer-shm: using_defaults\r\nMutex rewrite-map: using_defaults\r\nMutex authdigest-client: using_defaults\r\nPidFile: \"\/run\/httpd\/httpd.pid\"\r\nDefine: DUMP_VHOSTS\r\nDefine: DUMP_RUN_CFG\r\nUser: name=\"apache\" id=48\r\nGroup: name=\"apache\" id=48\r\n<\/pre>\n<h3>Step 7: Get More Information About Apache<\/h3>\n<p>To get more information about your Apache installation, use the following command:<\/p>\n<pre>\r\nhttpd -V\r\n<\/pre>\n<p>This will display the server version, build date, module magic number, server loaded, compiled using, architecture, server MPM, and other server details.<\/p>\n<pre>\r\nServer version: Apache\/2.4.6 (CentOS)\r\nServer built:   Jan 12 2015 13:22:31\r\nServer's Module Magic Number: 20120211:23\r\nServer loaded:  APR 1.4.8, APR-UTIL 1.5.2\r\nCompiled using: APR 1.4.8, APR-UTIL 1.5.2\r\nArchitecture:   64-bit\r\nServer MPM:     prefork\r\n  threaded:     no\r\n    forked:     yes (variable process count)\r\nServer compiled with....\r\n -D APR_HAS_SENDFILE\r\n -D APR_HAS_MMAP\r\n -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)\r\n -D APR_USE_SYSVSEM_SERIALIZE\r\n -D APR_USE_PTHREAD_SERIALIZE\r\n -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT\r\n -D APR_HAS_OTHER_CHILD\r\n -D AP_HAVE_RELIABLE_PIPED_LOGS\r\n -D DYNAMIC_MODULE_LIMIT=256\r\n -D HTTPD_ROOT=\"\/etc\/httpd\"\r\n -D SUEXEC_BIN=\"\/usr\/sbin\/suexec\"\r\n -D DEFAULT_PIDLOG=\"\/run\/httpd\/httpd.pid\"\r\n -D DEFAULT_SCOREBOARD=\"logs\/apache_runtime_status\"\r\n -D DEFAULT_ERRORLOG=\"logs\/error_log\"\r\n -D AP_TYPES_CONFIG_FILE=\"conf\/mime.types\"\r\n -D SERVER_CONFIG_FILE=\"conf\/httpd.conf\"\r\n<\/pre>\n<h3>Step 8: Check PHP Version<\/h3>\n<p>Finally, you can check your PHP version with the following command:<\/p>\n<pre>\r\nphp -v\r\n<\/pre>\n<p>This will display the PHP version, build date, copyright information, and Zend Engine version.<\/p>\n<pre>\r\nPHP 5.4.16 (cli) (built: Oct 31 2014 12:59:36)\r\nCopyright (c) 1997-2013 The PHP Group\r\nZend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies\r\n<\/pre>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">sudo yum install mariadb mariadb-server httpd php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap -y<\/span> \u2013 Installs Apache web server, MariaDB database, and PHP packages<\/li>\n<li><span class=\"fw-bold\">sudo systemctl start httpd.service<\/span> \u2013 Starts Apache web server<\/li>\n<li><span class=\"fw-bold\">sudo systemctl enable httpd.service<\/span> \u2013 Sets Apache web server to auto-start at boot<\/li>\n<li><span class=\"fw-bold\">sudo systemctl start mariadb<\/span> \u2013 Starts MariaDB database<\/li>\n<li><span class=\"fw-bold\">sudo systemctl enable mariadb.service<\/span> \u2013 Sets MariaDB database to auto-start at boot<\/li>\n<li><span class=\"fw-bold\">sudo mysql_secure_installation<\/span> \u2013 Runs the script to secure MariaDB installation<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/httpd\/conf.d\/welcome.conf<\/span> \u2013 Opens the welcome.conf file for editing<\/li>\n<li><span class=\"fw-bold\">mkdir -p \/var\/www\/html\/yourdomain<\/span> \u2013 Creates the DocumentRoot directory for your new domain<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/httpd\/conf.d\/vhost.conf<\/span> \u2013 Opens the vhost.conf file for editing<\/li>\n<li><span class=\"fw-bold\">httpd -S<\/span> \u2013 Debugs Apache configuration<\/li>\n<li><span class=\"fw-bold\">httpd -V<\/span> \u2013 Displays more information about Apache<\/li>\n<li><span class=\"fw-bold\">php -v<\/span> \u2013 Checks PHP version<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>In this guide, we have walked you through the process of installing the LAMP stack on CentOS 7, RHEL 7, or Oracle Linux 7. This process involves installing the Apache web server, MariaDB database, and PHP packages, starting and enabling the services, securing your MariaDB installation, and configuring your Apache Virtual Host. By following these steps, you can set up a web server and database server on your Linux operating system and host dynamic websites and web applications.<\/p>\n<p>Remember, it&#8217;s crucial to secure your MariaDB installation to protect your data from unauthorized access. Also, configuring your Apache Virtual Host correctly is essential for hosting multiple websites on a single server.<\/p>\n<p>We hope this guide has provided you with the essential guidance and insights needed to install the LAMP stack on CentOS 7, RHEL 7, or Oracle Linux 7. For more in-depth information on web servers and hosting, you can refer to our articles on the <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a> web servers, as well as the different types of web hosting such as <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS server<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud hosting<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared hosting<\/a>.<\/p>\n<p>Remember, the journey to becoming a proficient webmaster or website administrator is a continuous learning process. Keep exploring, learning, and implementing.<\/p>\n<h2>FAQ Section<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the LAMP stack?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The LAMP stack is an acronym for a set of open-source software that is typically installed together to enable a server to host dynamic websites and web applications. It stands for Linux (operating system), Apache (web server), MySQL or MariaDB (database server), and PHP (programming language).<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why is it important to secure MariaDB installation?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Securing your MariaDB installation is crucial to protect your data from unauthorized access. The secure installation script helps you enforce a password for the root user, remove anonymous users, disallow root login remotely, and remove the test database, making your database server more secure.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the purpose of the DocumentRoot directory in Apache?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The DocumentRoot directory is the directory out of which Apache will serve your domain&#8217;s files. When a visitor requests a file from your website, Apache will append the request to the path of your DocumentRoot to find the file.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is a virtual host in Apache?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">A virtual host is a feature of Apache that allows a single server to host multiple websites. You can have different settings for each site and they can have their own domain name and IP address, or share the same IP address while having different domain names.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How can I check the PHP version installed on my server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">You can check the PHP version installed on your server by running the command &#8216;php -v&#8217; in the terminal. This will display the PHP version, build date, copyright information, and Zend Engine version.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>The LAMP stack, an acronym for Linux, Apache, MySQL\/MariaDB, and PHP, is a popular open-source software group that allows you to run a web server and host dynamic websites. In&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6193,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055],"tags":[1199,1258,1531,1565,1585,1646],"class_list":["post-5660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","tag-apache","tag-centos-7","tag-lamp","tag-mariadb","tag-mysql","tag-php"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=5660"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5660\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6193"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}