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 compile and install Nginx1.10.1+MySQL5.7.14+PHP7.0.11 for CentOS

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

Share

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

Today, I would like to share with you the relevant knowledge points about how to compile and install Nginx1.10.1+MySQL5.7.14+PHP7.0.11 in CentOS. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

I. Firewall configuration

Centos 7.x uses firewall as the firewall by default, which is changed to iptables firewall here.

1. Close firewall:

Systemctl stop firewalld.service # stop firewall

Systemctl disable firewalld.service # prevents firewall from booting

2. Install iptables firewall

Yum install iptables-services # installation

Vi / etc/sysconfig/iptables # Editing Firewall profile

# sample configuration for iptables service# you can edit this manually or use system-config-firewall# please do not ask us to add additional ports/services to this default configuration*filter:input accept [0:0]: forward accept [0:0]: output accept [0:0]-an input-m state-- state related Established-j accept-an input-p icmp- j accept-an input-I lo-j accept-an input-p tcp-m state-- state new-m tcp-- dport 22-j accept-an input-p tcp-m state-- state new-m tcp-- dport 80-j accept-an input-p tcp-m state-state new-m tcp-dport 3306-j accept-an input-j reject--reject-with icmp-host-prohibited-a forward-j reject--reject-with icmp-host-prohibitedcommit

: wq! # Save exit

Systemctl restart iptables.service # finally restart the firewall to make the configuration effective

Systemctl enable iptables.service # set the firewall to boot

/ usr/libexec/iptables/iptables.init restart # restart the firewall

2. Close selinux

Vi / etc/selinux/config

# selinux=enforcing # comment out

# selinuxtype=targeted # comment out

Selinux=disabled # increased

: wq! # Save exit

Setenforce 0 # makes the configuration effective immediately

III. System agreement

Software source code package location: / usr/local/src

Source package compilation installation location: / usr/local/ software name

Download the software package

1. Download nginx

Http://nginx.org/download/nginx-1.10.1.tar.gz

2. Download mysql

Http://cdn.mysql.com/downloads/mysql-5.6/mysql-5.6.33.tar.gz

3. Download php

Http://cn2.php.net/distributions/php-5.6.26.tar.gz

4. Download cmake (mysql compilation tool)

Https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz

5. Download pcre (nginx pseudo-static is supported)

Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

6. Download openssl (nginx extension)

Https://www.openssl.org/source/openssl-1.0.2j.tar.gz

7. Download zlib (nginx extension)

Http://zlib.net/zlib-1.2.8.tar.gz

8. Download libmcrypt (php extension)

Http://nchc.dl.sourceforge.net/project/mcrypt/libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

9. Download yasm (php extension)

Http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

10. T1lib (php extension)

Ftp://sunsite.unc.edu/pub/linux/libs/graphics/t1lib-5.1.2.tar.gz

11. Download the gd library installation package

Https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.1.tar.gz

12. Libvpx (required for gd library)

Http://ftp.osuosl.org/pub/blfs/conglomeration/libvpx/libvpx-1.6.0.tar.bz2

13. Tiff (required for gd library)

Http://download.osgeo.org/libtiff/tiff-4.0.6.tar.gz

14. Libpng (required for gd library)

Ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.25.tar.gz

15. Freetype (required for gd library)

Http://download.savannah.gnu.org/releases/freetype/freetype-2.7.tar.gz

16. Jpegsrc (required for gd library)

Http://www.ijg.org/files/jpegsrc.v9b.tar.gz

17. Boost (required to compile mysql)

Http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

The above packages are uploaded to the / usr/local/src directory

Install compilation tools and library files (install using yum command)

Yum install-y apr* autoconf automake bison bzip2 bzip2* cloog-ppl compat* cpp curl curl-devel fontconfig fontconfig-devel freetype freetype* freetype-devel gcc gcc-c++ gtk+-devel gd gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libxpm* libxml* libtiff libtiff* make mpfr ncurses* ntp openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet t1lib t1lib * nasm nasm* wget zlib-devel

