Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Install openresty, mariadb and php7 services with yum source and source code package

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Before starting the deployment, it is necessary to give a brief introduction!

OpenResty is a high-performance Web platform based on Nginx and Lua, which integrates a large number of excellent Lua libraries, third-party modules and most dependencies. It is used to conveniently build dynamic Web applications, Web services and dynamic gateways that can handle ultra-high concurrency and high scalability.

MariaDB server is one of the most popular database servers in the world. It is made by the original developer's MySQL and is guaranteed to remain open source. MariaDB makes a variety of use cases very flexible because of its high speed, extensibility, robustness, rich ecosystem, storage engine, plug-ins and many other tools.

PHP, I don't think we need to babble any more.

Then let's start a new learning journey.

1. Preliminary preparation (minimizing the installed system)

1. Update the system

Yum makecache & & yum-y update

two。 Install common basic softwar

Yum-y install bash-completion vim net-tools bind-utilswget screen

Finally, don't forget to restart.

2. Update the yum source (Ali Cloud Source: mirrors.aliyun.com)

[root@localhost~] # mv / etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup

[root@localhost~] # ls / etc/yum.repos.d/

CentOS-Base.repo.backup CentOS-fasttrack.repo CentOS-Vault.repo

CentOS-CR.repo CentOS-Media.repo

CentOS-Debuginfo.repo CentOS-Sources.repo

Shut down fastestmirror first

[root@localhostyum.repos.d] # vi / etc/yum/pluginconf.d/fastestmirror.conf (enabled=0)

[root@localhost yum.repos.d] # wget-O/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@localhost yum.repos.d] # yumclean all

[root@localhost yum.repos.d] # yum makecache

3. Install mariadb

1. Add mariadb yum repository

Vi / etc/yum.repos.d/MariaDB.repo

[mariadb]

Name= MariaDB

Baseurl= http://yum.mariadb.org/10.1/centos7-amd64

Gpgkey= https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

Gpgcheck=1

two。 You can use yum search MariaDB to view the installation package, which is officially given as long as you install server and client, and the rest is based on

Come with your own needs.

Yum install MariaDB-server MariaDB-client

Note: although it is said that you only need to add system services and start the database, I have reported errors several times (personal advice is to make

Use my following steps)

[root@localhost ~] # yum search mariadb

At this time, there will be a lot of software, you just need to install it with yum.

[root@localhost ~] # yum-y install MariaDB-backupMariaDB-client MariaDB-common MariaDB-compat MariaDB-connect-engineMariaDB-cracklib-password-check MariaDB-devel MariaDB-gssapi-clientMariaDB-gssapi-server MariaDB-oqgraph-engine MariaDB-server MariaDB-shared MariaDB-test mariadb-benchmariadb-devel mariadb-embedded mariadb-embedded-devel mariadb-libs mariadb

There is also a post on the Internet saying that it needs to be initialized, and I have also tried to set up some configurations of the database, such as whether to delete the test database, whether to prohibit remote login to the database, whether to delete the desperate users, and so on, which can be followed by the configuration items-defaults-file,-- datadir,-- user, etc., which do not feel very useful (a little bit of nonsense, back to the original topic).

[root@localhost my.cnf.d] # mysql_secure_installation

3. Join the system service

[root@localhost ~] # systemctl enable mariadb

[root@localhost ~] # systemctl start mariadb.service

[root@localhost ~] # systemctl stop mariadb.service

Reminder: many things installed through yum are default, unlike source code compilation or your own DOWN installation package can be specified, column

Some more important paths come out.

Yum installation automatically creates mysql users and user groups

Yum installation automatically creates / etc/my.cnf and / etc/my.cnf.d file shelves (and stores files such as server.conf client.conf tokudb.conf)

Default rpm path

Basedir = / usr/bin

Datadir=/var/lib/mysql

H = / usr/include/mysql

Plung=/usr/lib64/mysql

Share=/usr/share/mysql (confcharset etc)

