Rabu, 17 Oktober 2018

How to install php 7.1 from source centos 6

  Tidak ada komentar
Install some needed liblary
[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 the php source code package
[root@maswachid ~]# wget http://id1.php.net/distributions/php-7.1.23.tar.gz
--2018-10-16 14:35:01--  http://id1.php.net/distributions/php-7.1.23.tar.gz
Connecting to 192.168.71.17:9898... connected.
Proxy request sent, awaiting response... 200 OK
Length: 19476447 (19M) [application/x-gzip]
Saving to: “php-7.1.23.tar.gz”

100%[============================================================================================>] 19,476,447  1.02M/s   in 10s

2018-10-16 14:35:13 (1.79 MB/s) - “php-7.1.23.tar.gz” saved [19476447/19476447]

[root@maswachid ~]# ls
anaconda-ks.cfg        epel-release-latest-6.noarch.rpm  install.log.syslog                          php-5.6.38          ssl
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                                    php-7.1.23.tar.gz
apr-util-1.6.1.tar.gz  install.log                       mysql80-community-release-el6-1.noarch.rpm  remi-release-6.rpm
[root@maswachid ~]#

Extract the php source code package
[root@maswachid ~]# tar -xzf php-7.1.23.tar.gz
[root@maswachid ~]# ls
anaconda-ks.cfg                   httpd-2.4.36        mirror.1                                    php-7.1.23.tar.gz
apache-2.4.36.tar.gz              index.html          mysql80-community-release-el6-1.noarch.rpm  remi-release-6.rpm
apr-1.6.5.tar.gz                  install.log         php-5.6.38                                  ssl
apr-util-1.6.1.tar.gz             install.log.syslog  php-5.6.38.tar.gz
epel-release-latest-6.noarch.rpm  mirror              php-7.1.23
[root@maswachid ~]#
Change working directory to php source code directory
[root@maswachid ~]# cd php-7.1.23
[root@maswachid php-7.1.23]# ls
acinclude.m4      makedist                      README.SELF-CONTAINED-EXTENSIONS
aclocal.m4        Makefile.frag                 README.STREAMS
appveyor          Makefile.gcov                 README.SUBMITTING_PATCH
build             Makefile.global               README.TESTING
buildconf         makerpm                       README.TESTING2
buildconf.bat     missing                       README.UNIX-BUILD-SYSTEM
CODING_STANDARDS  mkinstalldirs                 README.WIN32-BUILD-SYSTEM
config.guess      netware                       run-tests.php
config.sub        NEWS                          sapi
configure         pear                          scripts
configure.in      php7.spec.in                  server-tests-config.php
CONTRIBUTING.md   php.gif                       server-tests.php
CREDITS           php.ini-development           snapshot
ext               php.ini-production            stamp-h.in
EXTENSIONS        README.EXT_SKEL               stub.c
footer            README.GIT-RULES              tests
generated_lists   README.input_filter           travis
genfiles          README.MAILINGLIST_RULES      TSRM
header            README.md                     UPGRADING
INSTALL           README.namespaces             UPGRADING.INTERNALS
install-sh        README.NEW-OUTPUT-API         vcsclean
LICENSE           README.PARAMETER_PARSING_API  win32
ltmain.sh         README.REDIST.BINS            Zend
main              README.RELEASE_PROCESS
[root@sipencatar-cloud php-7.1.23]#

Built the php configuration
[root@maswachid php-7.1.23]# ./buildconf
You should not run buildconf in a release package.
use buildconf --force to override this check.
[root@sipencatar-cloud php-7.1.23]# ./buildconf --force
Forcing buildconf
Removing configure caches
buildconf: checking installation...
buildconf: autoconf version 2.63 (ok)
rebuilding aclocal.m4
rebuilding configure
rebuilding main/php_config.h.in
[root@maswachid php-7.1.23]#

Configure the php source installation
[root@maswachid php-7.1.23]# ./configure --prefix=/usr/local/php7 --enable-fpm --disable-short-tags --with-openssl --with-pcre-regex --with-zlib --enable-bcmath --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
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 for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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
..
..
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/phpdbg/phpdbg.1
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@sipencatar-cloud php-7.1.23]#
Compile the php source code
[root@maswachid php-7.1.23]#
[root@maswachid php-7.1.23]# make
/bin/sh /root/php-7.1.23/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.23/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.23/include -I/root/php-7.1.23/main -I/root/php-7.1.23 -I/root/php-7.1.23/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.23/ext/mbstring/oniguruma -I/root/php-7.1.23/ext/mbstring/libmbfl -I/root/php-7.1.23/ext/mbstring/libmbfl/mbfl -I/root/php-7.1.23/ext/sqlite3/libsqlite -I/root/php-7.1.23/ext/zip/lib -I/root/php-7.1.23/TSRM -I/root/php-7.1.23/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.23/ext/opcache/ZendAccelerator.c -o ext/opcache/ZendAccelerator.lo
/bin/sh /root/php-7.1.23/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.23/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.23/include -I/root/php-7.1.23/main -I/root/php-7.1.23 -I/root/php-7.1.23/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.23/ext/mbstring/oniguruma -I/root/php-7.1.23/ext/mbstring/libmbfl -I/root/php-7.1.23/ext/mbstring/libmbfl/mbfl -I/root/php-7.1.23/ext/sqlite3/libsqlite -I/root/php-7.1.23/ext/zip/lib -I/root/php-7.1.23/TSRM -I/root/php-7.1.23/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.23/ext/opcache/zend_accelerator_blacklist.c -o ext/opcache/zend_accelerator_blacklist.lo
/bin/sh /root/php-7.1.23/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.23/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.23/include -I/root/php-7.1.23/main -I/root/php-7.1.23 -I/root/php-7.1.23/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.23/ext/mbstring/oniguruma -I/root/php-7.1.23/ext/mbstring/libmbfl -I/root/php-7.1.23/ext/mbstring/libmbfl/mbfl -I/root/php-7.1.23/ext/sqlite3/libsqlite -I/root/php-7.1.23/ext/zip/lib -I/root/php-7.1.23/TSRM -I/root/php-7.1.23/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.23/ext/opcache/zend_accelerator_debug.c -o ext/opcache/zend_accelerator_debug.lo
/bin/sh /root/php-7.1.23/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/opcache/ -I/root/php-7.1.23/ext/opcache/ -DPHP_ATOM_INC -I/root/php-7.1.23/include -I/root/php-7.1.23/main -I/root/php-7.1.23 -I/root/php-7.1.23/ext/date/lib -I/usr/include/libxml2 -I/root/php-7.1.23/ext/mbstring/oniguruma -I/root/php-7.1.23/ext/mbstring/libmbfl -I/root/php-7.1.23/ext/mbstring/libmbfl/mbfl -I/root/php-7.1.23/ext/sqlite3/libsqlite -I/root/php-7.1.23/ext/zip/lib -I/root/php-7.1.23/TSRM -I/root/php-7.1.23/Zend    -I/usr/include -g -O2 -fvisibility=hidden -DZEND_SIGNALS    -c /root/php-7.1.23/ext/opcache/zend_accelerator_hash.c -o ext/opcache/zend_accelerator_hash.lo
..
..
st.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 -lz -lcrypt -lrt -lstdc++ -lpng -lz -ljpeg -lcurl -lbz2 -lz -lrt -lm -ldl -lnsl -lrt -lxml2 -lz -lm -lssl -lcrypto -lcurl -lxml2 -lz -lm -licui18n -licuuc -licudata -lm -licuio -lxml2 -lz -lm -lxml2 -lz -lm -lcrypt -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-7.1.23]#
Install the php by running make install
[root@maswachid php-7.1.23]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/php7/bin/
Installing PHP CLI man page:      /usr/local/php7/php/man/man1/
Installing PHP FPM binary:        /usr/local/php7/sbin/
Installing PHP FPM defconfig:     /usr/local/php7/etc/
Installing PHP FPM man page:      /usr/local/php7/php/man/man8/
Installing PHP FPM status page:   /usr/local/php7/php/php/fpm/
Installing phpdbg binary:         /usr/local/php7/bin/
Installing phpdbg man page:       /usr/local/php7/php/man/man1/
Installing PHP CGI binary:        /usr/local/php7/bin/
Installing PHP CGI man page:      /usr/local/php7/php/man/man1/
Installing build environment:     /usr/local/php7/lib/php/build/
Installing header files:          /usr/local/php7/include/php/
Installing helper programs:       /usr/local/php7/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php7/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php7/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/root/php-7.1.23/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/
[root@maswachid php-7.1.23]#
[root@maswachid php-7.1.23]# /root/php-7.1.23/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
[root@maswachid php-7.1.23]# ln -s -f phar.phar /usr/local/php7/bin/phar
[root@maswachid php-7.1.23]#