Installation section

The following is done under the command line by logging in remotely to the server

First, install mysql

1. Install cmake

Cd / usr/local/srctar zxvf cmake-3.6.2.tar.gzcd cmake-3.6.2./configuremakemake install

2. Install mysql

Mkdir-p / usr/local/boost

Cd / usr/local/src

Cp boost_1_59_0.tar.gz / usr/local/boost

Groupadd mysql # add mysql Group

Useradd-g mysql mysql-s / bin/false # create a user mysql and join the mysql group, and do not allow mysql users to log in directly to the system

Mkdir-p / data/mysql # create mysql database storage directory

Chown-r mysql:mysql / data/mysql # set the permissions of the mysql database storage directory

Mkdir-p / usr/local/mysql # create the mysql installation directory

Cd / usr/local/src # enters the package storage directory

Tar zxvf mysql-5.7.14.tar.gz # decompression

Cd mysql-5.7.14 # enter the directory

Cmake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dwith_innobase_storage_engine=1-ddefault_charset=utf8-ddefault_collation=utf8_general_ci-dwith_embedded_server=off-dwith_boost=/usr/local/boost

Note: you can use the-ddownload_boost=1-dwith_boost=/usr/local/boost parameter to install the boost package online, which requires the server to connect to the network, so it is easy to download and fail.

Cmake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dmysql_unix_addr=/tmp/mysql.sock-dmysql_user=mysql-ddefault_charset=utf8-ddefault_collation=utf8_general_ci-denabled_local_infile=on-dwith_innobase_storage_engine=1-dwith_federated_storage_engine=1-dwith_blackhole_storage_engine=1-dwithout_example_storage_engine=1-dwith_embedded_server=off-ddownload_boost=1-dwith_boost=/usr/local/boost

Make # compilation

Make install # installation

Compilation error, before recompilation to delete the failed file, recompile, need to clear the old object files and cache information.

Make clean

Rm-f cmakecache.txt

Rm-rf / etc/my.cnf # Delete the default configuration file of the system (do not delete it if there is no default)

Cd / usr/local/mysql # enter the mysql installation directory

. / bin/mysqld-- user=mysql-- initialize-- basedir=/usr/local/mysql-- datadir=/data/mysql # generate mysql system database

-- initialize means the password is generated by default,-- initialize-insecure means no password is generated, and the password is empty.

See this line [note] a temporary password is generated for root@localhost: csjlm3dytg.d

Cp / usr/local/mysql/support-files/my-default.cnf / usr/local/mysql/my.cnf

Ln-s / usr/local/mysql/my.cnf / etc/my.cnf # soft connections added to the / etc directory

Cp / usr/local/mysql/support-files/mysql.server / etc/rc.d/init.d/mysqld # add mysql to the system startup

Chmod 755 / etc/init.d/mysqld # increased execution permissions

Chkconfig mysqld on # join Boot Boot

Vi / etc/rc.d/init.d/mysqld # editing

Basedir=/usr/local/mysql # mysql Program installation path

Datadir=/data/mysql # mysql database storage directory

: wq! # Save exit

Service mysqld start # Startup

Vi / etc/profile # adds the mysql service to the system environment variable: add the following line at the end

Export path=$path:/usr/local/mysql/bin

: wq! # Save exit

Source / etc/profile # makes the configuration effective immediately

The following two lines link the library files of myslq to the default location of the system, so that you don't have to specify the library file address of mysql when compiling software like php.

Ln-s / usr/local/mysql/lib/mysql / usr/lib/mysql

Ln-s / usr/local/mysql/include/mysql / usr/include/mysql

Mkdir / var/lib/mysql # create directory

Ln-s / tmp/mysql.sock / var/lib/mysql/mysql.sock # add soft links

Mysql_secure_installation # modify the mysql password, enter the previously generated secret csjlm3dytg.d enter, and follow the prompts.

Press y | y for yes, any other key for no: y # do you want to install password security plug-ins? Select y

