CentOS 7 install Nginx, PHP, MySQL packages

Initialize the system##

Set software source###

- aliyun , remi, mysql
# Set up aliyun library
$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# Set up the remi library,Set up the mysql library
$ yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

# Due to mysql copyright restrictions,Centos 7 does not have a built-in mysql server,Must be installed from the mysql official
$ yum install http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

Source address: nginx: Linux packages Create vi /etc/yum.repos.d/nginx.repo, and fill in the following content to install the yum repository library

[ nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1

Replace OS with "rhel" or "centos" Replace OSRELEASE with 5", "6", or "7"

Update metadata

# Update metadata
$ yum makecache

install software##

Common software and nmp software###

# Update system
$ yum update

# Install common software
$ yum install vim git supervisor redis

# Install php based on remi,So you need to install the remi source
# If you need to install another version,You need to repo=remi-php7x 
$ yum install --enablerepo=remi-php70 php php-pdo php-fpm php-mbstring php-mcrypt php-gd php-mysqli php-zip

# Install nginx
$ yum install nginx --enablerepo=nginx

# Install mysql server
$ yum install mysql-server

Start service###

# Start service
$ systemctl start php-fpm mysqld nginx supervisord

Boot from start

# boot
$ systemctl enable php-fpm mysqld nginx supervisord

Initialize the database###

Start mysql and get the password####

$ systemctl start mysqld

# mysql 5.7 A temporary password will be generated when the installation is complete,We need to find the error log`/var/log/mysqld.log`To get this temporary password
# use below command to see the password:
$ grep 'temporary password'/var/log/mysqld.log 
[ Note] A temporary password is generated for root@localhost: _ab3BAKulW?r

Initialize mysql

$ mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:******

New password:******

Re-enter newpassword:******

The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password:100 
Change the password for root ?((Press y|Y for Yes, any other key for No):*

Estimated strength of the password:100 
Do you wish to continuewith the password provided?(Press y|Y for Yes, any other key for No): y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users?(Press y|Y for Yes, any other key for No):  Y

Success.

Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely?(Press y|Y for Yes, any other key for No): N

... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it?(Press y|Y for Yes, any other key for No): N

 ... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now?(Press y|Y for Yes, any other key for No): Y

Success.

All done!

How to set a password

$ mysql -uroot -p******
mysql>set password for'root'@'localhost'=password('markzhao123456');
mysql> exit

Software configuration##

Configure nginx

Run group when configuring nginx####

# /etc/nginx/nginx.conf
user nginx nginx;

Configure nginx virtual host####

# /etc/nginx/conf.d/default.conf

server{
 listen 80;
 # If this is IP,Will allow access,otherwise,You can't visit even if you break the egg
 server_name www.domain.com ;
 index index.php index.html index.htm default.html default.htm default.php;
 root /webdata/www/domain/public;

 # Note here that the difference from the server itself is
 # fastcgi_param  SCRIPT_FILENAME  /scripts/$fastcgi_script_name;
 # fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 # Will cause FastCGI sent in stderr:"Primary script unknown"while reading response header from upstream
 location ~ \.php$ {
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.php;
  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  include        fastcgi_params;}

 location /{
  try_files $uri $uri//index.php?$query_string;}

 location ~.*\.(js|css)?$ {
  expires 12h;}

 access_log /webdata/logs/domain_access.log;
 error_log /webdata/logs/domain_error.log;}

Configure php

Configure php-fpm

# /etc/php-fpm.d/www.conf
user = nginx
group = nginx

Configure php.ini

# Time zone
date.timezone = Asia/Shanghai

Configure session to be writable

$ chown -R nginx:nginx /var/lib/php/session/

Configure the system to allow access

# Configure http
$ firewall-cmd --permanent --zone=public--add-service=http
# Configuration 3306
$ firewall-cmd --permanent --zone=public--add-port=3306/tcp
# Restart firewall
$ firewall-cmd --reload

Configure database user####

CREATE USER 'remote'@'%' IDENTIFIED WITH mysql_native_password AS 'U*OSy)iKk$XO9dMB';
GRANT ALL PRIVILEGES ON *.* TO 'remote'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
GRANT ALL PRIVILEGES ON `1dailian\_v2`.* TO 'remote'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES

supplement##

Download and install MySQL

Get the latest download address: http://dev.mysql.com/downloads/mysql/

Download link: http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.13-1.el7.i686.rpmhttp://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.13-1.el7.i686.rpm

# download
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.13-1.el7.i686.rpm
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.13-1.el7.i686.rpm

# installation
yum localinstall mysql-community-client**.rpm
yum localinstall mysql-community-server**.rpm

Reference article##

Reprinted from https://juejin.im/post/5c876968e51d454170785745

Recommended Posts

CentOS 7 install Nginx, PHP, MySQL packages
Centos7.3 install nginx
CentOS7.2 install Mysql5.7.13
CentOS7 install MySQL
CentOS install mysql
CentOS install PHP
CentOS7 install mysql
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS8 install MySQL8.0
CentOS7 install mysql8
CentOS7 install MySQL8
Centos install php73 fast cgi + nginx
centos 7.5 install mysql5.7.17
CentOS yum install Apache + PHP + Tomcat7 + MySQL
CentOS6.5 offline install MySQL5.6.26
Install MySQL5.7 in centos7
Install php in centos
Install mysql5.7 under CentOS7
CentOS 7.2 Yum install MySQL 5.6
Centos7 install Mysql8 tutorial
Centos manually install mysql8
Install mysql under Centos 7
Centos7 install Mysql database
Install mysql5.1 under CentOS6.5
Install mysql online on centos
centos install mysql through yum
CentOs7.3 compile and install Nginx 1.9.9
Install MySQL 8.0.16 on Linux Centos
Install MySQL under Linux (CentOS 7)
Tencent Cloud Centos install nginx
Centos6 install mysql 5.7.x series
CentOS 7 yum install PHP7.3 tutorial
Install Nginx server on CentOS 7
CentOS8 install MySQL8 (pro test)
Centos compile and install LAMP (apache-2.4.7 + mysql-5.5.35 + php 5.5.8) + Redis
How to install MySQL on CentOS 8
CentOS7 yum install and start mysql
CentOS Yum compile and install MySQL 5.6
How to install PHP7.4 in CentOS
Install MySql with Docker in CentOS7
CentOS 6.x compile and install Nginx
How to install Nginx on CentOS 8
Install MySQL on Linux CentOS7 (Windows)
CentOS7 yum install and start mysql
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos yum install mysql5.6 or above
1.5 Install Centos7
centos7 .*tar package to install MySQL5.7
How to install PHP on CentOS 8
CentOS7.5 source code compile and install mysql5.7.29
Install mysql8.0.13 version under Linux CentOS7 system
Linux environment construction: CentOs + Apache + MySQL + PHP
Centos7 compile and install MySQL8 problem record
Ubuntu install PHP and PHP Nginx configuration method
CentOS7.4 source code compile and install MySQL8.0
Configure Nginx + PHP 7.0 + MySQL environment under Ubuntu 16.04
CentOS7 system yum way to install MySQL5.7
Centos6 install Python2.7.13
Centos7 install Python 3.6.
Centos7 install protobuf