April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Categories

April 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

How to install LAMP (Linux Apache, MariaDB & PHP) on CentOS 7

yum install mariadb mariadb-server mysql

INSTALL MARIA DB

MariaDB is the default database server in CentOS 7, so go ahead and install it with yum using the following command:

## yum install mariadb mariadb-server mysql

Once installed, add bind-address = 127.0.0.1 to /etc/my.cnf.d/server.cnf to bind MariaDB to localhost only:

## vim /etc/my.cnf.d/server.cnf

[mysqld]
#log-bin=mysql-bin
#binlog_format=mixed
bind-address = 127.0.0.1

[root@testserver7 my.cnf.d]# systemctl restart mariadb
[root@testserver7 my.cnf.d]# systemctl status mariadb
mariadb.service – MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled)
Active: active (running) since Fri 2015-02-06 09:17:59 SGT; 2s ago
Process: 9179 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 9150 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 9178 (mysqld_safe)
CGroup: /system.slice/mariadb.service
??9178 /bin/sh /usr/bin/mysqld_safe –basedir=/usr
??9348 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib64/mysql/plugin –log-erro…

Feb 06 09:17:57 testserver7 systemd[1]: Starting MariaDB database server…
Feb 06 09:17:57 testserver7 mysqld_safe[9178]: 150206 09:17:57 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log’.
Feb 06 09:17:57 testserver7 mysqld_safe[9178]: 150206 09:17:57 mysqld_safe Starting mysqld daemon with databases from /…/mysql
Feb 06 09:17:59 testserver7 systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
Hint: Some lines were ellipsized, use -l to show in full.
[root@testserver7 my.cnf.d]# systemctl enable mariadb
ln -s ‘/usr/lib/systemd/system/mariadb.service’ ‘/etc/systemd/system/multi-user.target.wants/mariadb.service’
[root@testserver7 my.cnf.d]#
[
/usr/bin/mysqladmin -u root password ‘test123’

/usr/bin/mysqladmin -u root -h testserver7 password ‘test123′

update mysql.user set password=PASSWORD(“test123”) where User=’root’;

Reset root password
[root@testserver7 my.cnf.d]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.41-MariaDB MariaDB Server

Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> update mysql.user set password=PASSWORD(“test123”) where User=’root’;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit
Bye
[root@testserver7 my.cnf.d]#

## mysql_secure_installation

Enter current password for root (enter for none): ENTER
Set root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

root@testserver7 my.cnf.d]# systemctl restart httpd
[root@testserver7 my.cnf.d]# systemctl status httpd
httpd.service – The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Fri 2015-02-06 09:47:33 SGT; 17s ago
Process: 10372 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 10377 (httpd)
Status: “Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec”
CGroup: /system.slice/httpd.service
??10377 /usr/sbin/httpd -DFOREGROUND
??10379 /usr/sbin/httpd -DFOREGROUND
??10380 /usr/sbin/httpd -DFOREGROUND
??10381 /usr/sbin/httpd -DFOREGROUND
??10382 /usr/sbin/httpd -DFOREGROUND
??10383 /usr/sbin/httpd -DFOREGROUND

Feb 06 09:47:28 testserver7 systemd[1]: Starting The Apache HTTP Server…
Feb 06 09:47:33 testserver7 httpd[10377]: AH00558: httpd: Could not reliably determine the server’s fully qualified dom…essage
Feb 06 09:47:33 testserver7 systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@testserver7 my.cnf.d]# systemctl enable httpd

/etc/httpd/conf.d

vi harden.conf

TraceEnable off

## Disable Signature
ServerSignature Off

## Disable Banner
ServerTokens Prod

[root@testserver7 conf.d]# apachectl configtest
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 192.168.1.3. Set the ‘ServerName’ directive globally to suppress this message
Syntax OK
[root@testserver7 conf.d]#

K, let’s continue with PHP configuration. Edit /etc/php.ini and set the following:

## vim /etc/php.ini

date.timezone = America/New_York
memory_limit = 64M
expose_php = Off

restart Apache using systemctl for the changes to take effect:

## systemctl restart httpd
## systemctl status httpd

Test if PHP module is loaded in Apache using:

## httpd -M | grep php

also

## php -v

You can create a test info.php script too using the following command:

## echo -e “ /var/www/html/info.php

and access it with the following command:

## curl -I $(curl -s icanhazip.com)/info.php

SET-UP APACHE VHOSTS

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:

## cat /etc/httpd/conf.d/vhosts.conf

# Load my vhosts
IncludeOptional vhosts.d/*.conf

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’s set-up one for domain1.com and another for domain2.net
VHOST for domain1.com

## cat /etc/httpd/vhosts.d/domain1.com.conf


ServerAdmin webmaster@domain1.com
DocumentRoot “/var/www/html/domain1.com”
ServerName domain1.com
ServerAlias www.domain1.com
ErrorLog “/var/log/httpd/domain1.com-error_log”
CustomLog “/var/log/httpd/domain1.com-access_log” combined


DirectoryIndex index.html index.php
Options FollowSymLinks
AllowOverride All
Require all granted

VHOST for domain2.net

## cat /etc/httpd/vhosts.d/domain2.net.conf


ServerAdmin webmaster@domain2.net
DocumentRoot “/var/www/html/domain2.net”
ServerName domain2.net
ServerAlias www.domain2.net
ErrorLog “/var/log/httpd/domain2.net-error_log”
CustomLog “/var/log/httpd/domain2.net-access_log” combined


DirectoryIndex index.html index.php
Options FollowSymLinks
AllowOverride All
Require all granted

Finally, restart Apache for the changes to take effect:

## apachectl configtest
## systemctl restart httpd
## systemctl status httpd

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>