Ubuntu Install PHPRecord the main process and the pits encountered.
First download php,http://php.net/downloads.php, I use the version of 5.6.25:
wget http://cn2.php.net/distributions/php-5.6.25.tar.gz
After downloading, unzip to the server random directory
Tar xzvf php-5.6.25.tar.gz
Add www user
Groupadd www
Useradd-g www www
After that, configure compiles as follows:
#./configure \--prefix=/usr/local/php56 \--with-config-file-path=/usr/local/php56/etc \-- Enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-opcache \--enable-fpm \-- With-fpm-user=www \--with-fpm-group=www \--with-mysql=mysqlnd \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \-- With-gettext \--enable-mbstring \--with-iconv \--with-mcrypt \--with-mhash \--with-openssl \--enable-bcmath \-- Enable-soap \--with-libxml-dir \--enable-pcntl \--enable-shmop \--enable-sysvmsg \--enable-sysvsem \--ENABLE-SYSVSHM \--enable-sockets \--with-curl \--with-zlib \--enable-zip \--with-bz2 \--with-readline
./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--enable-inline-optimization-- Disable-debug--disable-rpath--enable-shared--enable-opcache--enable-fpm--with-fpm-user=www--with-fpm-group=www --with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-gettext--enable-mbstring--with-iconv-- With-mcrypt--with-mhash--with-openssl--enable-bcmath--enable-soap--with-libxml-dir--enable-pcntl--enable-shmop --enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-sockets--with-curl--with-zlib--enable-zip--with-bz2-- With-readline--WITH-GD--enable-gd-native-ttf--enable-gd-jis-conv
The following errors may occur at this time:
Mcrypt.h not found. Please reinstall Libmcrypt
Reason: CentOS source can not install libmcrypt-devel, due to copyright reasons did not bring MCrypt package download libmcrypt-2.5.8.tar.gz, and then install, as follows:
TAR-ZXVF libmcrypt-2.5.8.tar.gz
cd/usr/local/src/libmcrypt-2.5.8
./configure--prefix=/usr/local
The following error may occur:
configure:error:c++ compiler cannot create executables
A reliable solution is to:
Yum Install gcc gcc-c++ gcc-g77
And then re-execute, the problem should be solved.
Make
Make install
Then configure again, you may encounter the following error:
Error:don ' t know how to define struct flock on the This system, set--enable-op
A reliable solution is to:
sudo ln-s/usr/local/mysql/lib/libmysqlclient.so/usr/lib/
sudo ln-s/usr/local/mysql/lib/libmysqlclient.so.18/usr/lib/libmysqlclient.so.18
export
LD_LIBRARY_PATH=
/lib/
:
/usr/lib/
:
/usr/local/lib:/usr/local/mysql/lib
Again, should not be an error.
Make
Make install
Note: When a low-profile server, such as less than 1GB, may have the following error when make occurs:
Make: * * * [Ext/fileinfo/libmagic/apprentice.lo] Error 1
Solutions
This is caused by less than 1G of memory.
In the./configure Plus option:
--disable-fileinfo
Disable FileInfo Support Disable FileInfo
Or, re-make may pass.
[Email protected] bin]#./php-version
PHP 5.6.28 (CLI) (Built:nov 18 2016 13:02:58)
Copyright (c) 1997-2016 the PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
Configure PHP
[Email protected] php-5.6.28]#
cp php.ini-development /usr/local/php56/etc/php.ini
Configuring the PHP-FPM Service
# cp /usr/local/php56/etc/php-fpm.conf.default /usr/local/php56/etc/php-fpm.conf
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm56
# chmod +x /etc/init.d/php-fpm56
Start PHP-FPM
# service php-fpm56 start
Starting php-fpm done
到此为止,php本身的安装和配置就完成了,如何验证呢。。。。
很重要的一点是:php本身并不是一个web服务器,只是一个web服务器后面的cgi实现,就像java本身并不提供http服务一样,前台有个tomcat。
所以php要依赖于nginx或者apache作为前置,因为我们一直用nginx,所以以nginx为例。
首先,我不得不说nginx自带的nginx.conf中配置php的示例代码是坑。。。
读者直接参考php官方给的即可,http://php.net/manual/zh/install.unix.nginx.php。亲测,没有问题的。
Ubuntu Install PHP