[LINUX] Build CentOS8 LAMP

environment

CentOS Linux release 8.0.1905 (Core) Minimal install with gcc related, vim, git

web

Install_and_configure_apache2.4.37


[[email protected] ~]# dnf install httpd httpd-devel httpd-tools mod_ssl -y
[[email protected] ~]# httpd -v
Server version: Apache/2.4.37 (centos)
Server bui lt:   Oct  7 2019 21:42:02

[[email protected] ~]# cd /etc/httpd/conf/
[[email protected] /etc/httpd/conf]# cp httpd.conf httpd.conf.bk

[[email protected] /etc/httpd/conf]# cat httpd.conf.bk | egrep -v "(\#|^$)" > httpd.conf

[[email protected] /etc/httpd/conf]# vim httpd.conf
-:Listen 80
+:Listen 0.0.0.0:80

-:    DirectoryIndex index.html
+:    DirectoryIndex index.php index.html index.cgi
(Added at the end)
ServerTokens Prod

[[email protected] /etc/httpd/conf]# cd

[[email protected] ~]# firewall-cmd --list-all
  services: cockpit dhcpv6-client ssh

[[email protected] ~]# firewall-cmd --remove-service={dhcpv6-client,cockpit} --zone=public --permanent

[[email protected] ~]# firewall-cmd --add-serevice={http,https} --zone=public --permanent

[[email protected] ~]# firewall-cmd --reload

[[email protected] ~]# firewall-cmd --list-all
  services: http https ssh

[[email protected] ~]# echo "test page" > /var/www/html/index.html

[[email protected] ~]# chmod -R apache:apache /var/www

[[email protected] ~]# systemctl start httpd

[[email protected] ~]# systemctl enable httpd

Access http: // server IP / with a browser, and if it is displayed, it is OK.

PHP

Install_and_configure_php7.2.11


[[email protected] ~]# dnf install php php-fpm php-mbstring \
php-devel php-mysqlnd -y

[[email protected] ~]# php -v
PHP 7.2.11 (cli) (built: Oct  9 2018 15:09:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

[[email protected] ~]# vim /etc/php.ini
-:;date.timezone =
+:date.timezone = Asia/Tokyo
-:expose_php = On
+:expose_php = Off
-:;mbstring.language = Japanese
+:mbstring.language = Japanese
-:;mbstring.internal_encoding =
+:mbstring.internal_encoding = UTF-8
-:;mbstring.http_input =
+:mbstring.http_input = UTF-8
-:;mbstring.http_output =
+:mbstring.http_output = UTF-8
-:;mbstring.encoding_translation = Off
+:mbstring.encoding_translation = On
-:;mbstring.detect_order = auto
+:mbstring.detect_order = auto
-:;mbstring.substitute_character = none
+:mbstring.substitute_character = none

[[email protected] ~]# echo -n '<?php\nphpinfo();\n?>' > /var/www/html/index.php

[[email protected] ~]# cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.bk
[[email protected] ~]# vim /etc/php-fpm.d/www.conf
-:;listen.owner = nobody
+:listen.owner = apache
-:;listen.group = nobody
+:listen.group = apache
-:;listen.mode = 0660
+:listen.mode = 0660

[[email protected] ~]# systemctl restart httpd

Access http: // server IP / index.php with a browser, and if phpinfo () is displayed, it's OK.

mysql

Install_and_configure_mysql8.0


[[email protected] ~]# dnf install mysql-server mysql-devel -y

[[email protected] ~]# vim /etc/my.cnf.d/mysql-server.cnf
(Added at the end)
+:character-set-server=utf8
+:bind-address=0.0.0.0
#+:collation-server=utf8_unicode_ci

[[email protected] ~]# vim /etc/my.cnf
([client]Added directly below)
+:default-character-set=utf8
+:[mysql]
+:default-character-set=utf8

[[email protected] ~]# cp /usr/lib/systemd/system/mysqld.service \
/etc/systemd/system/

[[email protected] ~]# vim /etc/systemd/system/mysqld.service
-:ExecStart=/usr/libexec/mysqld --basedir=/usr
+:ExecStart=/usr/libexec/mysqld --basedir=/usr --skip-mysqlx

[[email protected] ~]# systemctl daemon-reload

[[email protected] ~]# systemctl start mysqld.service

[[email protected] ~]# systemctl status mysqld.service
   Active: active (running)

[[email protected] ~]# netstat -ant
tcp    0    0    0.0.0.0:3306    0.0.0.0:*    LISTEN

[[email protected] ~]# mysql -u root
(* Uppercase letters below are optional)
mysql> create database DBNAME;
mysql> create user [email protected];
mysql> grant all privileges on DBNAME.* to [email protected];
mysql> alter user [email protected] identified by 'PASSWORD';
mysql> quit;

[[email protected] ~]# vim test.php
<?php
    try {
        $dbcon = new PDO('mysql:host=localhost;dbname=DBNAME','USERNAME','PASSWORD');
        printf("success\n");
    }
    catch(PDOException $e){
        printf("failure\n");
        exit;
    }   
?>  

[[email protected] ~]# php test.php
success

[[email protected] ~]# firewall-cmd --add-service=mysql --zone=public --permanent

[[email protected] ~]# firewall-cmd --reload

[[email protected] ~]# firewall-cmd --list-all
  services: http https mysql ntp samba samba-client ssh

So far for the time being. I'm not good at SQL so I always search I wonder why it is often all capitalized.

Recommended Posts

Build CentOS8 LAMP
Build a LAMP environment [CentOS 7]
Build WordPress on CentOS 8 in LAMP environment
Static build ffmpeg (CentOS6)
Build a python3 environment on CentOS7
Build jupyter notebook on remote server (CentOS)
Build python 1.0
Stray build Python-3.8.5 on CentOS without root privileges
Build a LAMP environment on your local Docker
Build a LAMP environment in a very short time
Build a python environment with ansible on centos6