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

How to build LEMP environment under CentOS7.x

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of how to build the LEMP environment under CentOS7.x, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to build the LEMP environment under CentOS7.x. Let's take a look.

1. Install nginx

We installed a pre-built stable version of the nginx package from nginx's official rpm source.

$sudo rpm-- import http://nginx.org/keys/nginx_signing.key $sudo rpm-ivh http://nginx.org/packages/centos/7/noarch/rpms/nginx-release-centos-7-0.el7.ngx.noarch.rpm $sudo yum install nginx

In this way, nginx is installed, and nginx will not start automatically after the installation is complete. What needs to be done now is to let nginx start automatically and configure it to boot as the operating system starts. We also need to open the tcp/80 port in the firewall so that nginx's web service can be accessed remotely. All these operations and settings can be realized by entering the following command.

$sudo systemctl start nginx $sudo systemctl enable nginx $sudo firewall-cmd-zone=public-- add-port=80/tcp-- permanent $sudo firewall-cmd-- reload

Nginx has been started, now let's test nginx. The default document directory for nginx under centos7 is / usr/share/nginx/html. The default index.html file must already be in this directory. Let's check to see if we can access the test web page and enter the ip address / access of http://nginx.

2. Install mariadb/mysql

Centos/rhel 7 uses mariadb instead of the default mysql. As a simple alternative to mysql, mariadb ensures maximum compatibility with mysql's api and command line usage. The following is an example of how to install and configure maradb/mysql on centos7.

$sudo yum install mariadb-server $sudo systemctl start mariadb $sudo systemctl enable mariadb

After successfully starting the mariadb/mysql service, you also need to configure the security of the database, such as setting (non-empty) root passwords, deleting anonymous users, and locking remote access. Execute the following code:

$sudo mysql_secure_installation

Follow the prompts to set the root password, delete anonymous users, and so on.

3. Install php

Php is an important component in the lemp package, which is responsible for extracting the data stored in the mariadb/mysql server to generate dynamic content. In order to need lemp, you need to install at least two modules, php-fpm and php-mysql. Php-fpm (fastcgi process Manager) implements the access interface between nginx servers and php applications that generate dynamic content. The php-mysql module enables php programs to access mariadb/mysql databases.

First check the currently installed php package.

Yum list installed | grep php

If you have installed php packages, delete them first.

Add a source package to the yum installation.

Rpm-uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm rpm-uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Run yum install.

Use the yum command to customize the php engine and install some php extension module packages.

Yum install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64

Then install php fpm.

Yum install php56w-fpm

Finally, start php-fpm

$sudo systemctl start php-fpm $sudo systemctl enable php-fpm

4. Configure lemp to make nginx support php

First, disable the httpd service installed with the php package.

$sudo systemctl disable httpd

Next, configure the nginx virtual host so that nginx can handle php's tasks through php-fpm. Open / etc/nginx/conf.d/default.conf with a text editor and modify it as shown below.

Server {listen 80; server_name localhost; root / usr/share/nginx/html; index index.php index.html index.htm; # charset koi8-r; # access_log / var/log/nginx/log/host.access.log main; location / {} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500 502 503 504 / 50x.html Location = / 50x.html {} # proxy the php scripts to apache listening on 127.0.0.1 location 80 # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1 uri 9000 # location. Php$ {try_files $uri = 404; fastcgi_pass 127.0.0.1 uri 9000; fastcgi_index index.php; fastcgi_param script_filename $document_root$fastcgi_script_name; include fastcgi_params }}

Then, configure php and modify / etc/php.ini.

Cgi.fix_pathinfo=1 date.timezone = prc

Finally, test whether nginx can handle php pages. Be sure to restart nginx and php-fpm before testing.

$sudo systemctl restart nginx $sudo systemctl restart php-fpm

Create a file called test.php, then write the following and put it in the / usr/share/nginx/html/ directory.

Open a browser and enter the ip address / test.php of http://nginx. When you see the following interface, the lemp installation is complete.

This is the end of the article on "how to build the LEMP environment under CentOS7.x". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to build the LEMP environment under CentOS7.x". If you want to learn more, you are welcome to follow the industry information channel.

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

Internet Technology

Wechat

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

12
Report