Preparation
1. Firewall configuration
centos 7.x uses firewall as the firewall by default, here it is changed to iptables firewall .
1. Close the firewall:
systemctl stop firewalld.service #Stop firewall
systemctl disable firewalld.service #Disable firewall from booting up
2. Installation iptables firewall
yum install iptables-services #Install
vi /etc/sysconfig/iptables #Edit firewall configuration file
# 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]
-a input -m state -- state related,established -j accept
-a input -p icmp -j accept
-a input -i lo -j accept
-a input -p tcp - m state --state new -m tcp --dport 22 -j accept
-a input -p tcp -m state --state new -m tcp --dport 80 -j accept
-a input -p tcp -m state --state new -m tcp --dport 3306 -j accept
-a input -j reject --reject-with icmp-host-prohibited
-a forward -j reject --reject-with icmp-host-prohibited
commit
:wq! #Save and exit
systemctl restart iptables.service #Finally Restart the firewall to make the configuration take effect
systemctl enable iptables.service #Set the firewall to start at 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 and exit
setenforce 0 #Make the configuration take effect immediately
3. System Agreement
Software source code package storage location:/usr/local/src
Source code package compilation and installation location:/usr/local/Software name
4. Download the software package
1. Download nginx
http://nginx.org/download/nginx-1.10.3.tar.gz
2. Download mysql
https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.16.tar.gz
3. Download php
http://cn2 .php.net/distributions/php-7.1.2.tar.gz
4. Download cmake (mysql compilation tool)
https://cmake.org/files/v3.7 /cmake-3.7.2.tar.gz
5. Download pcre (supports nginx pseudo-static)
ftp://ftp.csx.cam.ac.uk/pub/software/ programming/pcre/pcre-8.40.tar.gz
6. Download openssl (nginx extension)
https://www.openssl.org/source/openssl-1.1.0e.tar .gz
7. Download zlib (nginx extension)
http://www.zlib.net/zlib-1.2.11.tar.gz
8. Download libmcrypt (php extension)
https://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)
http://download.freenas.org/distfiles/t1lib-5.1.2.tar.gz
11. Download the gd library installation package
https:// github.com/libgd/libgd/releases/download/gd-2.1.1/libgd-2.1.1.tar.gz
12, libvpx (required for gd library)
https:/ /codeload.github.com/webmproject/libvpx/tar.gz/v1.3.0
13. tiff (required for gd library)
http://download.osgeo.org/libtiff/ tiff-4.0.7.tar.gz
14, libpng (required for gd library)
ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng -1.6.28.tar.gz
15, freetype (required for gd library)
http://download.savannah.gnu.org/releases/freetype/freetype-2.7.1. tar.gz
16, jpegsrc (required by gd library)
http://www.ijg.org/files/jpegsrc.v9b.tar.gz
17, boost (required to compile mysql)
https://ufpr.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
The above software package is uploaded to /usr/local/src directory
5. Install compilation tools and library files (use the yum command to install)
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* libxaw-devel libxmu-devel 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 Chapter
The following is to log in to the server remotely using the putty tool, on the command line The following operations
1. Install mysql
1. Install cmake
cd /usr/local/src
tar zxvf cmake-3.7.2.tar.gz
cd cmake-3.7.2
./configure
make
make install
2. Install mysql
cd /usr/local/src
mkdir -p /usr/local/boost
cp boost_1_59_0.tar.gz /usr/local/ boost
groupadd mysql #Add mysql group
useradd -g mysql mysql -s /bin/false #Create user mysql and join the mysql group. Mysql users are not allowed to log in to the system directly
mkdir -p /data/mysql #Create the mysql database storage directory
chown -r mysql:mysql /data/mysql #Set the mysql database storage directory permissions
mkdir -p /usr/local/mysql #Create the mysql installation directory
cd /usr/local/src #Enter the software package storage directory
tar zxvf mysql-5.7.16.tar.gz #Extract
cd mysql-5.7.16 #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 parameters to install the boost software package online. The server needs to be connected to the Internet and the download may fail.
Cmake. -dcmake_install_prefix =/USR/LOCAL/MySQL -DMYSQL_DataDIR =/Data/MySQL -UNIX_ADDR =/TMP/MySQL.SOCK -DMYSQL_USER = m YSQL -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 #Compile
make install # Installation
Compilation error. Before recompiling, you need to delete the files that failed to compile. When recompiling, you need to clear the old object files and cache information.
make clean
rm -f cmakecache.txt
rm -rf /etc/my.cnf #Delete the system default configuration file (no need to delete it if it does not exist by 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 to generate a password by default, --initialize-insecure means not to generate a password, and the password is empty.
See this line [note] a temporary password is generated for root@localhost: i>x18*=rav=7
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 link 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 #Increase execution permissions
chkconfig mysqld on #Add to boot
vi /etc/rc.d/init.d/mysqld #Edit
basedir=/ usr/local/mysql #mysql program installation path
datadir=/data/mysql #mysql database storage directory
:wq! #Save and exit
service mysqld start #Start
vi /etc/profile #Add the mysql service to the system environment variable: add the following line at the end
export path=$path:/usr/local/mysql/bin
:wq! #Save and exit
source /etc/profile #Make the configuration take effect immediately
The following two lines link the myslq library file to the system default location, so that you can compile When using software like php, you don’t need to specify the library file address of mysql.
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 link
mysql_secure_installation #Modify the mysql password, enter the previously generated password csjlm3dytg.d and press Enter, follow the prompts.
press y|y for yes, any other key for no: y #Do you want to install the password security plug-in? Select y
there are three levels of password validation policy: #There are the following password strength options
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 are enough, select 1 to have uppercase, lowercase, special characters, etc.
uninstall plugin validate_password; #Uninstall password strength plugin
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' ; #Log in to the mysql console to modify
alter user 'root'@'localhost' identified with mysql_native_password as ' 123456'; #Change password
2. Install nginx
1. Install pcre
cd /usr/local/src
mkdir /usr/local/pcre
tar zxvf pcre-8.40.tar.gz
cd pcre-8.40
./configure --prefix=/usr/local /pcre
make
make install
2. Install openssl
cd /usr/local/src
mkdir /usr/ local/openssl
tar zxvf openssl-1.1.0e.tar.gz
cd openssl-1.1.0e
./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.11.tar.gz
cd zlib-1.2.11
./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.3.tar.gz
cd nginx-1.10.3
./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.1.0e --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.40
注意:--with-openssl=/usr/local/src/openssl-1.1.0e --with-zlib=/usr/local/src/zlib-1.2.11 --with-pcre=/usr/local/src/pcre-8.40指向的是源码包解压的路径,而不是安装的路径,否则会报错
make
make install
/usr/local/nginx/sbin/nginx #启动nginx
设置nginx开机启动
vi /etc/rc.d/init.d/nginx #编辑启动文件添加下面内容
############################################################ #!/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: /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 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) nginx_conf_file="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -v 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -m -s /bin/nologin $user fi options=`$nginx -v 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -r $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $nginx_conf_file ] || exit 6 make_dirs 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 $retval } restart() { #configtest || return $? stop sleep 1 start } reload() { #configtest || return $? echo -n $"reloading $prog: " killproc $nginx -hup retval=$? 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" 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|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac ############################################################
:wq! #保存退出
chmod 775 /etc/rc.d/init.d/nginx #赋予文件执行权限
chkconfig nginx on #设置开机启动
/etc/rc.d/init.d/nginx restart #重启
在浏览器中打开服务器ip地址,会看到下面的界面,说明nginx安装成功。
三、安装php
1、安装yasm
cd /usr/local/src
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install
2、安装libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
3、安装libvpx
cd /usr/local/src
tar zxvf libvpx-1.3.0.tar.gz
cd libvpx-1.3.0
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make
make install
4、安装tiff
cd /usr/local/src
tar zxvf tiff-4.0.7.tar.gz
cd tiff-4.0.7
./configure --prefix=/usr/local/tiff --enable-shared
make
make install
5、安装libpng
cd /usr/local/src
tar zxvf libpng-1.6.28.tar.gz
cd libpng-1.6.28
./configure --prefix=/usr/local/libpng --enable-shared
make
make install
6、安装freetype
cd /usr/local/src
tar zxvf freetype-2.7.1.tar.gz
cd freetype-2.7.1
./configure --prefix=/usr/local/freetype --enable-shared
make
make install
7、安装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、安装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/lib64 --with-tiff=/usr/local/tiff --with-vpx=/usr/local/libvpx
make
make install
说明:如果libgd编译失败,可以先跳过,直接使用系统默认的2.1.0版本,在编译php的时候把参数--with-gd=/usr/local/libgd修改为--with-gd即可。
9、安装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、安装php
注意:如果系统是64位,请执行以下两条命令,否则安装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.1.2.tar.gz
cd php-7.1.2
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-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 --enable-mysqlnd
make #编译
make install #安装
说明:如果提示libgd版本错误,把php编译参数--with-gd=/usr/local/libgd修改为--with-gd即可。
cp php.ini-production /usr/local/php/etc/php.ini #复制php配置文件到安装目录
rm -rf /etc/php.ini #删除系统自带配置文件
ln -s /usr/local/php/etc/php.ini /etc/php.ini #Add a soft link to the /etc directory
cp /usr/local/php/etc/php- fpm.conf.default /usr/local/php/etc/php-fpm.conf #Copy the template file to the 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 #Edit
pid = run /php-fpm.pid #Cancel the preceding semicolon
:wq! #Save and 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 #Edit
user = www #Set the php-fpm running account to be www
group = www #Set the php-fpm running group to be www
Set php-fpm to start at startup
cp /usr/local/src/php-7.1.2/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 execution permissions
chkconfig php-fpm on #Set up startup
vi /usr/local/ php/etc/php.ini #Edit configuration file
Find: disable_functions =
Modify 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, po six_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_mk fifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times, posix_ttyname,posix_uname
#Lists the functions that can be disabled in PHP. If some programs need to use this function, it can be deleted and undisabled.
Found: ;date.timezone =
Modified to: date.timezone = prc #Set time zone
Found: expose_php = on
Modified to: expose_php = off #Suppress display of php version information
Found: short_open_tag = off
Modify to: short_open_tag = on #Support php short tag
Find opcache.enable=0
Modify to opcache.enable=1 #php supports opcode caching
Found:;opcache.enable_cli=1 #php supports opcode caching
Modify to: opcache.enable_cli= 0
Add in the last line: zend_extension=opcache.so #Enable opcode caching function
:wq! #Save and exit
Configure nginx to support php
vi /usr/local/nginx/conf/nginx.conf
Modify the /usr/local/nginx/conf/nginx.conf configuration file and make the following modifications
user www www; # Remove the comments from the first line of user and modify the nginx running group to www www; it must be the same as the user and group configurations in /usr/local/php/etc/php-fpm.conf, otherwise an error will occur during 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 the location of the fastcgi server part, pay attention to the parameters of the fastcgi_param line, change it to $document_root$fastcgi_script_name, or use the absolute path
/etc/init.d/nginx restart #Restart nginx
service php-fpm start #Start php-fpm
Testing article
cd /usr/local/nginx/html/ #Enter nginx default website root directory
rm -rf /usr/local/nginx/html/* #Delete the default test page
vi index.php #New index.php file
phpinfo();
?>
:wq! #Save Exit
chown www.www /usr/local/nginx/html/ -r #Set directory owner
chmod 700 /usr/local/nginx/html/ -r #Set directory permissions
Open the server IP address in the browser, you will see the following interface
The above is the detailed content of How to compile and install Nginx+MySQL+PHP on CentOS. For more information, please follow other related articles on the PHP Chinese website!