Google Cloud Google cloud server configuration LNMP environment PHP+Mysql+Nginx installation details

Detailed explanation of Google Cloud Server configuration and installation of LNMP environment PHP+Mysql+Nginx under Centos8

Configuration If a worker wants to do his job well, he must first sharpen his tools. If he sharpens his knife and chops wood well, he must first cut the server.Well, when building a web website, without a good PHP environment, there will be more trouble later. I have talked about manually installing and deploying the PHP environment before. Today I will talk about how to install and deploy the PHP environment on Google without using a third-party panel.Use on dnf Command, manually install PHP+Mysql+How to configure the environment.

This tutorial is suitable for:/ Stream 8/ 9/ Red Hat Enterprise Linux ()

Google Cloud 谷歌云服务器配置 LNMP环境 PHP+Mysql+Nginx 安装详解-1

Google Cloud Server Configuration

The system is installed on Google's free cloud server. The machine type tested in this article is e2-medium (2 vCPUs, 4 GB memory).

Since CentOS 8 announced that it will stop supporting at the end of 21 and upgrade to CentOS Stream, Google Updating the previous Centos8 system to CentOS Stream 8 and CentOS Stream 9 systems has not changed much in terms of operation. Just add the software warehouse source.

The following takes the CentOS Stream 8 system as an example to carry out:

Google Cloud Google Cloud application andFor configuration methods, please visit:Apply for Google Cloud for free
well establishedAfter connecting to the server, connect to SSH and start the operation below. The first thing after installing the Centos8 system is to change the root password of the system.

谷歌云服务器配置 在 Centos8 下安装 LNMP 环境

Use the built-in web SSH on Google Cloud Platform to connect to the server, and modify the SSH connection method after logging in.

Google cloud server configuration changes server root password

use sudo -i or sudo su Command to switch to the super management root user, switch to the root super administrator mode and enter passwd command to change the password.

sudo -i passwd

Enter the password you want to change, and then confirm the password twice. After confirming the password, press Enter to complete the setting. use cd\ command to switch to the root directory.
use VI Command to modify the SSH configuration file.

vi /etc/ssh/sshd_config
谷歌云服务器配置 在 Centos8 下安装 LNMP 环境

If you want to modify the port for SSH remote connection, remove the # number in front of the Port, and then modify the port number you want to modify.
Modify the following content in sshd_config:

  • PermitRootLogin The default value is no, which needs to be changed to yes before SSH remote access can be used.
  • PasswordAuthentication The default value is no, change it to yes to enable password login.
  • ClientAliveInterval The default value is 420, modified to 3600, which is the client connection timeout time.
Port 10086 PermitRootLogin yes PasswordAuthentication yes ClientAliveInterval 3600

After modification, use:wqCommand to exit VI editing.

The above is how to enable SSH login using Google Cloud Server. After changing the ssh port, SElinux needs to be turned off, otherwise you cannot log in.

Shut down SElinux permanently

For the server, you first need to permanently shut down SElinux. Although SElinux is used to enhance Linux security, it is very troublesome to set up. It is recommended to close permanently.

vi /etc/selinux/config

Find SELINUX=enforcing, press i to enter edit mode, and change the parameters to SELINUX=disabled

谷歌云服务器配置 在 Centos8 下安装 LNMP 环境

After the modification is completed, press the Esc key on the keyboard, execute the command: wq, save and exit the file. Then reboot to restart the server. SElinux has been successfully shut down. The next step is to change the SSH port number. There are many automatic scanning machines on the Internet. Once infected, the consequences will be disastrous. Google Cloud charges based on traffic. Although it gives away 300 US dollars, if it is invaded, the bandwidth will be lost in one day. A few thousand dollars is no problem. So it’s better to change the remote port of SSH first!

Note: Some systems have the firewall turned on by default. You need to check the firewall status.

systemctl status firewalld

Google Cloud 谷歌云服务器配置 LNMP环境 PHP+Mysql+Nginx 安装详解-1

If the firewall is turned on, firewalld needs to be turned off with root user permissions.

# first needs to stop the firewall systemctl stop firewalld # after the firewall is stopped, permanently shut down systemctl disable firewalld

