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

Example Analysis of Centos 6.8 compiling and installing LNMP Environment

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article focuses on "Centos 6.8 compilation and installation of LNMP environment example analysis", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn the "Centos 6.8 compilation and installation of LNMP environment example analysis" bar!

As soon as the preparatory work

1. Close selinux

Modify the configuration file and take effect permanently after restarting the service.

# sed-I's Charpy selinux.SellinuxAccording to ledUnix g' / etc/selinux/config

The command line settings take effect immediately.

# setenforce 0

two。 If you are an Aliyun ecs user, port 80 is enabled in the security group settings to facilitate debugging.

Second, install nginx

1. Download the source package

Go to the official website of nginx, copy the download address of the latest stable version, and then download it with wget (you can use wget if you need to download the installation package next):

# cd / usr/local/src# wget# tar xvf nginx-1.10.3.tar.gz# yum groupinstall "development tools" # yum-y install gcc wget gcc-c++ automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-extutils-embed pcre-devel openssl-devel

Execution complete.

Enter the decompressed nginx-1.10.3 folder:

Cd / usr/local/src/nginx-1.10.3

Execute the following statement:

. / configure\-- prefix=/usr/local/nginx\-- sbin-path=/usr/sbin/nginx\-- conf-path=/etc/nginx/nginx.conf\-- error-log-path=/var/log/nginx/error.log\-- http-log-path=/var/log/nginx/access.log\-- pid-path=/var/run/nginx.pid\-- lock-path=/var/run/nginx.lock\-- http-client-body-temp-path=/var/tmp/ Nginx/client\-- http-proxy-temp-path=/var/tmp/nginx/proxy\-- http-fastcgi-temp-path=/var/tmp/nginx/fcgi\-- http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\-- http-scgi-temp-path=/var/tmp/nginx/scgi\-- user=nginx\-- group=nginx\-- with-pcre\-- with-http_v2_module\-with-http_ssl_module\-- with-http_realip_module\ -- with-http_addition_module\-- with-http_sub_module\-- with-http_dav_module\-- with-http_flv_module\-- with-http_mp4_module\-- with-http_gunzip_module\-- with-http_gzip_static_module\-- with-http_random_index_module\-- with-http_secure_link_module\-with-http_stub_status_module\-- with-http_auth_request_module\ -- with-mail\-- with-mail_ssl_module\-- with-file-aio\-with-ipv6\-- with-http_v2_module\-- with-threads\-- with-stream\-- with-stream_ssl_module

Execute the compilation when you are finished:

# make & & make install# mkdir-pv / var/tmp/nginx/client

3. Add a sysv startup script.

Edit the script with vim:

# vim / etc/init.d/nginx

Write the following:

#! / bin/sh # # nginx-this script starts and stops the nginx daemon # chkconfig:-85 15 # description: nginx is an http (s) server, http (s) reverse\ # proxy and imap/pop3 proxy server # processname: nginx # config: / etc/nginx/nginx.conf # config: / etc/sysconfig/nginx # pidfile: / var/run/nginx.pid # source function library. . / etc/rc.d/init.d/functions# source networking configuration. . / etc/sysconfig/network# check that networking is up. ["$networking" = "no"] & & exit 0nginx = "/ usr/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file= "/ etc/nginx/nginx.conf" [- f / etc/sysconfig/nginx] & &. / etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxstart () {[- x $nginx] | | exit 5 [- f $nginx_conf_file] | | exit 6 echo-n $"starting $prog:" daemon $nginx-c $nginx_conf_file retval=$? Echo [$retval-eq 0] & & touch $lockfile return $retval} stop () {echo-n $"stopping $prog:" killproc $prog-quit retval=$? Echo [$retval-eq 0] & & rm-f $lockfile return $retvalkillall-9 nginx} restart () {configtest | | return $? Stop sleep 1 start} reload () {configtest | | return $? Echo-n $"reloading $prog:" killproc $nginx-hupretval=$? Echo} force_reload () {restart} configtest () {$nginx-t-c $nginx_conf_file} rh_status () {status $prog} rh_status_q () {rh_status & gt;/dev/null 2 in start) rh_status_q & & exit 0 $1; stop) rh_status_q | | exit 0 $1;; restart | configtest) $1;; reload) rh_status_q | | exit 7 $1;; force-reload force_reload) Status) rh_status;; condrestart | try-restart) rh_status_q | | exit 0;; *) echo $"usage: $0 {start | stop | status | condrestart | try-restart | reload | force-reload | configtest}" exit 2esac

