Prerequisites
yum is located in /etc/yum.repos.d/
files have .repo extension to be recognized by YUM
$ sudo yum update
$ sudo systemctl status firewalld
$ sudo systemctl start firewalld
$ sudo systemctl enable firewalld
$ sudo systemctl stop firewalld
add service or custom port to to exclude from firewall
$ sudo firewall-cmd –permanent –add-service=http
$ sudo firewall-cmd –permanent –add-service=https
$ sudo firewall-cmd –permanent –add-service=mysql
$ sudo firewall-cmd –permanent –add-service=ntp
$ sudo firewall-cmd –permanent –add-port=8080/tcp
$ sudo firewall-cmd –permanent –add-port=4444/tcp
$ sudo firewall-cmd –permanent –add-port=4567/tcp
$ sudo firewall-cmd –permanent –add-port=4568/tcp
$ sudo firewall-cmd –permanent –add-port=139/tcp
$ sudo firewall-cmd –permanent –add-port=445/tcp
$ sudo firewall-cmd –reload
$ sudo systemctl restart firewalld.service
$ sudo iptables -L
4444, 45467, 4568 is for percona (if you need any), 139, 445 is for samba, 8080 is for https
i.e. test mysql access from remote machine (do this after mysql installation)
$ sudo mysql -h 10.0.0.71 -u msen -p
IP
Let’s assume our local ip is: 10.10.0.71
To learn hostname, get local ip, get public ip, get public ip in details
$ hostname
$ ip addr show
$ ip addr show eth0
$ ip addr show eth0 | grep inet | awk ‘{ print $2; }’ | sed ‘s/\/.*$//‘
OTHER
print kernel release, print kernel name
$ uname -r
3.10.0-123.el7.x86_64
$ uname -s
Linux
SETUP MARIADB REPO
select your OS to get the latest MariaDB repo
https://downloads.mariadb.org/mariadb/repositories
you can rename a similar name to MariaDB
$ sudo vi /etc/yum.repos.d/MariaDB.repo
copy paste this to MariaDB.repo:
# MariaDB 10.0 CentOS repository list – created 2015-07-09 14:56 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
finally update yum
$ sudo yum update
NTP (skip this if you don’t need to sync servers)
install ntp (network time protocol) server to synchronize time
$ sudo yum install ntp
first go to official http://www.pool.ntp.org/en/
choose your Continent area where the server physically is located, then search for your Country location
For United Sates:
server 0.us.pool.ntp.org server 1.us.pool.ntp.org server 2.us.pool.ntp.org server 3.us.pool.ntp.org
go to ntp config file
$ sudo vi /etc/ntp.conf
only local network can synchronize time with this server, edit like this
restrict 10.10.0.1 mask 255.255.0.0 nomodify notrap
Uncomment initials:
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
copy new United States to config and start
$ sudo systemctl start ntpdate
$ sudo systemctl enable ntpdate
$ sudo systemctl status ntpdate
run this
$ sudo ntpdate us.pool.ntp.org
SERVICES
if you need to check out all the services
$ sudo systemctl list-units –type=service
or you can search a specific service
$ sudo systemctl list-units –type=service | grep at\..*service
So we are ready now to install LAMP on Centos 7
1- Install Apache
Install Apache Web Server
to start, enable, check status, restart gracefully, restart and see the version of apache
$ sudo yum install httpd
$ sudo systemctl start httpd.service
$ sudo systemctl enable httpd.service
$ sudo systemctl status httpd.service
$ sudo apachectl graceful
$ sudo systemctl restart httpd.service
$ httpd -v
Apache Config
Setup Apache config, add ServerName followed by ip:80
$ sudo vi /etc/httpd/conf/httpd.conf
ServerName 10.10.0.71:80
to test apache configuration before restarting
$ sudo apachectl configtest
check out apache web with your local or public ip
2- Install MariaDB (MySQL)
Remove if existing 5.5 MariaDB
remove preversion of mariadb, clean up the repository cache, install, start, enable, run security script, check status and upgrade if necessary
$ sudo yum remove mariadb-server mariadb-libs
$ yum clean all
$ sudo yum install MariaDB-server MariaDB-client
$ sudo systemctl start mysql
($ sudo /etc/init.d/mysql start)
$ sudo systemctl enable mysql
$ sudo mysql_secure_installation
$ sudo systemctl status mysql
$ sudo mysql_upgrade -u root -p
login database
$ sudo mysql -u root -p
mysql>show databases;
mysql>exit;
main config file
$ sudo vi /etc/my.cnf
if it’s not there ask mysqld where it looks for its config
$ /usr/libexec/mysqld –help –verbose
3- Install PHP
Install
$ sudo yum install php php-mysql
search optional php packages, run almost all packages, you can also get info of a certain package i.e php-mysql
$ sudo yum search php-
$ sudo yum install php-gd php-pear php-mbstring php-pgsql php-fmp php-ldap php-devel php-pspell php-intl php-xml php-xmlrpc php-soap php-bcmath php-snmp php-embedded php-pecl-memcache php-odbc php-curl
$ sudo yum info php-mysql
test php
$ sudo vi /var/www/html/info.php
write this
<?php phpinfo(); ?>
restart apache and remove info.php later if in prod
$ sudo systemctl restart httpd.service
$ sudo rm /var/www/html/info.php
to change max file upload size
$ sudo vi /etc/php.ini
upload_max_filesize = 100M
test database from php
$ sudo vi /var/www/html/dbtest.php
copy paste this:
<?php $con = mysql_connect("localhost","root","YourPassword"); if (!$con){ die('Could not connect: ' . mysql_error()); }else{ echo "Congrats! connection established successfully"; } mysql_close($con); ?>
4- Install PhpMyAdmin
To install phpMyAdmin easily on CentOS 7, first install extra packages for enterprise linux (epel), then install phpMyAdmin
$ sudo yum install epel-release
$ sudo yum install phpMyAdmin
edit conf file
$ sudo vi /etc/httpd/conf.d/phpMyAdmin.conf
to access only from certain ip
put Require ip 10.10.0.71 under each Require ip 127.0.0.1
or disable first block and add this
<Directory /usr/share/phpMyAdmin/> Options none AllowOverride Limit Require all granted </Directory>
finally restart apache
$ sudo systemctl restart httpd.service
Now check out PhpMyAdmin
http://10.10.0.71/phpmyadmin