When entering the production environment later, the firewall can be set up on the Google Cloud platform.

Restart the server!

 reboot

Google Cloud Server configures CentOS 7/CentOS Stream 8/9 and installs software sources epel and remi

Next, you need to further install the software required by the centos8 system. Let's start updating the system and installing the sources required for the system software package. epel and remi are indispensable software repositories for centos8.

Install the software source using RPM:

CentOS 7 installation software repository:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

CentOS Stream 8 installation software repository:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-8.rpm

CentOS Stream 9 installation software repository:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-9.rpm

Use DNF method to install software sources:

DNF is the next generation of yum package manager (a derivative of Yum). The syntax of dnf and yum is similar and there are many similarities. DNF is installed by default on RHEL 8 and CentOS Stream 8 systems.

CentOS 7 installation software repository:

CentOS7 needs to install the dnf command first.

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm dnf install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

CentOS Stream 8 installation software repository:

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

CentOS Stream 9 installation software repository:

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

After the software source is installed, install dnf-utils

dnf-utils Classic YUM utility implemented as a CLI shim on top of DNF. The main purpose of these shims is to ensure backward compatibility with yum-3.

Use after installation dnf update Command to update the system software to the latest version.

dnf install dnf-utils dnf update

To check the data sources enabled on the system, use dnf repolist all The command can view all data sources, including unenabled data sources.

dnf repolist all
谷歌云服务器配置 在 Centos8 下安装 LNMP 环境

use dnf repolist command to view the software sources currently being used.

dnf repolist

use dnf repolist disabled Command to view the system disabled data sources.

dnf repolist disabled

After the software source is installed, you need to set up and optimize the installed software package source. use makecache The command generates a source cache.

dnf makecache

Install automatic updates with DNF enabled:

dnf install dnf-automatic systemctl start dnf-automatic.timer

Install the "Development Tools" package group:

dnf group install 'Development Tools' -y

Update system packages using DNF:

 dnf -y update

Google Cloud Server configures SWAP virtual memory

The default operating system installed by Google Cloud does not allocate swap space and needs to be added manually. If the operating system does not configure swapfile (allocate swap space), it will cause an error after memory load. Let’s teach you how to add the swap space of centos8 operating system!
use free -m Use the command to check the memory configuration. If there are 0s after Swap, you need to add swap space.

 free -m

Use six steps to create Swap virtual memory:

  1. Create a file with pre-allocated space of a specified size;
  2. To check the file size with ls command;
  3. Change the permissions of the swap file;
  4. Format swap file;
  5. Enable swap file;
  6. Modify the fstab file to automatically take effect after reboot.

Create an 8G SWAP partition. If you want to increase or decrease the SWAP virtual memory, please modify the value after count=.

sudo dd if=/dev/zero of=/swapfile bs=1024 count=8388608 ls -lh /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo vi /etc/fstab

use VI The command adds the following content at the end of the fstab file:

/swapfile swap swap sw 0 0

If you don't want to use VI command, you can also use it directly echo Command to set swap to start at boot.

echo '/swapfile swap swap sw 0 0' | sudo tee -a /etc/fstab

Server time synchronization

Install the server time synchronization tool. Time synchronization between the server and the client is very important.

Check the current time zone. If the time zone is UTC, you need to modify the server time zone.

timedatectl status|grep 'Time zone' # View the server hardware time hwclock # Synchronize the operating system time to the hardware time hwclock -w through hwclock -w

Modify server time zone

timedatectl set-timezone Asia/Shanghai timedatectl set-local-rtc 1 # uses the date command to check the current server time. date

Change the server time zone to Asia/Shanghai, which can be used later timedatectl Command to query the time zone.

In CentOS 8, the ntp software package is no longer supported by default, and time synchronization will be implemented by chrony.

By default, the chrony software package already exists after the centos8 system is installed. You can confirm whether it exists through rpm -q chrony. If it does not exist, use dnf to install it: dnf install chrony

vi /etc/chrony.conf
server ntp.aliyun.com iburst

Just add the domestic Alibaba Cloud time synchronization server in the first line and save it.

