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 Nginx+MySQL+PHP runtime environment for CentOS

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

Share

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

Most people do not understand the knowledge points of this article "CentOS how to compile and install Nginx+MySQL+PHP runtime environment", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how CentOS compiles and installs Nginx+MySQL+PHP runtime environment" 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 # add

: 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

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

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

The copy code is as follows:

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/src

Tar zxvf cmake-3.6.2.tar.gz

Cd cmake-3.6.2

. / configure

Make

Make install

2. Install mysql

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.6.33.tar.gz # decompression

Cd mysql-5.6.33 # enter the directory

Cmake. -dcmake_install_prefix=/usr/local/mysql-dmysql_datadir=/data/mysql-dsysconfdir=/etc # configuration

Make # compilation

Make install # installation

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

. / scripts/mysql_install_db-- user=mysql-- basedir=/usr/local/mysql-- datadir=/data/mysql # generate mysql system database

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

Cp. / 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 # set the mysql password and press enter y to enter the password twice as prompted

Second, install nginx

1. Install pcre

Cd / usr/local/src

Mkdir / usr/local/pcre

Tar zxvf pcre-8.39.tar.gz

Cd pcre-8.39

. / configure-- prefix=/usr/local/pcre

Make

Make install

2. Install openssl

Cd / usr/local/src

Mkdir / usr/local/openssl

Tar zxvf openssl-1.0.2j.tar.gz

Cd openssl-1.0.2j

. / config-- prefix=/usr/local/openssl

Make

Make install

Vi / etc/profile

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

: wq!

Source / etc/profile

3. Install zlib

Cd / usr/local/src

Mkdir / usr/local/zlib

Tar zxvf zlib-1.2.8.tar.gz

Cd zlib-1.2.8

. / configure-- prefix=/usr/local/zlib

Make

Make 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 # compilation

Make install # installation

7. Install jpeg

Cd / usr/local/src

Tar zxvf jpegsrc.v9b.tar.gz

Cd jpeg-9b

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

Make # compilation

Make install # installation

8. Install libgd

Cd / usr/local/src

Tar zxvf libgd-2.1.1.tar.gz # decompression

Cd libgd-2.1.1 # enter the directory

. / 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/ # configuration

Make # compilation

Make install # installation

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 two commands, otherwise there will be an error in installing php (32-bit system does not need to be executed)

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

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

Cd / usr/local/src

Tar-zvxf php-5.6.26.tar.gz

Cd php-5.6.26

Export ld_library_path=/usr/local/libgd/lib

. / configure-- prefix=/usr/local/php-- with-config-file-path=/usr/local/php/etc-- with-mysql=/usr/local/mysql-- 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-vpx-dir=/usr/local/libvpx/-- with-zlib-dir=/usr/local/zlib-- with-t1lib=/usr/local/t1lib-- with-iconv-- enable-libxml-- enable-xml-- enable-bcmath-- 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 # configuration

Make # compilation

Make install # installation

If there is a compilation error, you can clean it up and compile it again.

Make clean # cleanup

Make # compilation

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

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

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

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

: wq! # Save exit

Set php-fpm to boot

Cp / usr/local/src/php-5.6.26/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

The above is about the content of this article on "how to compile and install Nginx+MySQL+PHP runtime environment for CentOS". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please 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