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

HTTP return code list (Chinese and English explanation)

http return code list (below is an overview) for ...

Handwritten Vue2.0 data hijacking example

Table of contents 1: Build webpack 2. Data hijack...

Common usage of regular expressions in Mysql

Common usage of Regexp in Mysql Fuzzy matching, c...

A practical record of checking and processing duplicate MySQL records on site

Table of contents Preface analyze Data Total Repe...

How to run Linux commands in the background

Normally, when you run a command in the terminal,...

JavaScript to achieve a simple countdown effect

This article example shares the specific code of ...

Solution for Vue routing this.route.push jump page not refreshing

Vue routing this.route.push jump page does not re...

In-depth explanation of Session and Cookie in Tomcat

Preface HTTP is a stateless communication protoco...

Examples of using Docker and Docker-Compose

Docker is an open source container engine that he...

How to modify the ssh port number in Centos8 environment

Table of contents Preface start Preface The defau...

A brief discussion on MySQL count of rows

We are all familiar with the MySQL count() functi...

MySQL 8.0.21.0 Community Edition Installation Tutorial (Detailed Illustrations)

1. Download MySQL Log in to the MySQL official we...

Pure CSS to achieve the water drop animation button in Material Design

Preface You should often see this kind of special...