Set chrony to start running

systemctl enable chronyd systemctl start chronyd

Add new users and user groups

Before configuring Centos8, you need to add user groups and users for permissions related to web service access.

groupadd www useradd -g www www

After the users and user groups are configured, the basic environment of Centos8 has been almost configured. Next, start installing web-related services.

After Centos8 is configured, install Nginx+PHP8+Mysql. Be sure not to mistake the installation order. Install Nginx first, and then install PHP8 and Mysql.After Nginx is installed, no configuration is required. You can configure Nginx after installing PHP8.

Turn on the TCP BBR acceleration that comes with CentOS

If the system comes with a kernel higher than 4.9, BBR is included by default.

1. Use root privileges to run the following code. The kernel version is higher than 4.9.

uname -r

2. Turn on BBR

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

3. Effective changes

sysctl-p

4. Execute the following command. If the result contains bbr, it proves that your kernel has enabled bbr.

sysctl net.ipv4.tcp_available_congestion_control

Note: You can also execute the following command. If there is bbr in the result, it can also prove that your kernel has enabled bbr.

lsmod | grep bbr

 

Google Cloud Server Configuration and Installation Nginx

Installing nginx is relatively simple. Check the version after installation and it is 1.14.1. Software packages using DNF are relatively stable packages. Sometimes the version will be slightly lower, which is normal for centos official sources.

Before installing Nginx, first install the dependency packages required by Nginx.

dnf -y install zlib zlib-devel pcre pcre-devel openssl openssl-devel gd-devel make gcc gcc-c++
  • gcc linux compiler
  • pcre is a perl library, including a perl-compatible regular expression library. The http module of nginx uses pcre to parse regular expressions.
  • The zlib library provides many compression and decompression methods. nginx uses zlib to gzip the contents of the http package.
  • openssl is the cornerstone of secure web communication, that is, https-related dependencies

Install nginx:
After the dependency packages required by Nginx are installed, enter the following command to install nginx.

dnf install nginx nginx -v

After installation, set up startup:

systemctl enable nginx

Start Nginx. After starting, check the following current status of Nginx:

systemctl start nginx systemctl status nginx

Check the current status of port 80:

netstat -na | grep 80

Check and set whether the nginx default port is open:

firewall-cmd --query-port=80/tcp

If the return value is no, port 80 is not open and a firewall needs to be set up to allow port 80.

Open port 80:

firewall-cmd --add-port=80/tcp --permanent firewall-cmd --reload

Enter the server's IP address in the browser and check whether you can access the nginx welcome page.

配置谷歌云服务器 在 Centos8 下安装 LNMP 环境

The installation of Nginx has been successful. Next, check the installation directory. The directory for manually installing Nginx is usually /usr/local/nginx, but the directory installed using yum/dnf is different from the directory installed manually. The following are some corresponding directories for installing nginx using yum/dnf:

  • Nginx main configuration file: /etc/nginx/
  • Nginx execution file directory:/usr/sbin/nginx
  • Nginx home page html page path: /usr/share/nginx/html
  • Proxy directory:/var/cache/nginx/proxy_temp
  • Nginx cache directory:/var/cache/nginx/fastcgi_temp
  • scgi directory:/var/cache/nginx/scgi_temp
  • uwsgi directory:/var/cache/nginx/uwsgi_temp
  • Nginx log directory:/var/log/nginx
谷歌云安装PHP+Mysql+Nginx

Use after installation nginx -t command to test whether the installation is correct. Correct will return the following content.

The nginx version built into the default software repository of CentOS8 is 1.14.1. Recently, a missing scan prompted that you need to upgrade to version 1.17.7 or above. If you want to install a higher nginx version, please check:How to install the latest version of Nginx on Centos8

Google cloud server configuration and installation of PHP8

If using dnf -y install php If the command installs PHP by default, the version installed by default is very low. The current PHP version is PHP8.1. Let’s take a look at how to install PHP8.1.

First, check the software source for installing PHP8.1 in the system:

dnf list php
谷歌云安装PHP+Mysql+Nginx

