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