How to compile and install PHP and Nginx in Ubuntu environment

How to compile and install PHP and Nginx in Ubuntu environment

This article describes how to compile and install PHP and Nginx in Ubuntu environment. Share with you for your reference, the details are as follows:

Compile and install nginx

Change directory to the working folder:

cd /usr/local/src

Download the pcre source code and install it

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.20.tar.gz
tar -zxvf pcre2-10.20.tar.gz
mv ./pcre2-10.20.tar.gz ./pcre 
cd pcre
./configure --prefix=/usr/local/pcre
make && make install

Download zlib source code and install

wget http://tenet.dl.sourceforge.net/project/libpng/zlib/1.2.8/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
mv ./zlib-1.2.8.tar.gz ./zlib
cd zlib
./configure --prefix=/usr/local/zlib
make && make install

Download nginx source code and install

wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre --with-zlib=/usr/local/zlib
make && make install

Start nginx at boot

Add /ect/init.d/nginx and write the script

#!/bin/bash
# Description: Startup script for webserver on CentOS. cp it in /etc/init.d and
# chkconfig --add nginx && chkconfig nginx on
# then you can use server command to control nginx
#
# chkconfig: 2345 08 99
# description: Starts, stops nginx
set -e
PATH=$PATH:/usr/local/nginx/sbin/
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/nginx.conf
PIDFILE=/var/run/nginx.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
d_start() {
$DAEMON -c $CONFIGFILE || echo -n " ​​already running"
}
d_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " ​​not running"
}
d_reload() {
kill -HUP `cat $PIDFILE` || echo -n " ​​can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload
echo -n "Reloading $DESC configuration..."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0

chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on
service nginx start

Compile and install php5.6 from source code

Download PHP source code

cd /usr/local/src
wget http://cn2.php.net/get/php-5.6.24.tar.gz/from/this/mirror
mv mirror php-5.6.24.tar.gz
tar -zxvf php-5.6.24.tar.gz
cd php-5.6.24

Install dependent components

XML extension

apt-get install libxml2-dev

png extension

apt-get install libpng12-dev

FreeType extension

apt-get -y install libfreetype6-dev

openssl extension

apt-get install openssl
apt-get install libcurl3-openssl-dev

jpeg extension

apt-get install libjpeg-dev

Compile Statement

Generate configuration files

./configure --prefix=/opt/php --with-config-file-path=/opt/php/lib --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl-dir=/usr --with-openssl --with-pdo-mysql=mysqlnd --with-pear --enable-sockets --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli

After installing the dependent components, there should be no errors. If errors occur, please install the missing components and regenerate the configuration file.

Compile & Install

make && make install

View PHP server configuration

When we migrate the server, the code for generating the configuration file needs to be consistent with the original PHP server. We can use php-config --configure-options to view it.

The location of php-config is php/bin/php-config

No php.ini found?

After compiling and installing PHP directly, there is no php.ini. We can copy it from the decompressed directory to /opt/php/lib, and then configure it to take effect.

/opt/php/lib is the path configured in ./configure

I hope this article will help you configure your Ubuntu environment.

You may also be interested in:
  • How to compile and install PHP 5.3.3+memcache on Ubuntu
  • Compile and install PHP5.3 development environment under Ubuntu12
  • Tutorial on compiling and installing PHP 5.6.29 from source code on Ubuntu 16.04
  • Specific steps to compile and install xcache for php5.3 under ubuntu
  • Ubuntu nginx compile and install parameter configuration
  • Specific steps for installing and configuring nginx+php+mysql based on ubuntu
  • How to install PHP and configure PHP Nginx on Ubuntu
  • Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator installation and configuration text version
  • Xen-based VPS ubuntu+nginx+php installation tutorial
  • How to install nginx+mariaDB+php7+YAF on ubuntu14.04LTS
  • Installing LEMP Stack for Nginx Server in Ubuntu 16.04 (MariaDB, PHP 7 and HTTP 2.0 Support)

<<:  MySQL 8.0.12 installation and configuration graphic tutorial

>>:  Vue+thinkphp5.1+axios to realize file upload

Recommend

Use Visual Studio Code to connect to the MySql database and query

Visual Studio Code is a powerful text editor prod...

How to manually deploy war packages through tomcat9 on windows and linux

The results are different in Windows and Linux en...

33 of the best free English fonts shared

ChunkFive Free Typefamily Cuprum JAH I Free font Y...

Problems and solutions for MYSQL5.7.17 connection failure under MAC

The problem that MYSQL5.7.17 cannot connect under...

The difference between mysql outer join and inner join query

The syntax for an outer join is as follows: SELEC...

How to use MySQL 5.7 temporary tablespace to avoid pitfalls

Introduction MySQL 5.7 aims to be the most secure...

Example code for evenly distributing elements using css3 flex layout

This article mainly introduces how to evenly dist...

Issues with using Azure Container Registry to store images

Azure Container Registry is a managed, dedicated ...

Difference and principle analysis of Nginx forward and reverse proxy

1. The difference between forward proxy and rever...