Method of compiling and installing PHP and Nginx in Ubuntu environment
- 2021-07-01 08:39:57
- OfStack
This article illustrates the method of compiling and installing PHP and Nginx in Ubuntu environment. Share it for your reference, as follows:
Compile and install nginx
Switch 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 the 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 the 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 up 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: 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
Source code compilation and installation php 5.6
Download the source code of php
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 Extensions
apt-get install libpng12-dev
freetype Extensions
apt-get -y install libfreetype6-dev
openssl Extensions
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
0
jpeg Extensions
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
1
Compile statement
Generate Configuration File
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
2
Once the dependent components are installed, no errors should be reported. If errors are reported, install the missing components and rebuild the configuration file.
Compile & Installation
make && make install
View php Server Configuration
When we migrate the server, the above-mentioned code for generating the configuration file needs to be straight from the original php server, which can be viewed using php-config-configure-options.
The position of php-config is php/bin/php-config
No php was found. ini?
After compiling and installing php directly, there is no php. ini. We can go from the extracted directory copy to/opt/php/lib, and then configure it to take effect.
/opt/php/lib is the path configured in./configure
I hope this article is helpful to everyone's Ubuntu environment configuration.