{"id":6982,"date":"2017-09-12T14:47:24","date_gmt":"2017-09-12T06:47:24","guid":{"rendered":"http:\/\/rmohan.com\/?p=6982"},"modified":"2017-09-12T14:52:31","modified_gmt":"2017-09-12T06:52:31","slug":"lamp-on-centos7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6982","title":{"rendered":"LAMP on CentOS7"},"content":{"rendered":"<p>Many open source p[projects require LAMP with database and database user ready to go. Here we will look at basic commands on CentOS7 to get it up and running quickly.<\/p>\n<p>After CentOS7 installed update all packages<br \/>\nyum update -y<br \/>\nInstall apache web server<br \/>\nyum install httpd<br \/>\nStart service and enable it to start on boot<br \/>\nsystemctl start httpd.service<br \/>\nsystemctl enable httpd.service<br \/>\nInstall MariaDB database server<br \/>\nyum install mariadb-server mariadb<br \/>\nStart mysql services<br \/>\nsystemctl start mariadb<br \/>\nSecure mysql installation<br \/>\nmysql_secure_installation<br \/>\nEnable MariaDB to start on boot<br \/>\nsystemctl enable mariadb.service<br \/>\nInstall PHP with mysql support<br \/>\nyum install php php-mysql<br \/>\nRestart apache web server<br \/>\nsystemctl restart httpd.service<br \/>\nOpen necessary firewall ports for example http<br \/>\nfirewall-cmd &#8211;zone=public &#8211;permanent &#8211;add-service=http<br \/>\nfirewall-cmd &#8211;reload<br \/>\nAnd finally create database and user. See example below.<br \/>\ncreate database mydb;<br \/>\ngrant usage on *.* to mydbuser@localhost identified by &#8216;mypassword&#8217;;<br \/>\ngrant all privileges on mydb.* to user@localhost ;<br \/>\nFLUSH PRIVILEGES;<\/p>\n<p>Open vSwitch installation on CentOS 7.2<br \/>\nOpen vSwitch (OVS) is a production quality, multilayer virtual switch software available for various platforms. The server platforms include x86 based latest Linux distributions e.g. Debian 16 LTS or CentOS 7.2. Popular SDN switch operating system development company Pica8 also bundles the OVS in a custom Ubuntu version for Pronto, Dell, and many other switches.<\/p>\n<p>Below is an effort to provide easy installation instructions for OVS on CentOS 7.2 and also to integrate OVS with the OpenDaylight. Note this blog is updated to use OVS version 2.5.1 (bug fix release for OVS 2.5.0).<\/p>\n<p>Install the requisite packages.<br \/>\n#yum -y install make gcc openssl-devel autoconf automake rpm-build redhat-rpm-config python-devel openssl-devel kernel-devel kernel-debug-devel libtool wget<br \/>\nNecessary steps for building RPM<br \/>\n#mkdir -p ~\/rpmbuild\/SOURCES<br \/>\n#wget http:\/\/openvswitch.org\/releases\/openvswitch-2.8.0.tar.gz<br \/>\n#cp openvswitch-2.8.0.tar.gz ~\/rpmbuild\/SOURCES\/<br \/>\n#tar xfz openvswitch-2.8.0.tar.gz<br \/>\n#sed &#8216;s\/openvswitch-kmod, \/\/g&#8217; openvswitch-2.8.0\/rhel\/openvswitch.spec > openvswitch-2.8.0\/rhel\/openvswitch_no_kmod.spec<br \/>\nBuild the RPM<br \/>\n#rpmbuild -bb &#8211;nocheck ~\/openvswitch-2.8.0\/rhel\/openvswitch_no_kmod.spec<br \/>\nInstall the RPM<br \/>\n#ls -l ~\/rpmbuild\/RPMS\/x86_64\/<br \/>\n#yum localinstall ~\/rpmbuild\/RPMS\/x86_64\/openvswitch-2.8.0-1.x86_64.rpm<br \/>\nStart the OVS service and enable it for the next boot<br \/>\n#systemctl start openvswitch.service<br \/>\n#chkconfig openvswitch on<br \/>\nThis process will install the OVS on the server and start the process. Firewall should be open to accept the incoming TCP connection at port 6633.<\/p>\n<p>Test the OVS Version<br \/>\n#ovs-vsctl -V<\/p>\n<p>Useful OVS commands<br \/>\n#ovs-vsctl show<br \/>\n#ovs-ofctl show br0<\/p>\n<p>Create a new OVS Bridge, add physical ports, connect OVS with ODL controller<br \/>\n#ovs-vsctl add-br ovsbr0<br \/>\n#ovs-vsctl set bridge ovsbr0 protocols=OpenFlow13<br \/>\n#ovs-vsctl list controller<br \/>\n#ovs-vsctl add-port ovsbr0 eth4<br \/>\n#ovs-vsctl add-port ovsbr0 eth8<br \/>\n#ovs-vsctl set-controller ovsbr0 tcp:192.168.1.57:6633<br \/>\n#ovs-vsctl show<\/p>\n<p>First step we will install LAMP<br \/>\nyum -y install mariadb-server mariadb<br \/>\nsystemctl start mariadb.service<br \/>\nsystemctl enable mariadb.service<br \/>\nSecure MariaDB installation<br \/>\nmysql_secure_installation<br \/>\nInstall Apache server<br \/>\nyum -y install httpd<br \/>\nsystemctl start httpd.service<br \/>\nsystemctl enable httpd.service<br \/>\nInstall php with all modules<br \/>\nyum -y install php<br \/>\nyum -y install php-mysql<br \/>\nyum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel<br \/>\nRestart apache<br \/>\nsystemctl restart httpd.service<br \/>\nNow lets install phpMyAdmin<br \/>\nLets add epel repository<br \/>\nrpm -iUvh http:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm<br \/>\nInstall phpMyAdmin<br \/>\nyum install phpMyAdmin<br \/>\nMake sure we allow access to the software<br \/>\nvi \/etc\/httpd\/conf.d\/phpMyAdmin.conf<br \/>\nChange authentication<br \/>\nvi \/etc\/phpMyAdmin\/config.inc.php<\/p>\n<p>[&#8230;]<br \/>\n$cfg[&#8216;Servers&#8217;][$i][&#8216;auth_type&#8217;]     = &#8216;http&#8217;;    \/\/ Authentication method (config, http or cookie based)?<br \/>\n[&#8230;]<\/p>\n<p>Restart Apache<br \/>\nsystemctl restart  httpd.service<br \/>\nNow we setup virtual hosts<\/p>\n<p>mkdir -p \/var\/www\/html\/site1.com\/public_html<br \/>\nmkdir -p \/var\/www\/html\/site2.com\/public_html<\/p>\n<p>useradd webadmin<br \/>\npasswd webadmin<\/p>\n<p>chown -R webadmin:webadmin \/var\/www\/html\/site1\/public_html<br \/>\nchown -R webadmin:webadmin \/var\/www\/html\/site2\/public_html<\/p>\n<p>chmod -R 755 \/var\/www\/html<\/p>\n<p>vi \/etc\/httpd\/conf\/httpd.conf<br \/>\nIncludeOptional sites-enabled\/*.conf<\/p>\n<p>mkdir \/etc\/httpd\/sites-enabled<br \/>\nmkdir \/etc\/httpd\/sites-available<\/p>\n<p>cd sites-available<br \/>\nvi site1.com.conf<\/p>\n<p>    ServerName www.site1.com<br \/>\n    DocumentRoot \/var\/www\/html\/site1\/public_html<br \/>\n    ServerAlias site1.com<br \/>\n    ErrorLog \/var\/www\/html\/site1\/error.log<br \/>\n    CustomLog \/var\/www\/html\/site1\/requests.log combined<\/p>\n<p>vi site2.com.conf<\/p>\n<p>    ServerName www.site2.com<br \/>\n    DocumentRoot \/var\/www\/html\/site2\/public_html<br \/>\n    ServerAlias site2.com<br \/>\n    ErrorLog \/var\/www\/html\/site2\/error.log<br \/>\n    CustomLog \/var\/www\/html\/site2\/requests.log combined<\/p>\n<p>ln -s \/etc\/httpd\/sites-available\/site1.com.conf \/etc\/httpd\/sites-enabled\/site1.com.conf<br \/>\nln -s \/etc\/httpd\/sites-available\/site2.com.conf \/etc\/httpd\/sites-enabled\/site2.com.conf<\/p>\n<p>Make sure proper firewall accept ions are added<\/p>\n<p>firewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=http<br \/>\nfirewall-cmd &#8211;permanent &#8211;zone=public &#8211;add-service=https<br \/>\nfirewall-cmd &#8211;reload<\/p>\n<p>Install OSSEC Host Intrusion Detection Software<br \/>\nyum install mysql-devel postgresql-devel gcc<br \/>\nwget -U ossec https:\/\/bintray.com\/artifact\/download\/ossec\/ossec-hids\/ossec-hids-2.8.3.tar.gz<br \/>\ntar -zxvf ossec-hids-2.8.3.tar.gz<br \/>\ncd ossec-hids-2.8.3 cd ossec-hids-2.8.3<br \/>\n.\/install.sh<br \/>\nChoose local install, provide email and SMTP server for alerts<\/p>\n<p>Install Fail2Ban<br \/>\nyum install fail2ban fail2ban-systemd<br \/>\ncp -pf \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local<br \/>\nExamine configuration file to make sure settings are as you want them<br \/>\nvi \/etc\/fail2ban\/jail.local<br \/>\nAdd ssh jail file<br \/>\nvi \/etc\/fail2ban\/jail.d\/sshd.local<br \/>\n[sshd]<br \/>\nenabled = true<br \/>\nport = ssh<br \/>\n#action = firewallcmd-ipset<br \/>\nlogpath = %(sshd_log)s<br \/>\nmaxretry = 5<br \/>\nbantime = 86400<br \/>\nWith firewalld enabled and running<br \/>\nsystemctl enable fail2ban<br \/>\nsystemctl start fail2ban<br \/>\nTracking logon attempts<br \/>\ncat \/var\/log\/secure | grep &#8216;Failed password&#8217;<br \/>\nCheck banned IP address<br \/>\niptables -L -n<br \/>\nCheck fail2ban status<br \/>\nfail2ban-client status<br \/>\nRemove ban from IP<br \/>\nfail2ban-client set sshd unbanip IPADDRESS<\/p>\n<p>Install nagios to monitor server or vm<br \/>\ncd ~<br \/>\ncurl -L -O http:\/\/nagios-plugins.org\/download\/nagios-plugins-2.1.1.tar.gz<br \/>\ntar xvf nagios-plugins-*.tar.gz<br \/>\ncd nagios-plugins-*<br \/>\n.\/configure &#8211;with-nagios-user=nagios &#8211;with-nagios-group=nagios &#8211;with-openssl<br \/>\nmake<br \/>\nmake install<br \/>\nhtpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<br \/>\nsystemctl start nagios.service<br \/>\nsystemctl restart httpd.service<br \/>\nchkconfig nagios on<\/p>\n<p>If you like to restrict access to Nagios web portion by IP<br \/>\nvi \/etc\/httpd\/conf.d\/nagios.conf<br \/>\nFind and comment the following two lines by adding # symbols in front of them:<br \/>\nOrder allow,deny<br \/>\nAllow from all<br \/>\nThen uncomment the following lines, by deleting the # symbols, and add the IP addresses or ranges (space delimited) that you want to allow to in the<br \/>\nAllow from line:<\/p>\n<p>#  Order deny,allow<br \/>\n#  Deny from all<br \/>\n#  Allow from 127.0.0.1<br \/>\nInstall Clamv virus scanner<br \/>\nyum install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd<\/p>\n<p>cp \/usr\/share\/clamav\/template\/clamd.conf \/etc\/clamd.d\/clamd.conf<br \/>\nsed -i \u2018\/^Example\/d\u2019 \/etc\/clamd.d\/clamd.conf<\/p>\n<p>freshclam<\/p>\n<p>cp \/etc\/freshclam.conf \/etc\/freshclam.conf.bak<br \/>\nsed -i \u2018\/^Example\/d\u2019 \/etc\/freshclam.conf<\/p>\n<p>vi \/usr\/lib\/systemd\/system\/clam-freshclam.service<br \/>\n# Run the freshclam as daemon<br \/>\n[Unit]<br \/>\nDescription = freshclam scanner<br \/>\nAfter = network.target<\/p>\n<p>[Service]<br \/>\nType = forking<br \/>\nExecStart = \/usr\/bin\/freshclam -d -c 4<br \/>\nRestart = on-failure<br \/>\nPrivateTmp = true<\/p>\n<p>[Install]<br \/>\nWantedBy=multi-user.target<\/p>\n<p>systemctl enable clam-freshclam.service<br \/>\nsystemctl start clam-freshclam.service<br \/>\nAdd ssl website<br \/>\nInstall mod_ssl<br \/>\nyum install mod_ssl<br \/>\nCreate certioficate CSR \u2013 Certificate Signing Request<br \/>\nopenssl req -new -newkey rsa:2048 -nodes -keyout rmohan.key -out rmohan.csr<br \/>\nedit \/etc\/httpd\/sites-available and add below.<\/p>\n<p>     SSLEngine On<br \/>\n     SSLCertificateFile \/etc\/pki\/tls\/certs\/rmohan.crt<br \/>\n     SSLCertificateKeyFile \/etc\/pki\/tls\/private\/rmohan.key<br \/>\n     SSLCACertificateFile \/etc\/pki\/tls\/certs\/root-certificate.crt  #root certificate provided by ca-certificates, omit this line<\/p>\n<p>     ServerAdmin info@rmohan.com<br \/>\n     ServerName www.rmohan.com<br \/>\n     DocumentRoot \/var\/www\/html\/rmohan.com\/public_html\/<br \/>\n     ErrorLog \/var\/www\/html\/rmohan.com\/logs\/error.log<br \/>\n     CustomLog \/var\/www\/html\/rmohan.com\/logs\/access.log combined<\/p>\n<p>Finish configuration and setup correct permittions<br \/>\nmkdir \/var\/www\/html\/rmohan.com\/public_html<br \/>\nchown -R webadmin:webadmin \/var\/www\/html\/rmohan.com\/public_html<br \/>\nln -s \/etc\/httpd\/sites-available\/rmohan.com.conf \/ \/etc\/httpd\/sites-enabled\/rmohan.com.conf<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many open source p[projects require LAMP with database and database user ready to go. Here we will look at basic commands on CentOS7 to get it up and running quickly.<\/p>\n<p>After CentOS7 installed update all packages yum update -y Install apache web server yum install httpd Start service and enable it to start on boot [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6982"}],"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=6982"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6982\/revisions"}],"predecessor-version":[{"id":6989,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6982\/revisions\/6989"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6982"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6982"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6982"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}