The php version in the Centos8 default warehouse is 7.2.24. This version is too low. Next, switch to the remi source and find the php8.1 version.

Get a list of available PHPs:

dnf module list php
谷歌云安装PHP+Mysql+Nginx

The next step is to enable the PHP module of the remi warehouse. First reset the PHP module.

Reset the PHP data source module:

dnf module reset php
谷歌云安装PHP+Mysql+Nginx

Next, set up and enable the new PHP data source module. We need to install php8.1 and enable remi-8.1.

dnf module enable php:remi-8.1
谷歌云安装PHP+Mysql+Nginx

The remi-8.1 module has been enabled. Let’s install php8.1.

Enter the installation command to install:

dnf installphp
谷歌云安装PHP+Mysql+Nginx

After PHP is successfully installed, additionally install some commonly used PHP extension packages:

dnf install -y php-{mysqlnd,xml,xmlrpc,curl,gd,imagick,mbstring,opcache,soap,zip}

Extension installation for php8.0

dnf install -y php-{mysqlnd,pecl-imagick,pecl-imagick-devel,gd,intl,cli,mbstring,curl,php-pecl-zip}

use dnf search Command to check what extension packages are available for PHP8.1:

dnf search php81*

After querying, we found that there are too many php81 related software packages. What are these used for? Which ones should be installed and which ones should not be installed? The following is a detailed introduction to the php8.1 extension installation package.

PHP8.1 is ready, now let’s check which extension packages are installed.

rpm -qa|grep php
谷歌云安装PHP+Mysql+Nginx

Can also be used php –modules command to query installed PHP extensions.

php --modules

If you also need to install a PHP extension, just use the dnf -y install command plus the name of the extension you need to install.

For example, install the mysqlnd extension for PHP:

dnf install -y php-mysqlnd
谷歌云安装PHP+Mysql+Nginx

After the above is installed, next, set up the startup of php.

systemctl enable php-fpm

use systemctl Commands to manage quickly and easily. If there is a new PHP software package update, you can use the following command to upgrade to the latest available version.

dnf upgrade

Okay, now the installation of PHP8.1 is officially completed. Start the PHP service and let PHP start working.

systemctl enable php-fpm --now
After the server is started, take a look at the running status of PHP8.1.
systemctl status php-fpm

谷歌云安装PHP+Mysql+Nginx

If the status light is green, it means that PHP is working normally. There are some PHP configuration files that need to be modified.

PHP8 configuration

Modify the php.ini file

The php.ini file is the core configuration file of PHP. Modify it with caution!

Find the php.ini file location

谷歌云安装PHP+Mysql+Nginx
php -info | grep php.ini

Edit the php.ini file

use VI Use the command to edit the php.ini file, or use SFTP to log in to the server, and use Notepad to edit and modify the php.ini file. The recommended SFTP client is Xftp.

vi /etc/php.ini

Modify the variables in the file to the following values.

# prints PHP errors: display_errors = on # increases memory usage to 256M: memory_limit = 256M # file upload size, the default value is too small, it is recommended to modify the 1G size, which is 1024M: upload_max_filesize = 1024M # form maximum value, 48M is recommended: post_max_size = 48M # Maximum execution time of each script in seconds: max_execution_time=600 How many GET/POST/COOKIE input variables # can accept: max_input_vars = 3000 # Maximum time each script spends parsing request data: max_input_time = 1000

After the modification is completed, save and exit, and then modify the www.conf file of php.

Revise http://www.conf document

http://www.conf is the configuration file of the process service of php-fpm.

Modify user group and user name, set http://www.conf User group permissions for the file. Will http://www.conf Access permission settings -R, user and user group are set to nginx

chown nginx:nginx -R /etc/php-fpm.d/www.conf

edit http://www.conf File, modify user and user group variables.

vi /etc/php-fpm.d/www.conf

Will http://www.conf Variables in the file user and group All modified to nginx.

After modification, view listen variable:

Note: variables listen, the default is listen = /run/php-fpm/www.sock If you want to use 127.0.0.1:9000 to access PHP in Nginx, you need to listen Change the variable to listen = 127.0.0.1:9000. Otherwise, if you use 127.0.0.1:9000 in Nginx, you will not be able to access PHP.