There are three levels of password validation policy: # there are several password strength choices

Low length > = 8

Medium length > = 8, numeric, mixed case, and special characters

Strong length > = 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = low, 1 = medium and 2 = strong: 0 # Select 0, as long as 8 digits, select 1 with uppercase, lowercase, special characters, etc.

Related operations: enter the mysql console

Uninstall plugin validate_password; # Uninstall the password strength plugin

Mysqladmin-uroot-p password 123456 # change password

Set password for 'root'@'localhost' = password (' 123456'); # Log in to the mysql console to modify

Alter user user () identified by '123456password; # change password

Second, install nginx

1. Install pcre

Cd / usr/local/srcmkdir / usr/local/pcretar zxvf pcre-8.39.tar.gzcd pcre-8.39./configure-- prefix=/usr/local/pcremakemake install

2. Install openssl

Cd / usr/local/srcmkdir / usr/local/openssltar zxvf openssl-1.0.2j.tar.gzcd openssl-1.0.2j./config-- prefix=/usr/local/opensslmakemake installvi / etc/profileexport pathogens pathomandized.usrUnix localle.opensslbank binRom wqrabbit source / etc/profile

3. Install zlib

Cd / usr/local/srcmkdir / usr/local/zlibtar zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8./configure-- prefix=/usr/local/zlibmakemake install

4. Install nginx

Groupadd www

Useradd-g www www-s / bin/false

Cd / usr/local/src

Tar zxvf nginx-1.10.1.tar.gz

Cd nginx-1.10.1

/ configure-- prefix=/usr/local/nginx-- without-http_memcached_module-- user=www-- group=www-- with-http_stub_status_module-- with-http_ssl_module-- with-http_gzip_static_module-- with-openssl=/usr/local/src/openssl-1.0.2j-- with-zlib=/usr/local/src/zlib-1.2.8-- with-pcre=/usr/local/src/pcre-8.39

Note:-- with-openssl=/usr/local/src/openssl-1.0.2j-- with-zlib=/usr/local/src/zlib-1.2.8-- with-pcre=/usr/local/src/pcre-8.39 points to the path of decompression of the source package, not the path of installation, otherwise an error will be reported.

Make

Make install

/ usr/local/nginx/sbin/nginx # launch nginx

Set nginx to boot

Vi / etc/rc.d/init.d/nginx # Edit startup file to add the following

#! / bin/sh## nginx-this script starts and stops the nginx daemon## chkconfig:-85 "description: nginx is an http (s) server Http (s) reverse\ # proxy and imap/pop3 proxy server# processname: nginx# config: / etc/nginx/nginx.conf# config: / usr/local/nginx/conf/nginx.conf# pidfile: / usr/local/nginx/logs/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/local/nginx/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file= "/ usr/local/nginx/conf/nginx.conf" [- f / etc/sysconfig/nginx] & &. / etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs () {# make required directoriesuser= `$nginx-v 2 > & 1 | grep "configure arguments:" | sed's / [^ *] *-user=\ ([^] *\). * /\ 1if [- z "`grep $user / etc/ passwd`"]; thenuseradd-m-s / bin/nologin $userfioptions= `$ nginx-v 2 > & 1 | grep 'configure arguments:' `for opt in $options; doif [`echo $opt | grep'. *-temp-path'`] Thenvalue= `echo $opt | cut-d "="-f 2`if [!-d "$value"] Then# echo "creating" $valuemkdir-p $value & & chown-r $user $valuefifidone} start () {[- x $nginx] | | exit 5 [- f $nginx_conf_file] | | exit 6make_dirsecho-n $"starting $prog:" daemon $nginx-c $nginx_conf_fileretval=$?echo [$retval-eq 0] & & touch $lockfilereturn $retval} stop () {echo-n $"stopping $prog:" killproc $prog-quitretval=$?echo [$retval-eq 0] & rm-f $lockfilereturn $retval} restart () {# configtest | | return $? stopsleep 1start} 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 > / dev/null 2 > & 1} case "$1" instart) rh_status_q & & exit 0 $1 ; stop) rh_status_q | | exit 0 $1x restart | configtest) $1 * reload) rh_status_q | | exit 7 $1 * force_reload;;status) rh_status;;condrestart | try-restart) restart | | exit 0 *) echo $"usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-reload | configtest}" exit 2esac###