Restart mysql service to make sure there is no error


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.
[root@maswachid etc]# groups
root
[root@maswachid fpm.d]# sudo groupadd www
[root@maswachid fpm.d]# usermod -aG www apache
[root@maswachid fpm.d]#
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_logor 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 ~/usr/local/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-7.1.23/sapi/fpm/init.d.php-fpm php7-fpm
[root@maswachid init.d]# vi php7-fpm
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@sipencatar-cloud init.d]# service php7-fpm status
php-fpm is stopped
[root@maswachid init.d]# service php7-fpm start
Starting php-fpm  done
[root@maswachid init.d]# service php7-fpm status
php-fpm (pid 17414) is running...
[root@maswaachid init.d]#
After that we should have php-fpm process up and running!
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/php7/bin' > /etc/profile.d/php.sh
[root@maswachid ~]#

Execute such command, log out, log in and You'll be able to execute:

[root@maswachid ~]# php7 -v
-bash: php: command not found
[root@maswachid ~]# exit
logout
Connection to 192.168.71.24 closed.
[wachid@SSH-SERVER ~]$ ssh [email protected]
[email protected]'s password:
Last login: Tue Oct 16 11:25:12 2018 from 192.168.71.28
[root@maswachid ~]# php7 -v
PHP 7.1.23 (cli) (built: Oct 16 2018 15:01:35) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
[root@maswachid ~]#

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