Next, modify the request timeout value, modify the timeout period for a single request, remove the preceding semicolon, and change the value to 600.

request_terminate_timeout = 600

After the modification is completed, :wq save the file and exit, and the www.conf file is modified.

Modify session permissions

For example, modify the user group and permissions of /var/lib/php/session.

cd /var/lib/php chown nginx:nginx ./session chmod -R 777 ./session
systemctl reload php-fpm

At this point, PHP has been installed and configured. Restart the PHP service, or reboot the server.

Note: If Nginx does not support PHP access, check whether the listen variable is consistent with the Nginx setting. If you use 127.0.0.1:9000 to access, check whether port 9000 is open in the firewall.

netstat -lntp

PHP console commands

# Start PHP: systemctl start php-fpm # Stop: systemctl stop php-fpm # Restart: systemctl restart php-fpm # Restart to make the modified configuration take effect: systemctl reload php-fpm # Set up startup: systemctl enable php-fpm #PHP current Status: systemctl status php-fpm

Uninstall PHP

If you want to uninstall the php service installed using dnf, you can execute the uninstall command:

Note: If you compile and install php manually,remove The uninstall command is invalid. Uninstall the php main program first, and then remove the php-common that comes with the system.

dnf remove php dnf remove -y php-common

Disable SELinux

exist CentOS 8 permanently disabled on SELinux

vi /etc/selinux/config

Will SELinux The property is set to Disabled Then restart the server.

Google Cloud Server Configuration Configure Nginx

The following takes nginx1.20.1 version as an example:

Edit nginx.conf

If you want the web website to be accessible normally, you need to edit and modify the Nginx configuration file nginx.conf. nginx.conf is the core configuration file of Nginx. use VI Command to edit /etc/nginx/nginx.conf.

vi /etc/nginx/nginx.conf

The following is an example of a simple nginx.conf file for reference only:

user nginx; # configures the user or group, the default is nobody nobody. worker_processes auto; # allows the number of processes to be generated, the default is 1 pid /run/nginx.pid; # specifies the nginx process running file storage address error_log /var/log/nginx/error.log error; # specifies the error log path and level. This setting can be placed in the global block, http block, and server block. The levels are: debug|info|notice|warn|error|crit|alert|emerg. The higher the level, the fewer records. Generally, error # is set to load the dynamic module. include /usr/share/nginx/modules/*.conf; # working mode and maximum number of connections - events global settings events { accept_mutex on; # sets network connection serialization to prevent the occurrence of thundering groups, the default is on multi_accept on; # sets whether a process accepts multiple network connections at the same time. The default is off #use epoll; # event-driven model, select|poll|kqueue|epoll|resig|/dev/poll|eventport worker_connections 4096; # The maximum connection allowed by a single work process Number, default is 512 } #http server configuration file block http { log_format myFormat '$remote_addr–$remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for'; # custom log format access_log /var/log/nginx/access.log myFormat; # settings Access log path and format. combined is the default value of the log format. rewrite_log on; #access_log off; # cancel service access log sendfile on; # allows sendfile mode to transfer files, the default is off, and can be in http block, server block, location block. sendfile_max_chunk 0; # The number of transfers per process call cannot be greater than the set value. The default is 0, that is, there is no upper limit. keepalive_timeout 1000; # connection timeout, the default is 75s, can be in http, server, location block. client_max_body_size 1024m; types_hash_max_size 4096; tcp_nodelay on; tcp_nopush on; default_type application/octet-stream; # default file type, default is text/plain fastcgi_connect_timeout 3000; #fastcgi connection timeout, default 60 seconds fastcgi_send_timeout 3000; 1TP 5Tnginx process sends request to fastcgi process The timeout time of the process, the default value is 60 seconds fastcgi_read_timeout 3000; # The timeout time for the fastcgi process to send the output process to the nginx process, the default value is 60 seconds gzip on; #gzip compression switch, on turns on Gzip compression, the default is off, turns off gzip_min_length 1k; # enables gzip compression The minimum file, files smaller than the set value will not be compressed gzip_comp_level 9; # gzip compression level, 1-9, the larger the number, the better the compression, and the more CPU time is taken up gzip_buffers 4 16k; # Set the buffer required for compression Size gzip_http_version 1.1; # Set the HTTP protocol version for gzip compression. If there is no load, you can not use gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/ jpeg image/gif image/png application/vnd.ms-fontobject font/ttf font/opentype font/x-woff image/svg+xml; # file type for compression. JavaScript comes in many forms. The values can be found in the mime.types file. gzip_vary on; # Whether to add Vary: Accept-Encoding in the http header, it is recommended to enable gzip_disable "MSIE [1-6]\."; # Disable IE 6 gzip gzip_proxied off; ssl_session_cache shared:le_nginx_SSL:10m; ssl_session_timeout 1440m; ssl_session _tickets off ; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers off; ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-A ES256- GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"; include /etc/nginx/mime.types ; # file extension and file type mapping table. Set the mime type (email support type), the type is defined by the mime.types file. include /etc/nginx/conf.d/*.conf; # loads modular configuration files from the /etc/nginx/conf.d directory. }

 

