{"id":4191,"date":"2015-02-06T13:00:57","date_gmt":"2015-02-06T05:00:57","guid":{"rendered":"http:\/\/rmohan.com\/?p=4191"},"modified":"2015-02-06T13:00:57","modified_gmt":"2015-02-06T05:00:57","slug":"how-to-install-lamp-linux-apache-mariadb-php-on-centos-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4191","title":{"rendered":"How to install LAMP (Linux Apache, MariaDB &#038; PHP) on CentOS 7"},"content":{"rendered":"<p>yum install mariadb mariadb-server mysql<\/p>\n<p>INSTALL MARIA DB<\/p>\n<p>MariaDB is the default database server in CentOS 7, so go ahead and install it with yum using the following command:<\/p>\n<p>## yum install mariadb mariadb-server mysql<\/p>\n<p>Once installed, add bind-address = 127.0.0.1 to \/etc\/my.cnf.d\/server.cnf to bind MariaDB to localhost only:<\/p>\n<p>## vim \/etc\/my.cnf.d\/server.cnf<\/p>\n<p>[mysqld]<br \/>\n#log-bin=mysql-bin<br \/>\n#binlog_format=mixed<br \/>\nbind-address = 127.0.0.1<\/p>\n<p>[root@testserver7 my.cnf.d]# systemctl restart mariadb<br \/>\n[root@testserver7 my.cnf.d]# systemctl status mariadb<br \/>\nmariadb.service &#8211; MariaDB database server<br \/>\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/mariadb.service; enabled)<br \/>\n   Active: active (running) since Fri 2015-02-06 09:17:59 SGT; 2s ago<br \/>\n  Process: 9179 ExecStartPost=\/usr\/libexec\/mariadb-wait-ready $MAINPID (code=exited, status=0\/SUCCESS)<br \/>\n  Process: 9150 ExecStartPre=\/usr\/libexec\/mariadb-prepare-db-dir %n (code=exited, status=0\/SUCCESS)<br \/>\n Main PID: 9178 (mysqld_safe)<br \/>\n   CGroup: \/system.slice\/mariadb.service<br \/>\n           ??9178 \/bin\/sh \/usr\/bin\/mysqld_safe &#8211;basedir=\/usr<br \/>\n           ??9348 \/usr\/libexec\/mysqld &#8211;basedir=\/usr &#8211;datadir=\/var\/lib\/mysql &#8211;plugin-dir=\/usr\/lib64\/mysql\/plugin &#8211;log-erro&#8230;<\/p>\n<p>Feb 06 09:17:57 testserver7 systemd[1]: Starting MariaDB database server&#8230;<br \/>\nFeb 06 09:17:57 testserver7 mysqld_safe[9178]: 150206 09:17:57 mysqld_safe Logging to &#8216;\/var\/log\/mariadb\/mariadb.log&#8217;.<br \/>\nFeb 06 09:17:57 testserver7 mysqld_safe[9178]: 150206 09:17:57 mysqld_safe Starting mysqld daemon with databases from \/&#8230;\/mysql<br \/>\nFeb 06 09:17:59 testserver7 systemd[1]: Started MariaDB database server.<br \/>\nHint: Some lines were ellipsized, use -l to show in full.<br \/>\nHint: Some lines were ellipsized, use -l to show in full.<br \/>\n[root@testserver7 my.cnf.d]# systemctl enable mariadb<br \/>\nln -s &#8216;\/usr\/lib\/systemd\/system\/mariadb.service&#8217; &#8216;\/etc\/systemd\/system\/multi-user.target.wants\/mariadb.service&#8217;<br \/>\n[root@testserver7 my.cnf.d]#<br \/>\n[<br \/>\n\/usr\/bin\/mysqladmin -u root password &#8216;test123&#8217;<\/p>\n<p>\/usr\/bin\/mysqladmin -u root -h testserver7  password &#8216;test123&#8242;<\/p>\n<p> update mysql.user set password=PASSWORD(&#8220;test123&#8221;) where User=&#8217;root&#8217;;<\/p>\n<p> Reset root password<br \/>\n [root@testserver7 my.cnf.d]# mysql -u root<br \/>\nWelcome to the MariaDB monitor.  Commands end with ; or \\g.<br \/>\nYour MariaDB connection id is 1<br \/>\nServer version: 5.5.41-MariaDB MariaDB Server<\/p>\n<p>Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.<\/p>\n<p>Type &#8216;help;&#8217; or &#8216;\\h&#8217; for help. Type &#8216;\\c&#8217; to clear the current input statement.<\/p>\n<p>MariaDB [(none)]>   update mysql.user set password=PASSWORD(&#8220;test123&#8221;) where User=&#8217;root&#8217;;<br \/>\nQuery OK, 3 rows affected (0.00 sec)<br \/>\nRows matched: 3  Changed: 3  Warnings: 0<\/p>\n<p>MariaDB [(none)]> flush privileges;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>MariaDB [(none)]> quit<br \/>\nBye<br \/>\n[root@testserver7 my.cnf.d]#<\/p>\n<p>## mysql_secure_installation<\/p>\n<p>Enter current password for root (enter for none): ENTER<br \/>\nSet root password? [Y\/n] Y<br \/>\nRemove anonymous users? [Y\/n] Y<br \/>\nDisallow root login remotely? [Y\/n] Y<br \/>\nRemove test database and access to it? [Y\/n] Y<br \/>\nReload privilege tables now? [Y\/n] Y<\/p>\n<p>root@testserver7 my.cnf.d]# systemctl restart httpd<br \/>\n[root@testserver7 my.cnf.d]# systemctl status httpd<br \/>\nhttpd.service &#8211; The Apache HTTP Server<br \/>\n   Loaded: loaded (\/usr\/lib\/systemd\/system\/httpd.service; enabled)<br \/>\n   Active: active (running) since Fri 2015-02-06 09:47:33 SGT; 17s ago<br \/>\n  Process: 10372 ExecStop=\/bin\/kill -WINCH ${MAINPID} (code=exited, status=0\/SUCCESS)<br \/>\n Main PID: 10377 (httpd)<br \/>\n   Status: &#8220;Total requests: 0; Current requests\/sec: 0; Current traffic:   0 B\/sec&#8221;<br \/>\n   CGroup: \/system.slice\/httpd.service<br \/>\n           ??10377 \/usr\/sbin\/httpd -DFOREGROUND<br \/>\n           ??10379 \/usr\/sbin\/httpd -DFOREGROUND<br \/>\n           ??10380 \/usr\/sbin\/httpd -DFOREGROUND<br \/>\n           ??10381 \/usr\/sbin\/httpd -DFOREGROUND<br \/>\n           ??10382 \/usr\/sbin\/httpd -DFOREGROUND<br \/>\n           ??10383 \/usr\/sbin\/httpd -DFOREGROUND<\/p>\n<p>Feb 06 09:47:28 testserver7 systemd[1]: Starting The Apache HTTP Server&#8230;<br \/>\nFeb 06 09:47:33 testserver7 httpd[10377]: AH00558: httpd: Could not reliably determine the server&#8217;s fully qualified dom&#8230;essage<br \/>\nFeb 06 09:47:33 testserver7 systemd[1]: Started The Apache HTTP Server.<br \/>\nHint: Some lines were ellipsized, use -l to show in full.<br \/>\n[root@testserver7 my.cnf.d]# systemctl enable httpd<\/p>\n<p>\/etc\/httpd\/conf.d<\/p>\n<p>vi harden.conf<\/p>\n<p>TraceEnable off<\/p>\n<p>## Disable Signature<br \/>\nServerSignature Off<\/p>\n<p>## Disable Banner<br \/>\nServerTokens Prod<\/p>\n<p>[root@testserver7 conf.d]# apachectl configtest<br \/>\nAH00558: httpd: Could not reliably determine the server&#8217;s fully qualified domain name, using 192.168.1.3. Set the &#8216;ServerName&#8217; directive globally to suppress this message<br \/>\nSyntax OK<br \/>\n[root@testserver7 conf.d]#<\/p>\n<p>K, let\u2019s continue with PHP configuration. Edit \/etc\/php.ini and set the following:<\/p>\n<p>## vim \/etc\/php.ini<\/p>\n<p>date.timezone = America\/New_York<br \/>\nmemory_limit = 64M<br \/>\nexpose_php = Off<\/p>\n<p>restart Apache using systemctl for the changes to take effect:<\/p>\n<p>## systemctl restart httpd<br \/>\n## systemctl status httpd<\/p>\n<p>Test if PHP module is loaded in Apache using:<\/p>\n<p>## httpd -M | grep php<\/p>\n<p>also<\/p>\n<p>## php -v<\/p>\n<p>You can create a test info.php script too using the following command:<\/p>\n<p>## echo -e &#8220;<?php\\n\\tphpinfo();\" > \/var\/www\/html\/info.php<\/p>\n<p>and access it with the following command:<\/p>\n<p>## curl -I $(curl -s icanhazip.com)\/info.php<\/p>\n<p>SET-UP APACHE VHOSTS<\/p>\n<p>Now, you would have to set-up Apache Virtual Host Directives, to be able to host multiple domains, even SSL powered ones using one IP address. So, create \/etc\/httpd\/conf.d\/vhosts.conf and add the following:<\/p>\n<p>## cat \/etc\/httpd\/conf.d\/vhosts.conf<\/p>\n<p># Load my vhosts<br \/>\nIncludeOptional vhosts.d\/*.conf<\/p>\n<p>This tells Apache, to load the configuration files ending with .conf which reside in \/etc\/httpd\/vhosts.d. As you can guess, this is the place where we put our Virtual Hosts, so let\u2019s set-up one for domain1.com and another for domain2.net<br \/>\nVHOST for domain1.com<\/p>\n<p>## cat \/etc\/httpd\/vhosts.d\/domain1.com.conf<\/p>\n<p><VirtualHost YOUR_SERVER_IP:80><br \/>\n    ServerAdmin webmaster@domain1.com<br \/>\n    DocumentRoot &#8220;\/var\/www\/html\/domain1.com&#8221;<br \/>\n    ServerName domain1.com<br \/>\n    ServerAlias www.domain1.com<br \/>\n    ErrorLog &#8220;\/var\/log\/httpd\/domain1.com-error_log&#8221;<br \/>\n    CustomLog &#8220;\/var\/log\/httpd\/domain1.com-access_log&#8221; combined<\/p>\n<p>    <Directory \"\/var\/www\/html\/domain1.com\/\"><br \/>\n        DirectoryIndex index.html index.php<br \/>\n        Options FollowSymLinks<br \/>\n        AllowOverride All<br \/>\n        Require all granted<br \/>\n    <\/Directory><br \/>\n<\/VirtualHost><\/p>\n<p>VHOST for domain2.net<\/p>\n<p>## cat \/etc\/httpd\/vhosts.d\/domain2.net.conf<\/p>\n<p><VirtualHost YOUR_SERVER_IP:80><br \/>\n    ServerAdmin webmaster@domain2.net<br \/>\n    DocumentRoot &#8220;\/var\/www\/html\/domain2.net&#8221;<br \/>\n    ServerName domain2.net<br \/>\n    ServerAlias www.domain2.net<br \/>\n    ErrorLog &#8220;\/var\/log\/httpd\/domain2.net-error_log&#8221;<br \/>\n    CustomLog &#8220;\/var\/log\/httpd\/domain2.net-access_log&#8221; combined<\/p>\n<p>    <Directory \"\/var\/www\/html\/domain2.net\/\"><br \/>\n        DirectoryIndex index.html index.php<br \/>\n        Options FollowSymLinks<br \/>\n        AllowOverride All<br \/>\n        Require all granted<br \/>\n    <\/Directory><br \/>\n<\/VirtualHost><\/p>\n<p>Finally, restart Apache for the changes to take effect:<\/p>\n<p>## apachectl configtest<br \/>\n## systemctl restart httpd<br \/>\n## systemctl status httpd<\/p>\n","protected":false},"excerpt":{"rendered":"<p>yum install mariadb mariadb-server mysql<\/p>\n<p>INSTALL MARIA DB<\/p>\n<p>MariaDB is the default database server in CentOS 7, so go ahead and install it with yum using the following command:<\/p>\n<p>## yum install mariadb mariadb-server mysql<\/p>\n<p>Once installed, add bind-address = 127.0.0.1 to \/etc\/my.cnf.d\/server.cnf to bind MariaDB to localhost only:<\/p>\n<p>## vim \/etc\/my.cnf.d\/server.cnf<\/p>\n<p>[mysqld] #log-bin=mysql-bin #binlog_format=mixed [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4191"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4191"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4191\/revisions"}],"predecessor-version":[{"id":4192,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4191\/revisions\/4192"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}