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

Detailed explanation of mysql basic operation statement commands

1. Connect to MySQL Format: mysql -h host address...

Detailed explanation of JS ES6 variable destructuring assignment

Table of contents 1. What is deconstruction? 2. A...

Linux installation Redis implementation process and error solution

I installed redis today and some errors occurred ...

Detailed explanation of MySQL Explain

In daily work, we sometimes run slow queries to r...

Html page supports dark mode implementation

Since 2019, both Android and IOS platforms have s...

React uses emotion to write CSS code

Table of contents Introduction: Installation of e...

Solution to invalid margin-top of elements in div tags

Just as the title says. The question is very stran...

Case study of dynamic data binding of this.$set in Vue

I feel that the explanation of this.$set on the I...

Commonplace talk about the usage of MYSQL pattern matching REGEXP and like

like LIKE requires the entire data to match, whil...

An article to show you how to create and use Vue components

Table of contents 1. What is a component? 2. Crea...

MySQL Flush-List and dirty page flushing mechanism

1. Review The Buffer Pool will be initialized aft...

The difference between html Frame, Iframe and Frameset

10.4.1 The difference between Frameset and Frame ...

JS implements a simple brick-breaking pinball game

This article shares the specific code of JS to im...