4. Install PHP7

1. Take a look at the yum source first.

[root@localhost ~] # ls / etc/yum.repos.d/

Back webtatic-archive.repo webtatic.repo webtatic-testing.repo

[root@localhost ~] # ls / etc/yum.repos.d/back/

# in the / etc/yum.repo.d/ directory, leave only the beginning of webstaic, and put the rest in the back directory [create a directory back]

CentOS7-Base-163.repo CentOS-CR.repo CentOS-Media.repo epel.repo

CentOS-Base.repo.backup CentOS-Debuginfo.repo CentOS-Sources.repo epel-testing.repo CentOS-Base.repo.backup1 CentOS-fasttrack.repo CentOS-Vault.repo

two。 Delete the previous PHP version

[root@localhost ~] # yum remove php* php-common

3.rpm installs the corresponding yum source for Php7:

[root@localhost ~] # rpm-Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

4. Install php7 directly with yum:

[root@localhost ~] # yum install php70w

5. Remember to install php-fpm manually

[root@localhost ~] # yum-y install php-fpm

[root@localhost ~] # ls / etc/php

Php.d/ php-fpm.conf php-fpm.d/ php.ini php-zts.d/

6. Take a look at the PHP version:

[root@localhost~] # php-v

PHP 7.0.18 (cli) (built: Apr 15 2017 07:09:11) (NTS)

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

Note:

1. Php.ini is the core configuration file for php operation:

2. Php-fpm.conf is the configuration file of the php-fpm process service:

3. Configure www.conf (under the php-fpm.d directory)

Www.conf this is the extended profile for the php-fpm process service:

Some file paths for the php service are at /

5. Install openresty (compile and install)

1. Dependency relationship

Openresty depends on perl5.6.1+, libreadline, libpcre, and libssl. Install dependencies first.

[root@localhost ~] # yum-y install perl 5.6.1 + libreadline libpcre libssl

[root@localhost~] # yum-y install readline-devel pcre-devel openssl-devel gcc

2 download the source code

Https://openresty.org/download/openresty-1.11.2.3.tar.gz (April 17)

Https://openresty.org/download/openresty-1.11.2.2.tar.gz (November 16)