Connect FastCGI

If you want to use PHP scripts to build web sites, you also need to set Nginx to support PHP.

The following introduces the PHP service connection module, enter /etc/nginx/default.d catalog, view php.conf document. This file is used when installing PHPThe file needs no modification and is used to pass the PHP script to the FastCGI server.

# pass the PHP scripts to FastCGI server # # See conf.d/php-fpm.conf for socket configuration # index index.php index.html index.htm; location ~ \.(php|phar)(/.*)? $ { fastcgi_split_path_info ^(.+\.(?:php|phar))(/.*)$; fastcgi_intercept_errors on; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $ fastcgi_path_info; fastcgi_pass php-fpm; }

Enter /etc/nginx/conf.d directory, directory php-fpm.conf The file does not need to be changed, php-fpm.conf It is automatically generated when installing PHP8.1, yesphp.confis used to pass PHP scripts to the FastCGI server.

# PHP-FPM FastCGI server # network or unix domain socket configuration upstream php-fpm { server unix:/run/php-fpm/www.sock; }

 

exist /etc/nginx/conf.d Create new in directory default.conf file, or create a new custom .conf file. Server{…} contains the website configuration content.

This is just an example for testing. The server configuration in a production environment is much more complicated.

server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name XXX.com; root /home/www; index index.php index.html index.htm; ssl_certificate "/etc/letsencrypt/live/** */fullchain.pem"; # ssl certificate address ssl_certificate_key "/etc/letsencrypt/live***/privkey.pem"; # ssl certificate address ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; # cache validity period ssl_ciphers ECDHE-RSA- AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; # encryption algorithm ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # secure link optional Encryption protocol ssl_prefer_server_ciphers on; # uses the server-side preferred algorithm # Config for 0-RTT in TLSv1.3 ssl_early_data on; ssl_stapling on; ssl_stapling_verify on; add_header Strict-Transport-Security "max-age=31536000"; include /etc/nginx/ default.d/*.conf; # loads the configuration file of the default server block from /etc/nginx/default.d. # pseudo-static page location / { try_files $uri $uri/ /index.php?$args; } # reverse proxy location /update32/ { proxy_redirect off; proxy_read_timeout 1200s; proxy_pass http://127.0.0.1:20892; proxy_http_version 1.1; proxy_set_header X -Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; Data $ssl_early_data; } }

Add access permissions to the web storage directory:

chown nginx:nginx -R /home/www

After the configuration is completed, create a new index.php file in the /home/www directory and paste the following code:

<?php
phpinfo();
?>

This is a PHP probe code. After pasting the code into index.php, save the file, and then restart the server as root.
Visit Nginx official PHP FastCGI example
Problems encountered in Nginx:
"nginx: [emerg] unknown directive "" in /etc/nginx/conf.d/" error occurs, yesThere is a space conversion problem when uploading using SFTP. This problem will not occur when editing with VI under Linux.

Uninstall Nginx

If you want to uninstall all nginx installed using dnf, you can execute the uninstall command:

dnf remove nginx