Save exit (press: wq!); you may need to check some of the vim commands a little, otherwise there may be a slight problem with the operation.

Give the script execution permissions:

# chmod + x / etc/init.d/nginx

Add it to the service management list and set it to boot:

# chkconfig-add nginx# chkconfig nginx on

4. Start the service.

# service nginx start

The appearance of this thing means it's a success!

Note: if you report an error [emerg]: getpwnam ("nginx") failed

Solution:

# useradd-s / sbin/nologin-m nginx# id nginx

Third, install mysql

1. Version selection

One thing to understand before installation is that there are many ways to install mysql, each of which is different, so don't get confused.

Such as source code compilation installation (mysql-5.7.17.tar.gz), binary installation (mysql-5.7.17-linux-glibc2.5-i686.tar), nmp installation (the simplest). Here we use the source code to compile and install ourselves.

two。 Prepare the compilation environment

# yum groupinstall "server platform development"development tools"-y # yum install cmake-y

Cmake must be installed in the current version. You can download camke and compile it, or you can install it directly with yum. In the following compilation process, you can make up for what is missing if you report an error.

3. Prepare the mysql database storage directory

# mkdir / mnt/data# groupadd-r mysql# useradd-r-g mysql-s / sbin/nologin mysql# id mysql

4. Change data directory permissions.

# chown-r mysql:mysql / mnt/data

5. Download and decompress the stable version of the source code package downloaded from the official website.

Pay attention to the version when downloading and download the corresponding version. We compile the source code to download a long installation package like mysql-5.7.17.tar.gz, and we need the boost library at the time of installation, version 1.59; you can download the boost library and compile the boost library, or, as I did, download the mysql version with the boost library.

Start decompressing and compiling:

# tar xvf mysql-boost-5.7.17.tar.gz-c / usr/local/src# cd / usr/local/src/mysql-5.7.17# cmake. -dcmake_install_prefix=/usr/local/mysql\-dmysql_datadir=/mnt/data\-dsysconfdir=/etc\-dwith_innobase_storage_engine=1\-dwith_archive_storage_engine=1\-dwith_readline=1\-dwith_ssl=system\-dwith_zlib=system\-dwith_libwrap=0\-dmysql_tcp_port=3306\-dmysql_unix_addr=/tmp/mysql.sock\-ddefault_charset=utf8\-ddefault_collation=utf8_general_ci-ddownload_boost=1\-dwith_boost=/usr/local / mysql/boost/boost_1_59_0\ # make & & make install

6. Modify the permission group of the installation directory

# chown-r mysql:mysql / usr/local/mysql/

7. Initialize the database.

# / usr/local/mysql/bin/mysqld-initialize-user=mysql-basedir=/usr/local/mysql-datadir=/mnt/data/

It should be noted that here is the initialization command for mysql5.7, and all of the following are used:

# / usr/local/mysql/scripts/mysql_install_db-user=mysql-datadir=/mnt/data/

