How to install PHP 5.6 from source centos 6
Install some needed library
[root@maswachid ~]# sudo yum install autoconf libtool re2c bison libxml2-devel bzip2-devel libcurl-devel libpng-devel libicu-devel gcc-c++ libmcrypt-devel libwebp-devel libjpeg-devel openssl-devel -y
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
y
* base: centos.biz.net.id
* epel: del-repos.extreme-ix.org
* extras: centos.biz.net.id
* remi-safe: fr2.rpmfind.net
* updates: centos.biz.net.id
* webtatic: sp.repo.webtatic.com
Package autoconf-2.63-5.1.el6.noarch already installed and latest version
Package libtool-2.2.6-15.5.el6.x86_64 already installed and latest version
Package bison-2.4.1-5.el6.x86_64 already installed and latest version
Package libxml2-devel-2.7.6-21.el6_8.1.x86_64 already installed and latest version
Package bzip2-devel-1.0.5-7.el6_0.x86_64 already installed and latest version
Package libcurl-devel-7.19.7-53.el6_9.x86_64 already installed and latest version
Package 2:libpng-devel-1.2.49-2.el6_7.x86_64 already installed and latest version
Package gcc-c++-4.4.7-23.el6.x86_64 already installed and latest version
Package openssl-devel-1.0.1e-57.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package libicu-devel.x86_64 0:4.2.1-14.el6 will be installed
---> Package libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5 will be installed
---> Package libmcrypt-devel.x86_64 0:2.5.8-9.el6 will be installed
---> Package libwebp-devel.x86_64 0:0.4.3-3.el6 will be installed
---> Package re2c.x86_64 0:0.13.5-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================
Installing:
libicu-devel x86_64 4.2.1-14.el6 base 617 k
libjpeg-turbo-devel x86_64 1.2.1-3.el6_5 base 96 k
libmcrypt-devel x86_64 2.5.8-9.el6 epel 12 k
libwebp-devel x86_64 0.4.3-3.el6 epel 28 k
re2c x86_64 0.13.5-1.el6 epel 200 k
Transaction Summary
======================================================================================================================================
Install 5 Package(s)
Total download size: 953 k
Installed size: 4.2 M
Downloading Packages:
(1/5): libicu-devel-4.2.1-14.el6.x86_64.rpm | 617 kB 00:00
(2/5): libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64.rpm | 96 kB 00:00
(3/5): libmcrypt-devel-2.5.8-9.el6.x86_64.rpm | 12 kB 00:00
(4/5): libwebp-devel-0.4.3-3.el6.x86_64.rpm | 28 kB 00:00
(5/5): re2c-0.13.5-1.el6.x86_64.rpm | 200 kB 00:00
--------------------------------------------------------------------------------------------------------------------------------------
Total 178 kB/s | 953 kB 00:05
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : libwebp-devel-0.4.3-3.el6.x86_64 1/5
Installing : libmcrypt-devel-2.5.8-9.el6.x86_64 2/5
Installing : libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64 3/5
Installing : libicu-devel-4.2.1-14.el6.x86_64 4/5
Installing : re2c-0.13.5-1.el6.x86_64 5/5
Verifying : re2c-0.13.5-1.el6.x86_64 1/5
Verifying : libicu-devel-4.2.1-14.el6.x86_64 2/5
Verifying : libjpeg-turbo-devel-1.2.1-3.el6_5.x86_64 3/5
Verifying : libmcrypt-devel-2.5.8-9.el6.x86_64 4/5
Verifying : libwebp-devel-0.4.3-3.el6.x86_64 5/5
Installed:
libicu-devel.x86_64 0:4.2.1-14.el6 libjpeg-turbo-devel.x86_64 0:1.2.1-3.el6_5 libmcrypt-devel.x86_64 0:2.5.8-9.el6
libwebp-devel.x86_64 0:0.4.3-3.el6 re2c.x86_64 0:0.13.5-1.el6
Complete!
[root@maswachid ~]#
Download php from official website
[root@maswachid ~]# wget http://my1.php.net/distributions/php-5.6.38.tar.gz
--2018-10-15 16:37:51-- http://my1.php.net/distributions/php-5.6.38.tar.gz
Connecting to 192.168.71.17:9898... connected.
Proxy request sent, awaiting response... 200 OK
Length: 19301157 (18M) [application/x-gzip]
Saving to: “php-5.6.38.tar.gz”
100%[============================================================================================>] 19,301,157 8.87M/s in 2.1s
2018-10-15 16:37:54 (8.87 MB/s) - “php-5.6.38.tar.gz” saved [19301157/19301157]
[root@maswachid ~]#
[root@sipencatar-cloud ~]# ls
anaconda-ks.cfg epel-release-latest-6.noarch.rpm install.log.syslog php-5.6.38.tar.gz
apache-2.4.36.tar.gz httpd-2.4.36 mirror remi-release-6.rpm
apr-1.6.5.tar.gz index.html mirror.1 ssl
apr-util-1.6.1.tar.gz install.log mysql80-community-release-el6-1.noarch.rpm
[root@maswachid ~]#
Extract php source
[root@maswachid ~]# tar xzf php-5.6.38.tar.gz
[root@maswachid ~]#
[root@maswachid ~]# ls
anaconda-ks.cfg epel-release-latest-6.noarch.rpm install.log.syslog php-5.6.38
apache-2.4.36.tar.gz httpd-2.4.36 mirror php-5.6.38.tar.gz
apr-1.6.5.tar.gz index.html mirror.1 remi-release-6.rpm
apr-util-1.6.1.tar.gz install.log mysql80-community-release-el6-1.noarch.rpm ssl
[root@maswachid ~]#
Change working directory to php extracted folder[root@maswachid ~]# cd php-5.6.38
[root@maswachid php-5.6.38]# ls
acinclude.m4 generated_lists mkinstalldirs README.NEW-OUTPUT-API server-tests-config.php
aclocal.m4 genfiles netware README.PARAMETER_PARSING_API server-tests.php
build header NEWS README.REDIST.BINS snapshot
buildconf INSTALL pear README.RELEASE_PROCESS stamp-h.in
buildconf.bat install-sh php5.spec.in README.SELF-CONTAINED-EXTENSIONS stub.c
CODING_STANDARDS LICENSE php.gif README.STREAMS tests
config.guess ltmain.sh php.ini-development README.SUBMITTING_PATCH travis
config.sub main php.ini-production README.TESTING TSRM
configure makedist README.EXT_SKEL README.TESTING2 UPGRADING
configure.in Makefile.frag README.GIT-RULES README.UNIX-BUILD-SYSTEM UPGRADING.INTERNALS
CREDITS Makefile.gcov README.input_filter README.WIN32-BUILD-SYSTEM vcsclean
ext Makefile.global README.MAILINGLIST_RULES run-tests.php win32
EXTENSIONS makerpm README.md sapi Zend
footer missing README.namespaces scripts
[root@maswachid php-5.6.38]# ./buildconf
You should not run buildconf in a release package.
use buildconf --force to override this check.
[root@sipencatar-cloud php-5.6.38]#
[root@sipencatar-cloud php-5.6.38]# ./buildconf --force
Forcing buildconf
Removing configure caches
buildconf: checking installation...
buildconf: autoconf version 2.63 (ok)
[root@maswachid php-5.6.38]#
Execute Configure help to show the configure option and documentation
[root@sipencatar-cloud php-5.6.38]# ./configure --help
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
Configure the php[root@maswachid php-5.6.38]# ./configure --prefix=/usr/local/php5 --enable-fpm --enable-sysvshm --enable-sysvsem --enable-sysvmsg --enable-shmop --disable-short-tags --with-openssl --with-pcre-regex --with-zlib --enable-bcmath --enable-opcache --with-gettext --with-mcrypt --with-bz2 --enable-calendar --with-curl --enable-exif --with-gd --enable-intl --enable-mbstring --with-mysqli --enable-pcntl --with-pdo-mysql --enable-soap --enable-sockets --with-xmlrpc --enable-zip --with-jpeg-dir --with-png-dir --enable-wddx --enable-ftp --with-mhash --with-fpm-user=www-data --with-fpm-group=www-data
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking how to run the C preprocessor... cc -E
checking for ANSI C header files... yes
..
..
+--------------------------------------------------------------------+
Thank you for using PHP.
config.status: creating php5.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/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: executing default commands
[root@maswachid php-5.6.38]#
[root@maswachid php-5.6.38]# make
/bin/sh /root/php-5.6.38/libtool --silent --preserve-dup-deps --mode=compile cc -Iext/mcrypt/ -I/root/php-5.6.38/ext/mcrypt/ -DPHP_ATOM_INC -I/root/php-5.6.38/include -I/root/php-5.6.38/main -I/root/php-5.6.38 -I/root/php-5.6.38/ext/date/lib -I/root/php-5.6.38/ext/ereg/regex -I/usr/include/libxml2 -I/root/php-5.6.38/ext/mbstring/oniguruma -I/root/php-5.6.38/ext/mbstring/libmbfl -I/root/php-5.6.38/ext/mbstring/libmbfl/mbfl -I/root/php-5.6.38/ext/sqlite3/libsqlite -I/root/php-5.6.38/ext/zip/lib -I/root/php-5.6.38/TSRM -I/root/php-5.6.38/Zend -I/usr/include -g -O2 -fvisibility=hidden -c /root/php-5.6.38/ext/mcrypt/mcrypt.c -o ext/mcrypt/mcrypt.lo
/bin/sh /root/php-5.6.38/libtool --silent --preserve-dup-deps --mode=link cc -export-dynamic -I/usr/include -g -O2 -fvisibility=hidden ext/date/php_date.lo ext/date/lib/astro.lo ext/date/lib/dow.lo ext/date/lib/parse_date.lo ext/date/lib/parse_tz.lo ext/date/lib/timelib.lo ext/date/lib/tm2unixtime.lo ext/date/lib/unixtime2tm.lo ext/date/lib/parse_iso_intervals.lo ext/date/lib/interval.lo ext/ereg/ereg.lo ext/ereg/regex/regcomp.lo ext/ereg/regex/regexec.lo ext/ereg/regex/regerror.lo ext/ereg/regex/regfree.lo ext/libxml/libxml.lo ext/openssl/openssl.lo ext/openssl/xp_ssl.lo ext/pcre/pcrelib/pcre_chartables.lo ext/pcre/pcrelib/pcre_ucd.lo ext/pcre/pcrelib/pcre_compile.lo ext/pcre/pcrelib/pcre_config.lo ext/pcre/pcrelib/pcre_exec.lo ext/pcre/pcrelib/pcre_fullinfo.lo ext/pcre/pcrelib/pcre_get.lo ext/pcre/pcrelib/pcre_globals.lo ext/pcre/pcrelib/pcre_maketables.lo ext/pcre/pcrelib/pcre_newline.lo ext/pcre/pcrelib/pcre_ord2utf8.lo ext/pcre/pcrelib/pcre_refcount.lo ext/pcre/pcrelib/pcre_study.lo ext/pcre/pcrelib/pcre_tables.lo ext/pcre/pcrelib/pcre_valid_utf8.lo ext/pcre/pcrelib/pcre_version.lo ext/pcre/pcrelib/pcre_xclass.lo ext/pcre/pcrelib/pcre_jit_compile.lo ext/pcre/php_pcre.lo ext/sqlite3/sqlite3.lo ext/sqlite3/libsqlite/sqlite3.lo ext/zlib/zlib.lo ext/zlib/zlib_fopen_wrapper.lo ext/zlib/zlib_filter.lo ext/bcmath/bcmath.lo ext/bcmath/libbcmath/src/add.lo ext/bcmath/libbcmath/src/div.lo ext/bcmath/libbcmath/src/init.lo ext/bcmath/libbcmath/src/neg.lo ext/bcmath/libbcmath/src/outofmem.lo ext/bcmath/libbcmath/src/raisemod.lo ext/bcmath/libbcmath/src/rt.lo ext/bcmath/libbcmath/src/sub.lo ext/bcmath/libbcmath/src/compare.lo ext/bcmath/libbcmath/src/divmod.lo ext/bcmath/libbcmath/src/int2num.lo ext/bcmath/libbcmath/src/num2long.lo ext/bcmath/libbcmath/src/output.lo ext/bcmath/libbcmath/src/recmul.lo ext/bcmath/libbcmath/src/sqrt.lo ext/bcmath/libbcmath/src/zero.lo ext/bcmath/libbcmath/src/debug.lo ext/bcmath/libbcmath/src/doaddsub.lo ext/bcmath/libbcmath/src/nearzero.lo ext/bcmath/libbcmath/src/num2str.lo ext/bcmath/libbcmath/src/raise.lo ext/bcmath/libbcmath/src/rmzero.lo ext/bcmath/libbcmath/src/str2num.lo ext/bz2/bz2.lo ext/bz2/bz2_filter.lo ext/calendar/calendar.lo ext/calendar/dow.lo ext/calendar/french.lo ext/calendar/gregor.lo ext/calendar/jewish.lo ext/calendar/julian.lo ext/calendar/easter.lo ext/calendar/cal_unix.lo ext/ctype/ctype.lo ext/curl/interface.lo ext/curl/multi.lo ext/curl/share.lo ext/curl/curl_file.lo ext/dom/php_dom.lo ext/dom/attr.lo ext/dom/document.lo ext/dom/domerrorhandler.lo ext/dom/domstringlist.lo ext/dom/domexception.lo ext/dom/namelist.lo ext
...
...
nd_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_indent.lo Zend/zend_builtin_functions.lo Zend/zend_sprintf.lo Zend/zend_ini.lo Zend/zend_qsort.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_execute.lo main/internal_functions_cli.lo sapi/cgi/cgi_main.lo sapi/cgi/fastcgi.lo -lcrypt -lz -lcrypt -lrt -lmcrypt -lstdc++ -lpng -lz -ljpeg -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -lcurl -lxml2 -lz -lm -lssl -lcrypto -licui18n -licuuc -licudata -lm -licuio -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lxml2 -lz -lm -lssl -lcrypto -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.
pharcommand.inc
clicommand.inc
directorygraphiterator.inc
directorytreeiterator.inc
invertedregexiterator.inc
phar.inc
Build complete.
Don't forget to run 'make test'.
[root@maswachid php-5.6.38]#
Make install the php
[root@maswachid php-5.6.38]# make install
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-non-zts-20131226/
Installing PHP CLI binary: /usr/local/php5/bin/
Installing PHP CLI man page: /usr/local/php5/php/man/man1/
Installing PHP FPM binary: /usr/local/php5/sbin/
Installing PHP FPM config: /usr/local/php5/etc/
Installing PHP FPM man page: /usr/local/php5/php/man/man8/
Installing PHP FPM status page: /usr/local/php5/php/php/fpm/
Installing PHP CGI binary: /usr/local/php5/bin/
Installing PHP CGI man page: /usr/local/php5/php/man/man1/
Installing build environment: /usr/local/php5/lib/php/build/
Installing header files: /usr/local/php5/include/php/
Installing helper programs: /usr/local/php5/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php5/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php5/lib/php/
[PEAR] Archive_Tar - already installed: 1.4.3
[PEAR] Console_Getopt - already installed: 1.4.1
[PEAR] Structures_Graph- already installed: 1.1.1
[PEAR] XML_Util - already installed: 1.4.2
[PEAR] PEAR - already installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
/root/php-5.6.38/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin
ln -s -f phar.phar /usr/local/php5/bin/phar
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
[root@maswachid php-5.6.38]#
PHP Configuration
PHP-FPM setup
Before we will be able to run PHP from Apache we need to setup PHP-FPM worker. After installation there should be PHP-FPM default configuration file in installation directory. We will alter the file and then change it a bit.
cd /usr/local/php/etc
mkdir fpm.d
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
We need to uncomment/change these lines:
include=etc/fpm.d/*.conf
pid = /var/run/php-fpm.pid
error_log = log/php-fpm.log
COPY EVERYTHING UNDER Pool Definitions TO CLIPBOARD AND REMOVE IT FROM php-fpm.conf FILE
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
include=/etc/fpm.d/*.conf
- by default there is one pool defined inside php-fpm.conf
file. The best way to solve it is the same way as we solved Apache vhosts. We will include each pool in separate directory. In php-fpm.conf
file one pool is already defined. We need to delete it from this file and put it inside fpm.d
directory. We will have better control over the pools. The easiest way is just to Cut it from this file and paste it into new one.
Now let's create the file inside fpm.d for our example.com domain:
cd fpm.d
vi example.com.conf
PASTE TEXT FROM CLIPBOARD HERE AND CHANGE THESE LINES:
[www] -> [example_com] //Must be unique per file
user = apache
group = www
listen = 127.0.0.1:9000 //Port must be unique per file
catch_workers_output = yes
slowlog = /var/www/example.com/logs/php-fpm.slow.log
request_slowlog_timeout = 30s
php_flag[display_errors] = off
php_admin_value[error_log] = /var/www/example.com/logs/php-fpm.error.log
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 64M
php_admin_value[open_basedir] = /var/www/example.com/htdocs
Each pool must have different name. So we need to change it from
[www]
to something else, for instance to domain name. It'll be easier to find the issues inside log files.
We set user and group to the same user as apache to have access to files.
Port will be different per pool. Standard way is to start from port 9000. Next will be 9001 etc.
We will catch errors and log them to file. In addition we set logging for slow requests.
Nice part is that we can overwrite the settings from
php.ini
here. So we can overwrite error_log
or memory_limit
for instance. We should also set open_basedir
so PHP will have access only to files inside our htdocs directory. Our server will be more secure with this setting.
php.ini and OPCache configuration
Second thing is php.ini file. After installation php.ini file should located in /usr/local/php/lib. This is only the location. After compiling from source You won't anything there so we need to copy it from uncompressed sources.
[root@maswachid ~]# cd /usr/local/php/lib/
[root@maswachid lib]# ls
php
[root@maswachid lib]# cp ~/php-5.6.38/php.ini-development ./php.ini
[root@maswachid lib]# cd php
[root@maswachid php]# ls
Archive Console doc OS pearcmd.php peclcmd.php Structures test
build data extensions PEAR PEAR.php php.ini System.php XML
[root@maswachid php]# vi php.ini
[root@maswachid php]#
This is pretty large file with lot of configuration settings. Fortunately we only need to change some of the options:
short_open_tag = On
open_basedir = /var/www
disable_functions = exec,passthru,shell_exec,system,proc_open,popen
expose_php = Off
max_execution_time = 30
memory_limit = 64M
date.timezone = Europe/Warsaw
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = Off
display_startup_errors = Off
log_errors = On
post_max_size = 5M
upload_max_filesize = 4M
opcache.enable=1
opcache.memory_consumption=64
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=7000
opcache.validate_timestamps=0 ;set this to 1 on production server
opcache.fast_shutdown=1
So we set few things here, enable <? tag, limit access to files from PHP level, disabled dangerous functions, adjusts timezone, security, max execution times, errors etc. In addition we have enable OPCache for PHP.
Each one of these options are well commented inside php.ini file. If You don't like the settings here or You need something else, feel free to change it for Your purposes.
Useful shell scripts for PHP
/etc/init.d/php-fpm
As You probably remember during Apache setup we create script so we can use service command to start / stop Apache process. Now we will do the same for PHP-FPM
With PHP source code there comes ready script for that purpose.
[root@maswachid php]# cd /etc/init.d
[root@maswachid init.d]# cp ~/php-5.6.38/sapi/fpm/init.d.php-fpm php-fpm
[root@maswachid init.d]# vi php-fpm
[root@maswachid init.d]#
Now we need to setup configuration for the file:
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=/var/run/php-fpm.pid
Save the file and add executable permission.
[root@maswachid init.d]# chmod +x php-fpm5
[root@maswachid init.d]# service php-fpm5 status
php-fpm is stopped
[root@maswachid init.d]# service php-fpm5 start
Starting php-fpm done
[root@maswachid init.d]# service php-fpm5 status
php-fpm (pid 99223) is running...
[root@maswachid init.d]#
After that we should have php-fpm process up and running!
Setup Add PHP to $PATH
We can do one more thing to make our life easier:) Add PHP executable to PATH, so we'll be able to call php command from every directory.
[root@maswachid ~]# php -v
-bash: php: command not found
[root@maswachid ~]# echo 'pathmunge /usr/local/php5/bin' > /etc/profile.d/php.sh
[root@maswachid ~]#
Execute such command, log out, log in and You'll be able to execute:
[root@maswachid ~]# php -v
-bash: php: command not found
[root@maswachid ~]# exit
logout
Connection to 192.168.71.24 closed.
[maswachid@ssh-server ~]$ ssh [email protected]
[email protected]'s password:
Last login: Tue Oct 16 11:25:12 2018 from 192.168.75.28
[root@maswachid ~]# php -v
PHP 5.6.38 (cli) (built: Oct 15 2018 16:57:28)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[root@maswachid ~]#
Check php modules[root@maswachid php-5.6.38]# php5 -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
zip
zlib
[Zend Modules]
[root@maswachid php-5.6.38]#
Setup Apache for PHP-FPM
Now is the time to finally setup Apache for .php files. Let's edit one of the Virtual Hosts now.
vi /usr/local/apache2/conf/vhosts/example.com.conf
<VirtualHost *80>
ServerName example.com
<LocationMatch "^/(.*\.php(/.*)?)$">
ProxyPass fcgi://127.0.0.1:9000/var/www/example.com/htdocs/$1
</LocationMatch>
////Rest of the file below
So basically we need to proxy all files with .php extension to our PHP-FPM process. Also we need to restart Apache and make sure PHP-FPM is running httpd server:
service php-fpm start
service httpd restart
How to test if PHP is working?
We need to test if our PHP installation works. The easiest way to debug and check what's going on would be to create
test.php
file inside our /var/www
directory.vi /var/www/example.com/htdocs/test.php
and paste
phpinfo()
function there:<?php
phpinfo();
Save the file and open the file in Your browser, assuming that your vagrant setup is correct. For instance
http://example.com/test.php
or 192.168.99.99/test.php
If everything is OK you should get information about PHP installation. Well done!
Tidak ada komentar :
Posting Komentar