: wq! # Save exit

Chmod 775 / etc/rc.d/init.d/nginx # gives file execution permissions

Chkconfig nginx on # set boot up

/ etc/rc.d/init.d/nginx restart # restart

Open the server ip address in the browser

Third, install php

1. Install yasm

Cd / usr/local/src

Tar zxvf yasm-1.3.0.tar.gz

Cd yasm-1.3.0

. / configure

Make

Make install

2. Install libmcrypt

Cd / usr/local/src

Tar zxvf libmcrypt-2.5.8.tar.gz

Cd libmcrypt-2.5.8

. / configure

Make

Make install

3. Install libvpx

Cd / usr/local/src

Tar xvf libvpx-1.6.0.tar.bz2

Cd libvpx-1.6.0

. / configure-- prefix=/usr/local/libvpx-- enable-shared-- enable-vp9

Make

Make install

4. Install tiff

Cd / usr/local/src

Tar zxvf tiff-4.0.6.tar.gz

Cd tiff-4.0.6

. / configure-prefix=/usr/local/tiff-enable-shared

Make

Make install

5. Install libpng

Cd / usr/local/src

Tar zxvf libpng-1.6.25.tar.gz

Cd libpng-1.6.25

. / configure-prefix=/usr/local/libpng-enable-shared

Make

Make install

6. Install freetype

Cd / usr/local/src

Tar zxvf freetype-2.7.tar.gz

Cd freetype-2.7

. / configure-prefix=/usr/local/freetype-enable-shared

Make

Make install

7. Install jpeg

Cd / usr/local/src

Tar zxvf jpegsrc.v9b.tar.gz

Cd jpeg-9b

. / configure-prefix=/usr/local/jpeg-enable-shared

Make

Make install

8. Install libgd

Cd / usr/local/src

Tar zxvf libgd-2.1.1.tar.gz

Cd libgd-2.1.1

. / configure-- prefix=/usr/local/libgd-- enable-shared-- with-jpeg=/usr/local/jpeg-- with-png=/usr/local/libpng-- with-freetype=/usr/local/freetype-- with-fontconfig=/usr/local/freetype-- with-xpm=/usr/-- with-tiff=/usr/local/tiff-- with-vpx=/usr/local/libvpx

Make

Make install

Note: if libgd compilation fails, you can skip it and directly use the default version 2.1.0 of the system. When compiling php, change the parameter-- with-gd=/usr/local/libgd to-- with-gd.

9. Install t1lib

Cd / usr/local/src

Tar zxvf t1lib-5.1.2.tar.gz

Cd t1lib-5.1.2

. / configure-prefix=/usr/local/t1lib-enable-shared

Make without_doc

Make install

10. Install php

Note: if the system is 64-bit, execute the following command, otherwise there will be an error in installing php.

\ cp-frp / usr/lib64/libltdl.so* / usr/lib/

\ cp-frp / usr/lib64/libxpm.so* / usr/lib/

Cd / usr/local/src

Tar-zvxf php-7.0.11.tar.gz

Cd php-7.0.11

Export ld_library_path=/usr/local/libgd/lib