After successful initialization, the initial command of 5.7generates a random root login password that you need to log in with and then modify (you must change the generated random password or you can't do it later). At the end, there is a password like this:

8. Copy Profil

# cp support-files/my-default.cnf / etc/my.cnf

There is another point to note here: the mysql5.7 configuration file needs to modify the key configuration of my.cnf. There are configuration items in the previous default configuration file of mysql5.7, which do not need to be modified manually. The following is the configuration, which is modified according to the actual situation:

[mysqld] basedir = / usr/local/mysqldatadir = / mnt/dataport = 3306socket = / ultrapower/test/mysql/tmp/mysql.socksql_mode=no_engine_substitution,strict_trans_ tables [client] socket = / ultrapower/test/mysql/tmp/mysql.sock

If you add content under [client], notice that sql_mode=no_engine_substitution,strict_trans_tables is placed under [mysqld].

If the error tmp directory is good, go to the corresponding place to create a directory, and then give mysql permission after creation, chown-r mysql:mysql tmp.

9. Set up boot boot

# cp / usr/local/mysql/support-files/mysql.server / etc/init.d/mysqld# chmod + x / etc/init.d/mysql

Register as Boot Boot Service:

# chkconfig mysqld on# chkconfig-add mysqld

Check to see if the setting is successful:

# chkconfig-list mysql

10. Set the path environment variable.

# echo "export path=$path:/usr/local/mysql/bin" > / etc/profile.d/mysql.sh# source / etc/profile.d/mysql.sh

11. Start the service

# service mysqld start

So basically, the mysql is installed.

twelve。 Log in to mysql and change your password

Password generated by mysql-uroot-p

Perform password change:

Alter user 'root'@'localhost' identified by' newpassword'

Fourth, install php-fpm

1. Install the dependency package:

Yum install libmcrypt libmcrypt-devel mhash mhash-devel libxml2 libxml2-devel bzip2 bzip2-devel

There are also a few omissions here. If you make a mistake and indicate what is missing, make up for it by yum.

two。 After downloading the source code package from the official website, start compiling and installing:

# tar xvf php-7.0.16.tar.bz2-c / usr/local/src# cd / usr/local/src/php-7.0.16 execute the following configuration file: #. / configure-- prefix=/usr/local/php\-- with-config-file-scan-dir=/etc/php.d\-- with-config-file-path=/etc\-- with-mysql=/usr/local/mysql\-- with-mysqli=/usr/local/mysql/bin/mysql _ config\-- enable-fpm\-- enable-opcache\-- disable-fileinfo\-- with-jpeg-dir\-- with-iconv-dir=/usr/local\-- with-freetype-dir\-- with-png-dir\-- with-zlib\-- with-libxml-dir=/usr\-- enable-xml\-- enable-bcmath\-- enable-shmop\-enable-exif\-with-curl\-- enable-sysvsem\-- enable-inline-optimization\-- enable -mbregex\-- enable-inline-optimization\-- enable-mbstring\-- with-mcrypt\-- with-gd\-- enable-gd-native-ttf\-- with-openssl\-- with-mhash\-- enable-pcntl\-- enable-sockets\-- with-xmlrpc\-- enable-ftp\-- with-gettext\-enable-zip\-- enable-soap\-- with-bz2

To implement the above configuration, if the following license appears, it is correct before you can start compiling. If there is a problem, it will be solved. Generally, some libraries are missing.

Perform compilation:

# make & & make install

3. Add php and php-fpm configuration files.

# cp / usr/local/src/php-7.0.16/php.ini-production / etc/php.ini# cd / usr/local/php/etc/# cp php-fpm.conf.default php-fpm.conf# sed-I's pid = run/php-fpm.pid@pid = / usr/local/php/var/run/php-fpm.pid@' php-fpm.conf

4. Add a php-fpm startup script.

# cp / usr/local/src/php-7.0.16/sapi/fpm/init.d.php-fpm / etc/init.d/php-fpm# chmod + x / etc/init.d/php-fpm

5. Add php-fpm to the list of services and set to boot.

# chkconfig-add php-fpm# chkconfig-list php-fpm# chkconfig php-fpm on

6. Start the service.

# service php-fpm start

Note: if there is an error during startup:

Warning: nothing matches the include pattern'/ usr/local/etc/php-fpm.d/*.conf' from / usr/local/etc/php-fpm.conf at line 125.errorrig. No pool defined at least one pool section must be specified in config fileerror: failed to post process the configurationerror: fpm initialization failed

Solution: execute cp www.conf.default www.conf to the specified directory

7. Add nginx support for fastcgi

First back up the default configuration file.

# cp / etc/nginx/nginx.conf / etc/nginx/nginx.confbak# cp / etc/nginx/nginx.conf.default / etc/nginx/nginx.conf

Edit / etc/nginx/nginx.conf to add a home page in php format to the supported main page format, like this:

Location / {root / usr/local/nginx/html;index index.php index.html index.htm;}

Uncomment the following:

Location ~\ .php$ {root / usr/local/nginx/html;fastcgi_pass 127.0.0.1 root 9000 fastcgival index index.php;fastcgi_param script_filename / usr/local/nginx/html/$fastcgi_script_name;include fastcgi_params;}

8. Restart nginx

# service nginx reload

9. Whether the test was successful

On the test page of the new index.php created in / usr/local/nginx/html/, the contents are as follows:

At this point, I believe that everyone on the "Centos 6.8 compilation and installation of LNMP environment instance analysis" have a deeper understanding, might as well to practical operation it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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