安装PHP:
依赖包安装:
yum install -y gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel
获取PHP的安装介质:
http://php.net/get/php-7.0.9.tar.gz/from/a/mirror
上传PHP介质到服务器,并解压:
[root@linuxme nginx-1.11.3]# cd /software [root@linuxme software]# ls -ltr total 19480 -rw-r--r-- 1 root root 938045 Aug 15 20:52 nginx-1.11.3.tar.gz drwxr-xr-x 9 1001 1001 4096 Aug 15 20:59 nginx-1.11.3 -rw-r--r-- 1 root root 18998880 Aug 15 21:17 php-7.0.9.tar.gz [root@linuxme software]# tar -xzf php-7.0.9.tar.gz [root@linuxme software]# [root@linuxme software]# ls -ltr total 19484 drwxr-xr-x 14 1000 1000 4096 Jul 20 21:11 php-7.0.9 -rw-r--r-- 1 root root 938045 Aug 15 20:52 nginx-1.11.3.tar.gz drwxr-xr-x 9 1001 1001 4096 Aug 15 20:59 nginx-1.11.3 -rw-r--r-- 1 root root 18998880 Aug 15 21:17 php-7.0.9.tar.gz [root@linuxme software]# cd php-7.0.9 [root@linuxme php-7.0.9]# ls acinclude.m4 ext Makefile.frag php.ini-production README.STREAMS stamp-h.in aclocal.m4 EXTENSIONS Makefile.gcov README.EXT_SKEL README.SUBMITTING_PATCH stub.c build footer Makefile.global README.GIT-RULES README.TESTING tests buildconf generated_lists makerpm README.input_filter README.TESTING2 travis buildconf.bat genfiles missing README.MAILINGLIST_RULES README.UNIX-BUILD-SYSTEM TSRM CODING_STANDARDS header mkinstalldirs README.md README.WIN32-BUILD-SYSTEM UPGRADING config.guess INSTALL netware README.namespaces run-tests.php UPGRADING.INTERNALS config.sub install-sh NEWS README.NEW-OUTPUT-API sapi vcsclean configure LICENSE pear README.PARAMETER_PARSING_API scripts win32 configure.in ltmain.sh php7.spec.in README.REDIST.BINS server-tests-config.php Zend CONTRIBUTING.md main php.gif README.RELEASE_PROCESS server-tests.php CREDITS makedist php.ini-development README.SELF-CONTAINED-EXTENSIONS snapshot [root@linuxme php-7.0.9]#
编译:configure
[root@linuxme php-7.0.9]# ./configure --prefix=/usr/local/php-7.0.9 \ > --with-config-file-path=/usr/local/php-7.0.9/etc \ > --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd \ > --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local \ > --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar \ > --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd \ > --with-mysqli=mysqlnd --enable-dom --enable-xml \ > --enable-fpm --with-libdir=lib64 (... ... 过多的输出。) checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... yes creating libtool appending configuration tag "CXX" to libtool Generating files configure: creating ./config.status creating main/internal_functions.c creating main/internal_functions_cli.c +--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP. config.status: creating php7.spec config.status: creating main/build-defs.h config.status: creating scripts/phpize config.status: creating scripts/man1/phpize.1 config.status: creating scripts/php-config config.status: creating scripts/man1/php-config.1 config.status: creating sapi/cli/php.1 config.status: creating sapi/fpm/php-fpm.conf config.status: creating sapi/fpm/www.conf config.status: creating sapi/fpm/init.d.php-fpm config.status: creating sapi/fpm/php-fpm.service config.status: creating sapi/fpm/php-fpm.8 config.status: creating sapi/fpm/status.html config.status: creating sapi/cgi/php-cgi.1 config.status: creating ext/phar/phar.1 config.status: creating ext/phar/phar.phar.1 config.status: creating main/php_config.h config.status: main/php_config.h is unchanged config.status: executing default commands [root@linuxme php-7.0.9]#
安装:make
[root@linuxme php-7.0.9]# make (... ... 过多的输出。) d_ini_scanner.lo Zend/zend_alloc.lo Zend/zend_compile.lo Zend/zend_constants.lo Zend/zend_dtrace.lo Zend/zend_execute_API.lo Zend/zend_highlight.lo Zend/zend_llist.lo Zend/zend_vm_opcodes.lo Zend/zend_opcode.lo Zend/zend_operators.lo Zend/zend_ptr_stack.lo Zend/zend_stack.lo Zend/zend_variables.lo Zend/zend.lo Zend/zend_API.lo Zend/zend_extensions.lo Zend/zend_hash.lo Zend/zend_list.lo Zend/zend_builtin_functions.lo Zend/zend_sprintf.lo Zend/zend_ini.lo Zend/zend_sort.lo Zend/zend_multibyte.lo Zend/zend_ts_hash.lo Zend/zend_stream.lo Zend/zend_iterators.lo Zend/zend_interfaces.lo Zend/zend_exceptions.lo Zend/zend_strtod.lo Zend/zend_gc.lo Zend/zend_closures.lo Zend/zend_float.lo Zend/zend_string.lo Zend/zend_signal.lo Zend/zend_generators.lo Zend/zend_virtual_cwd.lo Zend/zend_ast.lo Zend/zend_objects.lo Zend/zend_object_handlers.lo Zend/zend_objects_API.lo Zend/zend_default_classes.lo Zend/zend_inheritance.lo Zend/zend_smart_str.lo Zend/zend_execute.lo main/internal_functions_cli.lo main/fastcgi.lo sapi/cgi/cgi_main.lo -lcrypt -lcrypt -lrt -lpng -lz -ljpeg -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lcurl -lxml2 -lz -lm -lfreetype -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -o sapi/cgi/php-cgi Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled. directorygraphiterator.inc directorytreeiterator.inc invertedregexiterator.inc clicommand.inc pharcommand.inc phar.inc Build complete. Don't forget to run 'make test'. [root@linuxme php-7.0.9]#
安装:make install
[root@linuxme php-7.0.9]# ls /usr/local/ bin etc games include lib lib64 libexec nginx-1.11.3 sbin share src [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# make install Installing shared extensions: /usr/local/php-7.0.9/lib/php/extensions/no-debug-non-zts-20151012/ Installing PHP CLI binary: /usr/local/php-7.0.9/bin/ Installing PHP CLI man page: /usr/local/php-7.0.9/php/man/man1/ Installing PHP FPM binary: /usr/local/php-7.0.9/sbin/ Installing PHP FPM config: /usr/local/php-7.0.9/etc/ Installing PHP FPM man page: /usr/local/php-7.0.9/php/man/man8/ Installing PHP FPM status page: /usr/local/php-7.0.9/php/php/fpm/ Installing phpdbg binary: /usr/local/php-7.0.9/bin/ Installing phpdbg man page: /usr/local/php-7.0.9/php/man/man1/ Installing PHP CGI binary: /usr/local/php-7.0.9/bin/ Installing PHP CGI man page: /usr/local/php-7.0.9/php/man/man1/ Installing build environment: /usr/local/php-7.0.9/lib/php/build/ Installing header files: /usr/local/php-7.0.9/include/php/ Installing helper programs: /usr/local/php-7.0.9/bin/ program: phpize program: php-config Installing man pages: /usr/local/php-7.0.9/php/man/man1/ page: phpize.1 page: php-config.1 Installing PEAR environment: /usr/local/php-7.0.9/lib/php/ [PEAR] Archive_Tar - installed: 1.4.0 [PEAR] Console_Getopt - installed: 1.4.1 [PEAR] Structures_Graph- installed: 1.1.1 [PEAR] XML_Util - installed: 1.3.0 [PEAR] PEAR - installed: 1.10.1 Wrote PEAR system config file at: /usr/local/php-7.0.9/etc/pear.conf You may want to add: /usr/local/php-7.0.9/lib/php to your php.ini include_path /software/php-7.0.9/build/shtool install -c ext/phar/phar.phar /usr/local/php-7.0.9/bin ln -s -f phar.phar /usr/local/php-7.0.9/bin/phar Installing PDO headers: /usr/local/php-7.0.9/include/php/ext/pdo/ [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# ls /usr/local/ bin etc games include lib lib64 libexec nginx-1.11.3 php-7.0.9 sbin share src [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# ls /usr/local/php-7.0.9/ bin etc include lib php sbin var [root@linuxme php-7.0.9]#
配置PHP:
[root@linuxme php-7.0.9]# cd /usr/local/php-7.0.9/ [root@linuxme php-7.0.9]# ls etc/ pear.conf php-fpm.conf.default php-fpm.d [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# cp /software/php-7.0.9/php.ini-production etc/php.ini [root@linuxme php-7.0.9]# cp etc/php-fpm.conf.default etc/php-fpm.conf [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# cd etc/php-fpm.d/ [root@linuxme php-fpm.d]# ls www.conf.default [root@linuxme php-fpm.d]# cp www.conf.default www.conf [root@linuxme php-fpm.d]#
如果没有将“etc/php-fpm.d/”下的:www.conf.default,修改为:www.conf。
则在启动php-fpm服务的时候会报错:
[root@linuxme php-7.0.9]# sbin/php-fpm [15-Aug-2016 22:03:50] WARNING: Nothing matches the include pattern '/usr/local/php-7.0.9/etc/php-fpm.d/*.conf' from /usr/local/php-7.0.9/etc/php-fpm.conf at line 126. [15-Aug-2016 22:03:50] ERROR: No pool defined. at least one pool section must be specified in config file [15-Aug-2016 22:03:50] ERROR: failed to post process the configuration [15-Aug-2016 22:03:50] ERROR: FPM initialization failed [root@linuxme php-7.0.9]#
启动php-fpm:
[root@linuxme php-7.0.9]# sbin/php-fpm [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# ps -ef | grep --color php root 5996 1 0 22:06 ? 00:00:00 php-fpm: master process (/usr/local/php-7.0.9/etc/php-fpm.conf) nobody 5997 5996 0 22:06 ? 00:00:00 php-fpm: pool www nobody 5998 5996 0 22:06 ? 00:00:00 php-fpm: pool www root 6000 2619 0 22:06 pts/0 00:00:00 grep --color php [root@linuxme php-7.0.9]# [root@linuxme php-7.0.9]# netstat -tupln | grep --color php tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 5996/php-fpm [root@linuxme php-7.0.9]#
关于Nginx:
参考:
启动Nginx:
[root@linuxme ~]# /usr/local/nginx-1.11.3/sbin/nginx [root@linuxme ~]# [root@linuxme ~]# ps -ef | grep -v grep | grep --color nginx root 6016 1 0 22:11 ? 00:00:00 nginx: master process /usr/local/nginx-1.11.3/sbin/nginx nobody 6017 6016 0 22:11 ? 00:00:00 nginx: worker process root 6571 6550 0 21:10 pts/1 00:00:00 tail -f /usr/local/nginx-1.11.3/logs/access.log /usr/local/nginx-1.11.3/logs/error.log /usr/local/nginx-1.11.3/logs/nginx.pid [root@linuxme ~]#
Nginx配置文件:
[root@linuxme ~]# cat /usr/local/nginx-1.11.3/conf/nginx.conf | grep -v '#' | strings worker_processes 1; events { worker_connections 1024; http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } [root@linuxme ~]#
样例文件(普通):
[root@linuxme ~]# cd /usr/local/nginx-1.11.3/html/ [root@linuxme html]# ls 50x.html index.html [root@linuxme html]# [root@linuxme html]# echo "Hello world." > me.html [root@linuxme html]# [root@linuxme html]# ls 50x.html index.html me.html [root@linuxme html]# [root@linuxme html]# cat me.html Hello world. [root@linuxme html]#
测试:
[root@linuxme html]# curl -s http://localhost/me.html Hello world. [root@linuxme html]#
样例文件(PHP):
[root@linuxme html]# echo "" > php_me.php [root@linuxme html]# [root@linuxme html]# ls 50x.html index.html me.html php_me.php [root@linuxme html]# [root@linuxme html]# cat php_me.php [root@linuxme html]#
测试:
http://【ip】/php_me.php
可以看到,并没有被解释为PHP。
修改Nginx配置文件,并重新加载服务:
[root@linuxme html]# cat /usr/local/nginx-1.11.3/conf/nginx.conf | grep -v '#' | strings worker_processes 1; events { worker_connections 1024; http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~\.php$ { root /usr/local/nginx-1.11.3/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } } [root@linuxme html]# [root@linuxme html]# /usr/local/nginx-1.11.3/sbin/nginx -s reload [root@linuxme html]#
再次查看:http://【ip】/php_me.php
就没问题了。
——————————————————————
Done。