How to compile and install PHP and Nginx in Ubuntu environment

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

Compile and install nginx

Change directory to working folder:

cd /usr/local/src

Download the pcre source code and install

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

Boot nginx

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 control nginx
#
# chkconfig:23450899
# 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 0d_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

Source code compile and install php5.6

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 file

. /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 an error is reported, please install the missing components and then regenerate the configuration file.

Compile & install

make && make install

View php server configuration

When we migrate the server, the above code for generating the configuration file needs to be the same as the original PHP server, we can use php-config --configure-options to view.

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

Didn't find php.ini?

After directly compiling and installing php, there is no php.ini. We can copy from the decompressed directory to /opt/php/lib, and then make the configuration effective.

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

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

Recommended Posts

How to compile and install PHP and Nginx in Ubuntu environment
How to compile and install xdebug from source code in Ubuntu environment
How to install python in ubuntu server environment
How to install Helm in Ubuntu
How to install Nginx on Ubuntu 20.04
How to install PHP7.4 in CentOS
How to install mysql in Ubuntu 14.04
How to install Nginx on Ubuntu 20.04
How to install mysql in Ubuntu 14.04
How to install Nginx on Ubuntu 16.04
How to easily compile openJDK in Ubuntu
How to install cuda10.1 driver in Ubuntu
How to install ROS Noetic in Ubuntu20.04
How to install Ubuntu20.04 and install NVIDIA driver
How to install Pycharm and Ipython on Ubuntu 16.04/18.04
How to install and configure Gogs on Ubuntu 18.04
How to modify time zone and time in ubuntu
How to install and configure Cyberpanel on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure ownCloud on Ubuntu 16.04
How to install and configure GitLab on Ubuntu 18.04
How to install and use Docker on Ubuntu 20.04
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and secure phpMyAdmin on Ubuntu 16.04
How to install and configure Elasticsearch on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and configure VNC on Ubuntu 18.04
How to install and configure Sphinx on Ubuntu 16.04
How to install and configure OrientDB on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install php7.3 in centos8 custom directory
How to install and configure AppScale on Ubuntu 12.04
How to install and use Docker on Ubuntu 16.04
How to install and configure PostGIS on Ubuntu 14.04
CentOs7.3 compile and install Nginx 1.9.9
ubuntu18.04 compile and install python3.8
How to install Hadoop in standalone mode on Ubuntu 18.04
How to install and use MySQL Workbench on Ubuntu 18.04
How to modify time zone and time in ubuntu system
How to install theano and keras on ubuntu system
How to create a Python virtual environment in Ubuntu 14.04
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to use hanlp in ubuntu
How to install VirtualBox on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
How to install Vagrant on Ubuntu 20.04
How to install Bacula-Web on Ubuntu 14.04
How to install PostgreSQL on Ubuntu 16.04
How to install Git on Ubuntu 20.04
How to install Anaconda3 on Ubuntu 18.04
CentOS 6.x compile and install Nginx