. / configure-- prefix=/usr/local/php-- with-config-file-path=/usr/local/php/etc-- with-mysqli=/usr/local/mysql/bin/mysql_config-- with-mysql-sock=/tmp/mysql.sock-- with-pdo-mysql=/usr/local/mysql-- with-gd=/usr/local/libgd-- with-png-dir=/usr/local/libpng-- with-jpeg-dir=/usr/local/jpeg-- with-freetype-dir=/usr/local / freetype-- with-xpm-dir=/usr/lib64-- with-zlib-dir=/usr/local/zlib-- with-iconv-- enable-libxml-- enable-xml-- enable-shmop-- enable-sysvsem-- enable-inline-optimization-- enable-opcache-- enable-mbregex-- enable-fpm-- enable-mbstring-- enable-ftp-- enable-gd-native-ttf-with-openssl-enable-pcntl-- enable-sockets-- with-xmlrpc-- enable -zip-enable-soap-- without-pear-- with-gettext-- enable-session-- with-mcrypt-- with-curl-- enable-ctype-- enable-mysqlnd

Make # compilation

Make install # installation

Cp php.ini-production / usr/local/php/etc/php.ini # copy the php configuration file to the installation directory

Rm-rf / etc/php.ini # Delete the configuration file that comes with the system

Ln-s / usr/local/php/etc/php.ini / etc/php.ini # add soft link to / etc directory

Cp / usr/local/php/etc/php-fpm.conf.default / usr/local/php/etc/php-fpm.conf # copy template file as php-fpm configuration file

Ln-s / usr/local/php/etc/php-fpm.conf / etc/php-fpm.conf # add a soft connection to the / etc directory

Vi / usr/local/php/etc/php-fpm.conf # editing

Pid = run/php-fpm.pid # cancel the previous semicolon

: wq! # Save exit

Cp / usr/local/php/etc/php-fpm.d/www.conf.default / usr/local/php/etc/php-fpm.d/www.conf

Vi / usr/local/php/etc/php-fpm.d/www.conf # editing

User = www # set the php-fpm running account to www

Group = www # set the php-fpm running group to www

Set php-fpm to boot

Cp / usr/local/src/php-7.0.11/sapi/fpm/init.d.php-fpm / etc/rc.d/init.d/php-fpm # copy php-fpm to the startup directory

Chmod + x / etc/rc.d/init.d/php-fpm # add execute permission

Chkconfig php-fpm on # set boot up

Vi / usr/local/php/etc/php.ini # Edit configuration file

Find: disable_functions =

Modified to: disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups Posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

# list the functions that can be disabled by php. If some programs need to use this function, you can delete it and undisable it.

Find:; date.timezone =

Change it to: date.timezone = prc # set time zone

Find: expose_php = on

Modified to: expose_php = off # suppresses the display of php version information

Find: short_open_tag = off

Modified to: short_open_tag = on # supports php short tags

Find opcache.enable=0.

Modified to support opcode caching for opcache.enable=1 # php

Found:; opcache.enable_cli=1 # php supports opcode caching

Modified to: opcache.enable_cli=0

On the last line, add: zend_extension=opcache.so # to enable opcode caching

: wq! # Save exit

Configure nginx to support php

Vi / usr/local/nginx/conf/nginx.conf

To modify the / usr/local/nginx/conf/nginx.conf configuration file, the following modifications are required

The first line of user www www; # user is uncommented, and the nginx running group is changed to www www;. It must be the same as the user,group configuration in / usr/local/php/etc/php-fpm.conf, otherwise there will be errors in php operation.

Index index.html index.htm index.php; # add index.php

# 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 $document_root$fastcgi_script_name

Include fastcgi_params

}

# Uncomment part of fastcgi server location, note the parameter of fastcgi_param line, change it to $document_root$fastcgi_script_name, or use absolute path

/ etc/init.d/nginx restart # restart nginx

Service php-fpm start # launch php-fpm

Test piece

Cd / usr/local/nginx/html/ # enter the nginx default website root directory

Rm-rf / usr/local/nginx/html/* # Delete the default test page

Vi index.php # create a new index.php file

: wq! # Save exit

Chown www.www / usr/local/nginx/html/-r # sets the directory owner

Chmod 700 / usr/local/nginx/html/-r # set directory permissions

These are all the contents of the article "how to compile and install Nginx1.10.1+MySQL5.7.14+PHP7.0.11 for CentOS". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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