Home  >  Article  >  Backend Development  >  Detailed steps for LNMP compilation and installation under Centos7 system

Detailed steps for LNMP compilation and installation under Centos7 system

不言
不言forward
2019-01-01 09:43:563536browse

The content of this article is about the detailed steps of LNMP compilation and installation under Centos7 system. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

demo1

demo2

In order to avoid taking a long time to install every time, record the detailed tutorial of compilation and installation

The PHP download address of this article:

`wget http://cn2.php.net/distributions/php-7.2.0.tar.gz`

This article’s NGINX download address:

`wget http://nginx.org/download/nginx-1.12.0.tar.gz`

View the current directory: pwd

Steps to install NGINX:
The first step: Install the files that are required for compilation

yum install gcc gcc-c openssl openssl-devel cyrus-sasl-md5

If yum prompts that there is no yum, remember to install yum first. After the result is completed, enter the address of the download directory to decompress the NGINX installation package

解压到当前目录: tar -zxvf nginx-1.12.0.tar.gz

进入到解压后的安装目录
        cd nginx-1.12.0

Since the Linux compilation command is executed in one line, it is not difficult for the reader to copy it line by line.

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=../pcre-8.39 --with-zlib=../zlib-1.2.8

It should be noted that according to the compilation method above, the first installation can be successful. After uninstalling, the second installation will prompt pcre zlib did not find the corresponding path error. Therefore, the second compilation path should be changed to

./configure --prefix=/usr/local/nginx --with-http_ssl_module

. It should be noted that it is the directory address of the configuration installation--not the crossbar--

There are also some personalized directories The installation address, this article uses the default installation directory address

Configure the installation path, compile and install

make && make install

The installation will basically be successful without any accidents If there is a problem with the installation configuration path, you can reset the installation path and install it according to the above steps.

make clean  重置编译路径时,先执行

After the installation is completed, start nginx:

[root@VM_31_16_centos down]# /usr/local/nginx/sbin/nginx

Check whether nginx starts successfully as shown in the figure below:

ps -ef | grep nginx

Access nginx according to the IP address or domain name of the service. The following figure indicates successful startup.

There are two steps to start the function.

第一步骤:加入到开机运行
vim /etc/rc.local

The added code is as follows:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf &

Second step: Add to environment variables

[root@VM_31_16_centos ~]# vim /etc/profile

Add

export PATH="$PATH:/usr/local/nginx/sbin:"

wq in the last line: Save and exit
Execute the update to take effect. Modified content:

source /etc/profile

This completes the nginx compilation and installation. Adding environment variables eliminates the need to execute files in the installation directory.
You can view it directly by using the global command

nginx -v

The execution result is shown in the figure below:

nginx version: nginx/1.12.0

Written today Here, I will add the new PHP compilation and installation later.
Start the installation of PHP-FPM
First install the expansion package required for compilation:

yum install gcc gcc-c libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel

If nothing happens, the installation will basically be successful. Enter the PHP7.2 download directory and extract it to the current directory

cd /down/php-7.2.0
tar -zxvf php-7.2.0.tar.gz

Start configuring the compilation path

./configure --prefix=/usr/local/php7.2 --with-config-file-path=/usr/local/php7 .2/etc--enable mbstring --with-libxml-dir=/usr --enable-soap --with-curl --with-zlib --with-gd --with-pdo-sqlite --with-pdo -mysql --with-mysqli --with-mysql-sock --enable-mysqlnd --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable- sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex --enable-exif --enable-bcmath --with-mhash --enable-zip --with-pcre-regex --enable-ftp -- with-kerberos --with-xmlrpc --with-fpm-user=www --disable-fileinfo

Compile and install:

make && make install

Don’t rush to start PHP-FPM here. , PHP must be associated with the Nginx configuration file to parse the php file
Enter the PHP installation directory and copy a configuration file

cd /usr/local/php7.2/etc
cp php-fpm.conf.default php-fpm.conf
vim  php-fpm.conf

Edit the content as follows:

pid = run/php-fpm.pid Remove the previous

#According to the configuration of the last line of php-fpm.conf, enter the loaded configuration file

cd /usr/local/php7.2/etc/php-fpm.d
cp www.conf.default www.conf
vim www.conf

The address that needs to be edited
user = www       Username to join
group = www   User group to join

Ensure that the ports monitored by the system are not in conflict
listen = 127.0.0.1:9000 The default does not need to be modified

After these basic settings are set, start PHP-FPM

/usr/local/php7.2/sbin/php-fpm

Check whether the process is started:

ps -ef | grep php

You can see that there are not only the root process but also the process of the newly added www user group. In this way, PHP has been started successfully! ! !
The next step is to configure nginx to parse the PHP file configuration.

Make sure that the user name and user group configured in PHP are consistent.

Enter the Nginx configuration file directory, edit and modify the line

user www www;
worker_processes 3;

**The configured path address must be an absolute path address**
Similarly starting Nginx also requires the same www user group as PHP-FPM
After modifying the configuration, restart the Nginx server

/usr/local/nginx/sbin/nginx -s reload
Check whether nginx has started the changed configuration
ps -ef | grep nginx
The execution result is as shown in the figure below, indicating that the configuration has been successful.

Execute the PHP file according to the domain name or corresponding IP address. The successful execution result is as shown below, and the PHP file can be successfully parsed

接下来开始安装mysql,因为的mysql 编译时间较长,选择了yum 安装节省时间达到的效果一致

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm 
rpm -ivh mysql57-community-release-el7-8.noarch.rpm 
yum -y install mysql-server

按照步骤就可以安装成功。yum 安装也可以指定目录,这样会改变MySQL默认的启动配置文件的路径地址,不适合新手安装。

指定安装目录: yum --installroot=/usr/local/mysql --releasever=/ -y install mysql-server

MySQL启动和关闭

开启MySQL服务器方式一service mysqld restart
开启MySQL服务器方式二:    systemctl start mysqld
关闭MySQL服务器:    systemctl stop mysqld

MySQL第一次登陆会随机生成一个随机登陆密码,查看方式如下:

grep "password" /var/log/mysqld.log

登陆成功后,可以手动修改登陆密码,记得刷新权限

方式一:alter user 'root'@'localhost' identified by '123456';
方式二:update mysql.user set authentication_string=password('root') where user='root';

刷新权限: flush privileges

最后一个就是开启远程链接权限了,mysql默认是没有开始远程连接属性的。下面是仅供测试连接,开放了所有连接权限

mysql> use mysql;
Database changed
mysql> grant all privileges  on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select host,user,password from user;
host user password
localhost root *A731AEBFB621E354CD41BAF207D884A609E81F5E
192.168.1.1 root *A731AEBFB621E354CD41BAF207D884A609E81F5E
% root *A731AEBFB621E354CD41BAF207D884A609E81F5E

3 rows in set (0.00 sec)

The above is the detailed content of Detailed steps for LNMP compilation and installation under Centos7 system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete