Install lnmp service using yum on CentOS 6

zhuanzaidizhi: https://www.qiansw.com/yum-lnmp.html

To demonstrate the simplicity of using linux, all the applications used in this article are installed using yum.

Install CentOS System

This article assumes that you have the ability to install the CentOS system and will not explain the installation process.
The operating system used in this article is CentOS 6 x86_64.

Connect Using ssh client

After the system is installed, we use the ifconfig command to view the IP of the system. The IP address of the system used in this paper is 192.168.6.141.

xshell is recommended as an ssh client and is free for individuals and schools.

After entering the ip address, username and password, you can successfully connect to the CentOS system remotely.

Install common tools

Install commonly used tools directly using yum.

yum install -y vim

Turn off SELINUX

SELinux(Security-Enhanced Linux) is the implementation of mandatory access control by the National Security Agency (NSA), and is the most outstanding new security subsystem in Linux history.

SELinux is a complex configuration and to avoid its impact, it is recommended that novices turn it off directly.

Use sed to modify its configuration file, and when the modification is complete, restarting the system will no longer enable SELinux:

sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config

Temporarily (without restart) turn off SELinux:

setenforce 0

Configure or close iptables

iptables are not explained in this article and will be turned off directly.
You can execute iptables-L to compare before and after executing the following commands.

#Empty iptables rule
iptables -F

#Preservation
service iptables save

Install Nginx

The default repository for CentOS 6 does not contain nginx, so we can manually add the repository for nginx.

Visit nginx's website to get repo files

We need to visit the official website of nginx first to get the official warehouse address.
Click here to access the official nginx documentation.

According to the instructions in the document, the final repo file should be the following so that you can copy it directly.

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

Save the above configuration in the / etc/yum.repos.d/nginx.repo file using vim.

Install nginx

Once the warehouse is installed, nginx can be installed directly using yum.

yum install -y nginx

start nginx

Execute service nginx start to start nginx.

After successful startup, execute netstat-tunlp|grep 80 to see that nginx has started listening on port 80.

[root@localhost ~]# netstat -tunlp|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1881/nginx

And by accessing the server's ip address directly through the browser, you can see that a welcome page for nginx has appeared.

Set nginx to Start Up

Execute chkconfig nginx on to set nginx to boot.

Install MySQL

The default repository for CentOS 6 contains MySQL directly and MySQL Server can be installed directly from yum.

yum install -y mysql mysql-server

The MySQL service name is mysqld, and we can start the MySQL service with the following command.

service mysqld start

Like nginx, use the following command to add mysqld to the startup task.

chkconfig mysqld on

After successful startup, execute netstat-tunlp|grep 3306 to see that mysqld has started listening on port 3306.

[root@localhost ~]# netstat -tunlp|grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2094/mysqld

You can also connect to the MySQL server through the MySQL client.

[root@localhost ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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>

Install PHP

The CentOS default repository contains the php suite, which we can install using yum directly.
The following is a minimal installation, and we use php-fpm to resolve php.

yum install -y php-cli php-fpm

You can view other PHP extensions at any time using yum list php-*, below are all the extensions included in the default repository.

[root@localhost ~]# yum list php-*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.sina.cn
 * updates: mirrors.sina.cn
Installed Packages
php-cli.x86_64                                                                      5.3.3-48.el6_8                                                            @updates
php-common.x86_64                                                                   5.3.3-48.el6_8                                                            @updates
php-fpm.x86_64                                                                      5.3.3-48.el6_8                                                            @updates
Available Packages
php.x86_64                                                                          5.3.3-48.el6_8                                                            updates
php-bcmath.x86_64                                                                   5.3.3-48.el6_8                                                            updates
php-dba.x86_64                                                                      5.3.3-48.el6_8                                                            updates
php-devel.x86_64                                                                    5.3.3-48.el6_8                                                            updates
php-embedded.x86_64                                                                 5.3.3-48.el6_8                                                            updates
php-enchant.x86_64                                                                  5.3.3-48.el6_8                                                            updates
php-gd.x86_64                                                                       5.3.3-48.el6_8                                                            updates
php-imap.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-intl.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-ldap.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-mbstring.x86_64                                                                 5.3.3-48.el6_8                                                            updates
php-mysql.x86_64                                                                    5.3.3-48.el6_8                                                            updates
php-odbc.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-pdo.x86_64                                                                      5.3.3-48.el6_8                                                            updates
php-pear.noarch                                                                     1:1.9.4-5.el6                                                             base
php-pecl-apc.x86_64                                                                 3.1.9-2.el6                                                               base
php-pecl-apc-devel.i686                                                             3.1.9-2.el6                                                               base
php-pecl-apc-devel.x86_64                                                           3.1.9-2.el6                                                               base
php-pecl-memcache.x86_64                                                            3.0.5-4.el6                                                               base
php-pgsql.x86_64                                                                    5.3.3-48.el6_8                                                            updates
php-process.x86_64                                                                  5.3.3-48.el6_8                                                            updates
php-pspell.x86_64                                                                   5.3.3-48.el6_8                                                            updates
php-recode.x86_64                                                                   5.3.3-48.el6_8                                                            updates
php-snmp.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-soap.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-tidy.x86_64                                                                     5.3.3-48.el6_8                                                            updates
php-xml.x86_64                                                                      5.3.3-48.el6_8                                                            updates
php-xmlrpc.x86_64                                                                   5.3.3-48.el6_8                                                            updates
php-zts.x86_64                                                                      5.3.3-48.el6_8                                                            updates

Similarly, we need to set php-fpm to boot up.

chkconfig php-fpm on
service php-fpm start

After booting, we can see that php-fpm has started listening on port 9000 through the netstat-tunlp|grep 9000 command.

[root@localhost ~]# netstat -tunlp|grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      2147/php-fpm

Configure nginx to support php programs

Next we demonstrate how to deploy the content of a web service.

Create web directories and files

Let's assume the web directory is/var/www and create and enter it.

mkdir /var/www
cd /var/www

We'll create two new files, an html file and a php file, which we'll see later.

The content of a.html is:

<h1>Hello World</h1>

b.php is:

<?php
phpinfo();
// All PHP information will be printed out
?>

Changing nginx configuration

We use VIM to open the configuration file vim/etc/nginx/conf.d/default.conf for the first site of nginx.

Change the root of line 9 to the directory we specified.

modify

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

Change to

    location / {
        root   /var/www;
        index  index.html index.htm;
    }

Remove comments on lines 30-36 to support php files, and also modify the root and fastcgi_param options to specify our working directory.

modify

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
#    root           html;
#    fastcgi_pass   127.0.0.1:9000;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
#    include        fastcgi_params;
#}

Change to

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include        fastcgi_params;
    }

After saving, perform service nginx reload to reload the nginx configuration.

At this point, we can directly access the file we just created through the browser.

epilogue

The above is a simple installation and configuration of lnmp, which can already parse php programs.In production environments, various changes are often made to their configuration files, and their performance has been optimized.

For example, php's session directory may default to a variety of issues such as lack of write permissions, changes in the number of connections to nginx, and so on.

Once you are familiar with the simple installation of lnmp, you can continue to gain insight and learn to manually compile a specified version of the nginx, php, or mysql service.

Keywords: PHP Nginx MySQL yum

Added by four4swords on Fri, 28 Jun 2019 19:45:31 +0300