Download using wget (you can log in to http://openresty.org to see the latest version)

[root@localhost~] # wget https://openresty.org/download/openresty-1.11.2.3.tar.gz

3. Decompress the downloaded compressed package

[root@localhost ~] # tar zxf openresty-1.11.2.3.tar.gz

4. Configure. / configure

[root@localhost openresty-1.11.2.3] # cd openresty-1.11.2.3/

[root@localhost openresty-1.11.2.3] # / configure-- prefix=/opt/openresty-- with-luajit

By default, the-prefix=/usr/local/openresty program is installed to the / usr/local/openresty directory.

We can specify various options, such as

. / configure-- prefix=/opt/openresty\

-- with-luajit\

-- without-http_redis2_module\

-- with-http_iconv_module\

-- with-http_postgres_module

For specific usage, please refer to. / configure-help or official documentation

5. Compile, install

[root@localhostopenresty-1.11.2.3] # gmake & & gmake install

6. Add nginx to the system variabl

PATH=/opt/openresty/nginx/sbin:$PATH

Export PATH or

[root@localhost openresty-1.11.2.3] # echo

"export PATH=$PATH:/opt/openresty/nginx/sbin/" > > / etc/profile & & source / etc/profile

7. Default project path

/ opt/openresty/nginx/html

8. Start, shut down, restart nginx

Nginx-c / opt/openresty/nginx/conf/nginx.conf / / start and load the configuration file

Nginx-s stop / / stop

Nginx-s reload / / restart

9. Do grammar checking for nginx

[root@localhost openresty-1.11.2.3] # nginx-t

Nginx: the configuration file/opt/openresty/nginx/conf/nginx.conf syntax is ok

Nginx: configuration file/opt/openresty/nginx/conf/nginx.conf test is successful

Start the nginx service

[root@localhost openresty-1.11.2.3] # nginx

Set firewall rules for port 80:

[root@localhost openresty-1.11.2.3] # cd

[root@localhost] # firewall-cmd--add-port=80/tcp-- permanent

Success

[root@localhost ~] # firewall-cmd-reload

Success

6. Use include instruction to realize nginx multi-virtual host configuration (nginx file setting)

1. Create nginx accounts and groups

[root@localhost~] # groupadd www-data

[root@localhost~] # useradd-g www-data www-data

two。 Configure the nginx.conf file: the content is as follows (program code)

User www-data

Worker_processes 1

Error_log/opt/openresty/nginx/logs/error.log crit

Pid / opt/openresty/nginx/logs/nginx.pid

Events {

# Network I /) model, epoll model is recommended for Linux system and kqueue model is recommended for FreeBSD system

Use epoll

Worker_connections 1024

}

Http {

Include / opt/openresty/nginx/conf/mime.types

Default_type application/octet-stream

Charset utf-8

Server_names_hash_bucket_size 128

Client_header_buffer_size 32k

Large_client_header_buffers 4 32k

Keepalive_timeout 60

Fastcgi_connect_timeout 300

Fastcgi_send_timeout 300

Fastcgi_read_timeout 300

Fastcgi_buffer_size 128k

Fastcgi_buffers 4 128k

Fastcgi_busy_buffers_size 128k

Fastcgi_temp_file_write_size 128k

Client_body_temp_path/opt/openresty/nginx/client_body_temp

Proxy_temp_path/opt/openresty/nginx/proxy_temp

Fastcgi_temp_path/opt/openresty/nginx/fastcgi_temp

Gzip on

Gzip_min_length 1k

Gzip_buffers 4 16k

Gzip_http_version 1.0

Gzip_comp_level 2

Gzip_types text/plain application/x-javascripttext/css application/xml

Gzip_vary on

Client_header_timeout 10

Client_body_timeout 10

Send_timeout 10

Sendfile on

Tcp_nopush on

Tcp_nodelay on

# virtual host

Include / host/nginx/conf/vhost/www_test_com.conf

Include / host/nginx/conf/vhost/www_test1_com.conf

Include / host/nginx/conf/vhost/www_test2_com.conf

# can also be replaced by include / host/nginx/conf/vhost/*.conf, where wildcards are supported.

# partingline###

# another virtual host using mix of IP-,name-, and port-based configuration

#

# server {

# listen 8000

# listen somename:8080

# server_name somename alias another.alias

# location / {

# root html

# index index.html index.htm

#}

#}

# HTTPS server

#

# server {

# listen 443 ssl

# server_name localhost

# ssl_certificate cert.pem

# ssl_certificate_key cert.key

# ssl_session_cache shared:SSL:1m

# ssl_session_timeout 5m

# ssl_ciphers HIGH:!aNULL:!MD5

# ssl_prefer_server_ciphers on

# location / {

# root html

# index index.html index.htm

#}

#}

}

3. In the virtual host configuration (www_test_com.conf, www_test1_com.conf, www_test2_com.conf) file of Nginx, set access.log,error.log

[root@localhost~] # mkdir-p / host/nginx/logs/test {"", 1, 2}

4. Create the virtual host configuration file directory vhost under the conf directory, and establish the corresponding domain names under the vhost directory.

Www_test_com.conf,www_test1_com.conf,www_test2_com.conf3 files.

# # I put the virtual host configuration file in this directory, but I just need to create the directory and .conf file manually first

[root@www test] # ls / host/nginx/conf/vhost/

Www_test1_com.conf www_test2_com.conf www_test_com.conf

Www_test_com.conf configuration Code:

Vi / host/nginx/conf/vhost/www_test_com.conf

Server {

Listen 80; # replace it with your own IP address (I am a domain name-based virtual host, so I have the same IP and different ports.

Client_max_body_size 100M

Server_name www.test.com; # change to your own domain name to be used

Charset utf-8; # character set: utf-8

Root / var/www/test/; # site path-the directory where the web page is stored

Index index.php index.html index.htm; # append index.php to make the nginx server support index.php as the home page by default:

Autoindex on

Access_log / host/nginx/logs/test/test.access.log

Error_log / host/nginx/logs/test/test.error.log

If (- d $request_filename) {

Rewrite ^ / (. *) ([^ /]) $http://$host/$1$2/ permanent

}

Error_page 404 / 404.html

Location = / 40x.html {

Root / var/www/test/; # your site path

Charset on

}

# redirect server error pages to the static page / 50x.html

#

Error_page 500 502 503 504 / 50x.html

Location = / 50x.html {

Root / var/www/test/; # own site path-web page storage path

Charset on

}

# load the client request to fastcgi, and the boss requires the use of fpm module (modification)

Location ~\ .php$ {

Root / var/www/test/

Fastcgi_pass 127.0.0.1:9000

Fastcgi_index index.php

Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name

Include fastcgi_params

}

Note: the configuration .php request is sent to the backend php-fpm module. By default, the php configuration block is annotated, so go to

Uncomment and modify, many of which are default. Root is the root directory where the configuration php program is placed, and the main modification is

The / scripts in fastcgi_param is $document_root

For example: fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name

Location~. *\. (php | php5 | php4 | shtml | xhtml | phtml)? ${

Fastcgi_pass 127.0.0.1:9000

Include / opt/openresty/nginx/conf/fastcgi_params

}

# the website has more pictures and fewer changes, and cache them locally in the browser for 15 days

Location. *\. (gif | jpg | jpeg | png | bmp | swf) ${

Expires 15d

}

# the website will load a lot of JS and CSS and cache them locally in the browser for 1 day

Location. *\. (js | css)? ${

Expires 1d

}

Location / (WEB-INF) / {

Deny all

}

}

Note: www_test1_com.conf configuration code and www_test2_com.conf configuration code are the same as www_test_com.conf (except

It is the same as the storage path of the web page.

5. Create the three directories / var/www/test,/var/www/test1,/var/www/test2, create an index.php under each of these three directories, and give them master and group permissions.

[root@www ~] # ls / var/www/test

Test/ test1/ test2/

[root@www ~] # vi/var/www/test/index.php

Add owner and group permissions to the webpage document directory / var/www/test {", 1Jing 2}.

[root@localhosttest] # chown-R www-data:www-data / var/www/test {"", 1, 2}

The other two test files (note the directory) are the same.

7. Php file configuration:

1.php-fpm.conf profile

[root@www~] # vi / etc/php-fpm.conf

Under the [global] configuration item, remove the semicolon comment before pid = / var/run/php-fpm/php-fpm.pid, and set the configuration file path with include=/etc/php-fpm.d/*.conf.

2.php-fpm.d/www.conf profile

[root@www~] # vi / etc/php-fpm.d/www.conf

There are user = and group= configuration items under [www] configuration, both of which have been changed.

User= www-data

Group= www-data

8. Check whether there is any error in the nginx configuration

Nginx-t

Start the Nginx service

[root@localhost~] # Nginx # # nginx launch command

Start the PHP service

[root@localhost~] # php-fpm # # PHP launch command

Start the mariadb service

[root@localhost~] # systemctl enable mariadb

9. Configure firewall rules:

[root@www~] # firewall-cmd-- add-port=80/tcp-permanent # nginx:80

[root@www~] # firewall-cmd-- add-port=3306/tcp-permanent # mariadb:3306

[root@www~] # firewall-cmd-- add-port=3306/tcp-permanent # PHP:9000

[root@www~] # firewall-cmd-reload

10. Do domain name mapping in the hosts file under C:\ WINDOWS\ system32\ drivers\ etc in the windows system.

11. You can view the visit.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report