A, LNMP Architecture Overview
The first few years, the Internet's most popular Web combinations than the LAMP (Linux + Apache + MySQL + PHP), then the LAMP architecture for deploying Web applications is a very popular way
But in recent years, with the popularity of Nginx services, the emergence of a new Web combinations that LNMP (Linux + Nginx + MySQL + PHP)
Nginx is a lightweight Web server, supports load balancing and reverse proxy, as Nginx all the features, so a lot of large domestic companies have chosen to do for their own Nginx Web server
In fact LNMP architecture and LAMP architecture similar, the main difference is that on Nginx and PHP configuration collaboration, this time I will mention later deployment, let's first look at its components and benefits
1) LNMP architectural components
Linux: as a basis for LNMP architecture, providing an operating system for supporting Web sites Nginx: As the front LNMP architecture, is a high-performance, powerful, lightweight Web server program MySQL: LNMP as a backend architecture, business systems and other applications in a variety of account information, product information, customer information, can be stored with this PHP: As the development of three kinds of dynamic web programming language, PHP is responsible for interpreting dynamic page file, and provides Web application development and runtime environment
2) LNMP architectural advantages
Easy to use: a variety of programs PHP Web interpretative language, developed not need to compile, easy to use for transplant Customizable: has a large number of additional components and modules can extend the functionality to meet most enterprise applications customized on request Ease of Development: Dynamic LNMP website, the page code profile, non-professional programmers can easily modify the page code Security and stability: the benefit from the advantages of open source, programmers concerned about the large number of components and improve LNMP found problems can be resolved quickly Low cost: because the components that are all open source software is freely available and free to use, greatly reducing the implementation costs of enterprises
3) LNMP workflow
first step: User sends a http request from the browser requests the domain name inputted to the Web server, Web server, and the processing in response to client requests Step two: If the client requests a static resource, by Nginx itself parsed and directly returned to the user If the request is dynamic, by Nginx this request forwarded by Fast-cgi interfaces to PHP-FPM this process management program, then PHP-FPM calls the process PHP parser to parse third step: After completion of the analysis, the parser will process the script after the return to parse PHP-FPM, then PHP-FPM will then return to the Nginx script information in the form of Fast-cgi the fourth step: After Nginx server receives, and then transferred in the form of http response to the browser, the browser parsing and rendering again, the last page will be rendered after the rendering
Two, LNMP deployment architecture
The deployed LNMP architecture, based on: (CentOS7.5 + Nginx-1.16.1 + MySQL-5.7.27 + PHP-7.3.15)
1) Nginx deployment
1, the installation dependencies
[root@lnmp ~]# yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2. Create a user-run Nginx
[root@lnmp ~]# useradd -M -s /sbin/nologin nginx
3, download packages
[root@lnmp ~]# wget -c http://www.nginx.org/download/nginx-1.16.1.tar.gz
4, compile and install Nginx
[root@lnmp ~]# tar xf nginx-1.16.1.tar.gz -C /usr/src/ [root@lnmp ~]# cd /usr/src/nginx-1.16.1/ [root@lnmp nginx-1.16.1]# ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module [root@lnmp nginx-1.16.1]# make -j 8 && make install -j 8 && cd ~
5, added to the environment variables and start Nginx Nginx
[root@lnmp ~]# echo 'export PATH=/etc/nginx/sbin:$PATH' >> /etc/profile [root@lnmp ~]# source /etc/profile && nginx [root@lnmp ~]# netstat -anput | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3759/nginx: master
6, Nginx will be added as a system service
[root@lnmp ~]# cat > /usr/lib/systemd/system/nginx.service << EOF [Unit] Description=nginx After=network.target [Service] Type=forking PIDFile=/etc/nginx/logs/nginx.pid ExecStart=/etc/nginx/sbin/nginx ExecReload=killall -s HUP $(cat /etc/nginx/logs/nginx.pid) ExecStop=killall -s QUIT $(cat /etc/nginx/logs/nginx.pid) PrivateTmp = Flase [Install] WantedBy=multi-user.target EOF
7. Check and start Nginx
[root@lnmp ~]# nginx -t nginx: the configuration file /etc/nginx/conf/nginx.conf syntax is ok nginx: configuration file /etc/nginx/conf/nginx.conf test is successful [root@lnmp ~]# systemctl daemon-reload && pkill -9 nginx [root@lnmp ~]# systemctl restart nginx && systemctl enable nginx [root@lnmp ~]# netstat -anput | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3793/nginx: master
2) MySQL deployment
1, download packages
[root@lnmp ~]# wget -c https://downloads.mysql.com/archives/get/file/mysql-5.7.27.tar.gz [root@lnmp ~]# wget -c https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
2, install the appropriate dependencies
[root@lnmp ~]# yum -y install ncurses ncurses-devel cmake libaio libaio-devel pcre pcre-devel \ zlib zlib-devel bison bison-devel libverto libverto-devel libstdc++ libstdc++-devel \ dbus dbus-devel libss libss-devel gcc gcc-c++ autoconf m4 libgcc e2fsprogs perl-Data-Dumper
3. Create a user and group to run MySQL
[root@lnmp ~]# groupadd mysql [root@lnmp ~]# useradd -M -s /sbin/nologin mysql -g mysql
4, extract boost tool, and move to the specified location without the need to compile and install
[root@lnmp ~]# tar xf boost_1_59_0.tar.gz [root@lnmp ~]# mv boost_1_59_0 /usr/local/boost
5, compile and install MySQL
[root@lnmp ~]# tar xf mysql-5.7.27.tar.gz -C /usr/src/ [root@lnmp ~]# cd /usr/src/mysql-5.7.27/ [root@lnmp mysql-5.7.27]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_EXTRA_CHARSETS=all \ -DENABLED_LOCAL_INFILE=ON \ -DWITH_DEBUG=0 \ -DWITH_BOOST=/usr/local/boost \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock make -j 8 && make install -j 8 && cd ~
6, after the installation is complete compilation, creates the directory, and adjust the parameters
[root@lnmp ~]# mkdir /usr/local/mysql/pid [root@lnmp ~]# mkdir /usr/local/mysql/logs [root@lnmp ~]# mkdir /usr/local/mysql/socket [root@lnmp ~]# mkdir /usr/local/mysql/tmp [root@lnmp ~]# mkdir /usr/local/mysql/ibtmp [root@lnmp ~]# mkdir /usr/local/mysql/binlog [root@lnmp ~]# mkdir /usr/local/mysql/relaylog [root@lnmp ~]# mkdir /usr/local/mysql/outcsv/ [root@lnmp ~]# mkdir /usr/local/mysql/ibdata [root@lnmp ~]# mkdir /usr/local/mysql/undolog [root@lnmp ~]# mkdir /usr/local/mysql/redolog [root@lnmp ~]# chown -R mysql:mysql /usr/local/mysql [root@lnmp ~]# chmod -R 750 /usr/local/mysql/outcsv [root@lnmp ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile [root@lnmp ~]# source /etc/profile
7, the definition of the MySQL configuration file
[root@lnmp ~]# cat > /etc/my.cnf << EOF [client] port = 3635 socket = /usr/local/mysql/socket/mysql.sock [mysqld] user = mysql port = 3635 federated skip_ssl bind_address = 0.0.0.0 max_connections = 3600 max_connect_errors = 200 autocommit = ON skip-name-resolve symbolic-links = 0 skip-external-locking log_timestamps = system explicit_defaults_for_timestamp = ON transaction_isolation = read-committed binlog_gtid_simple_recovery = ON show_compatibility_56 = ON transaction_write_set_extraction = OFF socket = /usr/local/mysql/socket/mysql.sock pid-file = /usr/local/mysql/pid/mysql.pid log-error = /usr/local/mysql/logs/mysql_error.log secure-file-priv = /usr/local/mysql/outcsv innodb_tmpdir = /usr/local/mysql/ibtmp basedir = /usr/local/mysql datadir = /usr/local/mysql/data tmpdir = /usr/local/mysql/tmp character-set-server = utf8 init_connect = SET NAMES utf8 collation-server = utf8_general_ci slow_query_log = ON long_query_time = 1 min_examined_row_limit = 960 log_slow_admin_statements = ON log_slow_slave_statements = ON log_queries_not_using_indexes = OFF slow_query_log_file = /usr/local/mysql/logs/mysql_slow.log back_log = 360 tmp_table_size = 64M max_allowed_packet = 64M max_heap_table_size = 64M sort_buffer_size = 1M join_buffer_size = 1M read_buffer_size = 2M read_rnd_buffer_size = 2M thread_cache_size = 64 thread_stack = 256K query_cache_size = 32M = 2M query_cache_limit query_cache_min_res_unit = 2K table_open_cache = 4096 open_files_limit = 65535 connect_timeout = 9 interactive_timeout = 21600 wait_timeout = 21600 innodb_data_file_path = ibdata1:12M;ibdata:12M:autoextend innodb_autoextend_increment = 12 innodb_data_home_dir = /usr/local/mysql/ibdata innodb_undo_tablespaces = 4 innodb_undo_logs = 128 innodb_max_undo_log_size = 1G innodb_undo_log_truncate = ON innodb_purge_rseg_truncate_frequency = 10 innodb_undo_directory = /usr/local/mysql/undolog innodb_log_file_size = 128M innodb_log_buffer_size = 16M innodb_log_files_in_group = 3 innodb_flush_log_at_trx_commit = 2 innodb_flush_log_at_timeout = 1 innodb_flush_method = O_DIRECT innodb_log_group_home_dir = /usr/local/mysql/redolog innodb_temp_data_file_path = ibtmp1:12M:autoextend:max:5G innodb_fast_shutdown = 0 default-storage-engine = InnoDB innodb_buffer_pool_size = 2G table_open_cache_instances = 8 innodb_buffer_pool_chunk_size = 256MB innodb_page_size = 16k innodb_sort_buffer_size = 1MB innodb_file_per_table = ON innodb_large_prefix = ON innodb_purge_threads = 8 innodb_page_cleaners = 8 innodb_read_io_threads = 8 innodb_write_io_threads = 8 innodb_thread_concurrency = 16 innodb_flush_neighbors = 0 innodb_lru_scan_depth = 1024 innodb_lock_wait_timeout = 60 innodb_print_all_deadlocks = ON innodb_deadlock_detect = ON innodb_strict_mode = ON innodb_buffer_pool_load_at_startup = ON innodb_buffer_pool_dump_at_shutdown = ON EOF
8, MySQL initialize
[root@lnmp ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data [root@lnmp ~]# echo $? 0
9, adding MySQL as a system service
[root@lnmp ~]# cp /usr/local/mysql/support-files/mysql.server /usr/local/mysql/bin/mysql.sh [root@lnmp ~]# chmod +x /usr/local/mysql/bin/mysql.sh [root@lnmp ~]# cat > /usr/lib/systemd/system/mysql.service << EOF [Unit] Description=MySQL After=network.target [Service] User=mysql Group=mysql Type=forking PrivateTmp=false LimitNOFILE = 65535 ExecStart=/usr/local/mysql/bin/mysql.sh start ExecStop=/usr/local/mysql/bin/mysql.sh stop [Install] WantedBy=multi-user.target EOF
10, start MySQL and set a password for the root user
[root@lnmp ~]# systemctl start mysql [root@lnmp ~]# systemctl enable mysql [root@lnmp ~]# netstat -anput | grep mysql tcp 0 0 0.0.0.0:3635 0.0.0.0:* LISTEN 34411/mysqld [root@mysql ~]# mysql -e"update mysql.user set authentication_string=password('abc-123') where user='root';flush privileges;"
11, authorize the root user
mysql> select host,user,authentication_string from mysql.user; +-----------+---------------+-------------------------------------------+ | host | user | authentication_string | +-----------+---------------+-------------------------------------------+ | localhost | root | *717D3436D5EC09E2941FEA929907C61FE8CE3E19 | | localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | +-----------+---------------+-------------------------------------------+ 3 rows in set (0.01 sec) mysql> grant all privileges on *.* to 'root'@'10.2.3.%' identified by 'abc-123'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> select host,user,authentication_string from mysql.user; +-----------+---------------+-------------------------------------------+ | host | user | authentication_string | +-----------+---------------+-------------------------------------------+ | localhost | root | *717D3436D5EC09E2941FEA929907C61FE8CE3E19 | | localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | | 10.2.3.% | root | *717D3436D5EC09E2941FEA929907C61FE8CE3E19 | +-----------+---------------+-------------------------------------------+ 4 rows in set (0.00 sec)
3) PHP deployment
1, the installation dependencies
yum -y install libxml2 libxml2-devel gd gd-devel libpng libpng-devel bzip2 bzip2-devel \ curl curl-devel gmp gmp-devel openldap openldap-devel libevent libevent-devel libxslt libxslt-devel
2, download packages
[root@lnmp ~]# wget -c https://www.php.net/distributions/php-7.3.15.tar.gz
3, installation libzip
Note: If you deploy PHP version is 7.X, you need to install libzip, otherwise it will prompt: Please reinstall the libzip distribution
[root@lnmp ~]# wget -c https://nih.at/libzip/libzip-1.2.0.tar.gz [root@lnmp ~]# tar xf libzip-1.2.0.tar.gz -C /usr/src/ [root@lnmp ~]# cd /usr/src/libzip-1.2.0/ [root@lnmp libzip-1.2.0]# ./configure && make -j 8 && make install -j 8 && cd ~ [root@lnmp ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h [root@lnmp ~]# cat > /etc/ld.so.conf.d/local.conf << EOF /usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64 EOF [root@lnmp ~]# ldconfig -v
4, compile and install PHP
[root@lnmp ~]# tar xf php-7.3.15.tar.gz -C /usr/src/ [root@lnmp ~]# cd /usr/src/php-7.3.15/ [root@lnmp php-7.3.15]# ./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7 --enable-fpm --enable-mbstring \ --with-gd --with-zlib --enable-inline-optimization --with-jpeg-dir=/usr/lib --disable-debug --disable-rpath \ --enable-shared --with-libxml-dir --with-xmlrpc --enable-soap --with-openssl --enable-exif --enable-fileinfo \ --enable-filter --with-pcre-dir --enable-ftp --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir \ --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --enable-json --enable-mbregex --enable-mbregex-backtrack \ --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --enable-session --enable-shmop \ --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip \ --enable-mysqlnd-compression-support --with-pear --enable-opcache --with-mhash --with-pcre-regex --with-sqlite3 --enable-bcmath --with-iconv --with-bz2 \ --enable-calendar --with-curl --with-cdb --enable-dom --without-pear --disable-phar && make -j 8 && make install -j 8
4, reference copy files and create a soft link for PHP
[root@lnmp php-7.3.15]# cp php.ini-production /usr/local/php7/php.ini [root@lnmp php-7.3.15]# ln -s /usr/local/php7/bin/* /usr/local/bin/ [root@lnmp php-7.3.15]# ln -s /usr/local/php7/sbin/* /usr/local/sbin/ && cd ~
5, the installation opcache module for improved performance
[root@lnmp ~]# cd /usr/src/php-7.3.15/ext/opcache/ [root@lnmp opcache]# /usr/local/php7/bin/phpize Configuring for: PHP Api Version: 20180731 Zend Module Api No: 20180731 Zend Extension Api No: 320180731 [root@lnmp opcache]# ./configure --with-php-config=/usr/local/php7/bin/php-config && make -j 8 && make install -j 8 && cd ~ [root@lnmp ~]# cp /usr/local/php7/lib/php/extensions/no-debug-non-zts-20180731/opcache.so /usr/local/php7/include/php/ext/
6, edit the PHP configuration file
[root@lnmp ~]# cp /usr/local/php7/php.ini /usr/local/php7/php.ini.bak [root@lnmp ~]# vim /usr/local/php7/php.ini memory_limit = 1024M max_execution_time = 0 post_max_size = 10800M upload_max_filesize = 10240M max_input_time = 360 [opcache] opcache.enable=1 opcache.enable_cli=1 opcache.fast_shutdown = 1 opcache.save_comments = 1 opcache.revalidate_freq = 5 opcache.validate_timestamps = 0 opcache.memory_consumption = 512 opcache.interned_strings_buffer = 8 opcache.max_accelerated_files = 10000 zend_extension = /usr/local/php7/include/php/ext/opcache.so [Date] date.timezone = Asia/Shanghai [Pdo_mysql] pdo_mysql.default_socket=/usr/local/mysql/socket/mysql.sock
7, copy the template file and PID's path to absolute path
[root@lnmp ~]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf [root@lnmp ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf [root@lnmp ~]# sed -i 's#;pid = run/php-fpm.pid#pid = /usr/local/php7/var/run/php-fpm.pid#' /usr/local/php7/etc/php-fpm.conf
8, the change is a group owner, and turn the dynamic mode, the dynamic parameter adjustment
[root@lnmp ~]# cp /usr/local/php7/etc/php-fpm.d/www.conf /usr/local/php7/etc/php-fpm.d/www.conf.bak [root@lnmp ~]# vim /usr/local/php7/etc/php-fpm.d/www.conf user = nginx group = nginx pm = dynamic pm.max_children = 130 pm.start_servers = 15 pm.min_spare_servers = 6 pm.max_spare_servers = 35
9, start the PHP-FPM and set to boot from Kai
[root@lnmp ~]# /usr/local/sbin/php-fpm -t [24-Feb-2020 15:14:03] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful [root@lnmp ~]# /usr/local/sbin/php-fpm [root@lnmp ~]# netstat -anput | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 92180/php-fpm: mast [root@lnmp ~]# vim /etc/rc.local [root@lnmp ~]# echo "/usr/local/sbin/php-fpm" >> /etc/rc.local
10, Nginx configuration to support PHP parsing
[root@lnmp ~]# cp /etc/nginx/conf/nginx.conf /etc/nginx/conf/nginx.conf.bak [root@lnmp ~]# vim /etc/nginx/conf/nginx.conf user nginx; worker_processes auto; worker_cpu_affinity auto; worker_rlimit_nofile 65535; pid /etc/nginx/logs/nginx.pid; error_log /etc/nginx/logserror.log info; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; log_format mds '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log mds; sendfile on; tcp_nopush on; tcp_nodelay on; send_timeout 10; keepalive_timeout 60; server_tokens off; client_max_body_size 512m; fastcgi_buffers 64 4K; client_header_buffer_size 15k; large_client_header_buffers 4 128k; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache max=65535 inactive=20s; gzip on; gzip_min_length 3k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 1; gzip_vary on; gzip_types text/plain application/x-javascript text/css application/xml; server { listen 10.2.3.11:80; server_name www.mds.com; charset utf-8; location / { root /etc/nginx/html; index index.html index.htm; } location ~ \.php$ { root /etc/nginx/html; fastcgi_pass 127.0.0.1:9000; # here to fill PFP-FPM listen address and port fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } }
Three, LNMP architecture test
1) write PHP test code
(1) page test code
[root@lnmp ~]# vim /etc/nginx/html/index.php <?php phpinfo(); ?>
(2) Test Code Database
[root@lnmp ~]# vim /etc/nginx/html/dbc.php <?php $servername = "10.2.3.11"; $username = "root"; $password = "abc-123"; try { $conn = new PDO("mysql:host=$servername:3635;",$username,$password); echo "database connection success"; } catch(PDOException $e) { echo $e->getMessage(); } ?>
2) Web access and database connectivity test test
(1) access the test page
(2) Test Database Connectivity
Fourth, the deployment of WordPress blog system architecture based LNMP
1) extract the package
[root@lnmp ~]# unzip /root/wordpress-4.9.4-zh_CN.zip [root@lnmp ~]# mv wordpress /etc/nginx/html/wordpress [root@lnmp ~]# chown -R nginx:nginx /etc/nginx/html/wordpress
2) define the Nginx configuration file
[root@lnmp ~]# cat /etc/nginx/conf/nginx.conf user nginx; worker_processes auto; worker_cpu_affinity auto; worker_rlimit_nofile 65535; pid /etc/nginx/logs/nginx.pid; error_log /etc/nginx/logserror.log info; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; log_format mds '$remote_addr - $remote_user [$time_local] "$request"' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log mds; sendfile on; tcp_nopush on; tcp_nodelay on; send_timeout 10; keepalive_timeout 60; server_tokens off; client_max_body_size 512m; fastcgi_buffers 64 4K; client_header_buffer_size 15k; large_client_header_buffers 4 128k; open_file_cache_valid 30s; open_file_cache_min_uses 2; open_file_cache max=65535 inactive=20s; gzip on; gzip_min_length 3k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 1; gzip_vary on; gzip_types text/plain application/x-javascript text/css application/xml; upstream wordpress { server 127.0.0.1:9000; } server { listen 10.2.3.11:80; server_name www.mds.com; charset utf-8; root /etc/nginx/html/wordpress; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; } location = /favicon.ico { log_not_found off; access_log off; } location = /robots.txt { allow all; log_not_found off; access_log off; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; } location ~ \.php$ { fastcgi_index index.php; fastcgi_pass wordpress; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } } }
3)为WordPress创建用户并授权
[root@lnmp ~]# mysql -uroot -pabc-123 -e"create database wordpress;" 2> /dev/null [root@lnmp ~]# mysql -uroot -pabc-123 -e"grant all privileges on wordpress.* to 'wordpress'@'10.2.3.%' identified by 'abc-123';;" 2> /dev/null [root@lnmp ~]# mysql -uwordpress -pabc-123 -h10.2.3.11 -P3635 -Dwordpress 2> /dev/null Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 5.7.27-log Source distribution Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select database(); +------------+ | database() | +------------+ | wordpress | +------------+ 1 row in set (0.00 sec)
3)复制范本文件并填写数据库连接信息
[root@lnmp ~]# cp /etc/nginx/html/wordpress/wp-config-sample.php /etc/nginx/html/wordpress/wp-config.php [root@lnmp ~]# vim /etc/nginx/html/wordpress/wp-config.php /** WordPress数据库的名称 */ define('DB_NAME', 'wordpress'); /** MySQL数据库用户名 */ define('DB_USER', 'wordpress'); /** MySQL数据库密码 */ define('DB_PASSWORD', 'abc-123'); /** MySQL主机 */ define('DB_HOST', '10.2.3.11:3635'); /** 创建数据表时默认的文字编码 */ define('DB_CHARSET', 'utf8'); /** 关闭核心提示 */ add_filter('pre_site_transient_update_core',create_function('$a',"return null;")); /** 关闭插件提示 */ add_filter('pre_site_transient_update_plugins',create_function('$a',"return null;")); /** 关闭主题提示 */ add_filter('pre_site_transient_update_themes',create_function('$a',"return null;")); /** 禁止WordPress检查更新 */ remove_action('admin_init','_maybe_update_core'); /** 禁止WordPress更新插件 */ remove_action('admin_init','_maybe_update_plugins'); /** 禁止WordPress更主题 */ remove_action('admin_init','_maybe_update_themes');
4)重启Nginx与PHP-FPM
[root@lnmp ~]# pkill -9 php-fpm [root@lnmp ~]# /usr/local/sbin/php-fpm [root@lnmp ~]# systemctl restart nginx mysql [root@lnmp ~]# netstat -anput Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2561/php-fpm: maste tcp 0 0 10.2.3.11:80 0.0.0.0:* LISTEN 2603/nginx: master tcp 0 0 0.0.0.0:3635 0.0.0.0:* LISTEN 3864/mysqld
5)测试访问WordPress博客系统
【只是为了打发时间】