Nginx console commands

Start: systemctl start nginx Stop: systemctl stop nginx Restart (without stopping nginx, make the modified configuration take effect): systemctl reload nginx Restart: systemctl restart nginx Set boot: systemctl enable nginx Disable boot: systemctl disable nginx View service status: systemctl status nginx

At this point, the installation of Nginx has come to an end. Now let’s start installing the MYSQL database service.

Google Cloud Server configuration and installation MySQL

Centos8 uses dnf to install mysql. First check whether mysql has been installed in the system.

rpm -qa |grep -i mysql

If MySQL has not been installed on the server before, start the installation now. If you have installed MySQL before, please use the remove command to uninstall it!

First check what versions are in the data source.

dnf list mysql*
谷歌云安装PHP+Mysql+Nginx
InstallMySQL

Install MySQL8.0

Only version 8.0.26 can be found in the official Centos software source. If you want to install a higher version, you need to use other data sources.

dnf -y install mysql-server
谷歌云安装PHP+Mysql+Nginx
InstallMySQL

After the installation is successful, start MySQL, and then set it to start MySQL at boot.

# Start MySQL systemctl start mysqld # Set boot systemctl enable mysqld # Check the MySQL installation version mysqladmin --version

Finally, check the status of MySQL8.0 that has been installed.

systemctl status mysqld
谷歌云安装PHP+Mysql+Nginx

OK, the green light is on, everything is normal! Next configure the MySQL server.

Google Cloud Server Configuration MySQL

run mysql_secure_installation Script that performs some security-related operations and sets the MySQL root password:

 sudo mysql_secure_installation
谷歌云安装PHP+Mysql+Nginx

VALIDATE PASSWORD COMPONENT can be used to test passwords and increase security. It checks the strength of passwords and allows users to set only those passwords
Safe enough. Do you want to set up the VALIDATE PASSWORD component?

enter:Y , press Enter to enter the configuration.

谷歌云服务器配置 谷歌云安装PHP+Mysql+Nginx

Select the password verification policy level and enter: 0 (low)

Enter a new password. The password must be greater than 8 characters and contain uppercase letters, lowercase letters, numbers, and special symbols. Then confirm the password you set.

谷歌云安装PHP+Mysql+Nginx

To confirm whether to continue using the provided password, enter:Y

谷歌云安装PHP+Mysql+Nginx

By default, MySQL is installed with aUser, allows anyone to log into the user account MySQL has created for them without logging in. This is for testing only and to make installation smoother. You should delete them before entering the production environment.

Remove anonymous user? enter: Y

谷歌云安装PHP+Mysql+Nginx
Normally, only root is allowed to connect to 'localhost'. This ensures that someone cannot guess the root password from the network.

It is forbidden to use root to remotely log in to MySQL. Enter: N

谷歌云安装PHP+Mysql+Nginx

By default, MySQL comes with a database called "test", accessible to anyone. This is also for testing only and should be removed from the environment before moving to production.

Remove the test database input that comes with MySQL:Y

谷歌云安装PHP+Mysql+Nginx

Reloading the permissions table will ensure that all changes made so far will take effect immediately.

To reload the permissions table, enter:Y

MySQL8.0 already has the utf8mb4 character set by default, so the character set will not be modified. MySQL has been configured successfully at this step!

Configure mysql remote login

Note: If you need to set up the root account for remote login, repeat the previous step and then allow root remote login, set it to Y.

Next use mysql -u root -p Use the command to log in to MySQL and set the host field of the root user to '%', which means to accept login requests from all IP addresses of root.

UPDATE USER SET host='%' WHERE user='root';

After setting, restart the mysql service:

systemctl restart mysqld

MySQL console commands

Start: systemctl start mysqld Stop: systemctl stop mysqld Restart: systemctl restart mysqld Set boot: systemctl enable mysqld Disable boot: systemctl disable mysqld View service status: systemctl status mysqld

At this point, everything is installed! The Linux environment of php+mysql+nginx has been set up successfully.

score

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Highly recommended: Google Cloud Server is currently known to be a truly powerful free cloud server that can meet the actual needs of most websites!