LNMP environment configuration of the compiler source code to install PHP method

Source: Internet
Author: User
Tags fpm install php install openssl mysql client openssl php development environment php source code zend

We use vagrant to build a virtual environment, where we use the box "chef/centos-6.5", which is a purer CentOS-6.5 system. For information on how to use vagrant, refer to Vagrant QuickStart.

$ vagrant Init chef/centos-6.5
$ vagrant Up

After executing the above command, a centos-6.5 virtual machine has been created and started, when we use the command SSH to connect to the virtual machine.

$ vagrant SSH

The prompt becomes a [vagrant@localhost ~]$, which indicates a successful connection to the virtual machine. Next, we can start the installation configuration of the PHP development environment.
If you do not use vagrant, you can install a CentOS system or a virtual machine yourself, the following steps are not directly related to vagrant.

Compile the source code to install PHP

First of all, download the PHP installation files, we use the source code to compile and install PHP 5.4.35 to php website download php installation files.

$ wget http://jp1.php.net/distributions/php-5.4.35.tar.gz
$ TAR-ZXVF php-5.4.35.tar.gz
$ CD php-5.4.35

Next to the PHP source code to compile the installation, access to the source directory, the following command to install:

Note that if MySQL is needed, it is best to provide the parameters at variance and specify that the MYSQLND library should be used, otherwise a separate compilation extension can only be installed using the MySQL Client library.

$./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc--with-iconv-dir-- With-freetype-dir--with-jpeg-dir--with-png-dir--with-zlib--with-libxml-dir=/usr--enable-xml-- Enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--with-curl--with-curlwrappers-- Enable-mbregex--enable-fpm--enable-mbstring--with-mcrypt--enable-ftp--WITH-GD-- With-openssl--with-mhash--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip- With-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd

After you execute the above command, you are prompted with the following error:

Configure:error:no acceptable C compiler found in $PATH

This is because the GCC compiler is not installed and we need to install GCC first.

$ sudo yum install gcc

After installation, recompile, this time a new error has occurred:

Configure:error:xml2-config not found. Please check your LIBXML2 installation.

Hint can not find libxml2, no problem, install it on the line.

$ sudo yum install Libxml2-devel

Continue to recompile, the process of compiling the installation is to solve the problem of the process, each encounter problems, we go to solve the problem, nothing can be our!

Configure:error:Cannot find OpenSSL ' s <evp.h>

Because we have--WITH-OPENSSL enabled, we need to install Openssl-devel.

$ sudo yum install Openssl-devel

Compile again, prompting

Configure:error:Please Reinstall the Libcurl distribution-
Easy.h should be in <curl-dir>/include/curl/

The error has been explained, install Libcurl

$ sudo yum install Libcurl-devel

Continue compiling, we will also encounter the following error

Configure:error:jpeglib.h not found.

Because our compilation parameters provide support for the GD library, we need to install the following libraries.

$ sudo yum install libjpeg libjpeg-devel
$ sudo yum install libpng libpng-devel
$ sudo yum install FreeType freetype-devel

Installed so many Lib, the total should be successful, compile again, the tragedy is, and the error:

Configure:error:mcrypt.h not found. Please reinstall Libmcrypt.

We also need to install Libmcrypt, this lib in the Yum is not, so need to download down, manual compilation.

$ wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz
$ TAR-ZXVF libmcrypt-2.5.7.tar.gz
$ CD libmcrypt-2.5.7
$./configure
$ make
$ sudo make install

OK, we compile again, this time must be successful, no success will not play ... Luckily, this configure succeeded, bang, compiled and installed:

$ make
$ sudo make install

Everything goes well, we have successfully compiled and installed PHP, the installation directory in/usr/local/php.
Finally, we need to provide the PHP configuration file php.ini.

$ sudo cp Php.ini-development/usr/local/php/etc/php.ini
$ sudo mv/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf

The installation directory for PHP is specified by the Configure--prefix= directory parameter. In addition, here we build is for the development of the environment, if necessary as a production environment, you need to pay attention to some security issues, while it is recommended not to copy php.ini-development files, but copy php.ini-production files.
Check out the PHP version:

$/usr/local/php/bin/php--version
PHP 5.4.35 (CLI) (Built:nov 25 2014 08:23:11)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies

For ease of operation, you can add PHP's Bin directory to environment variables. Edit ~/.bash_profile, add the following line above the export path:

Path= $PATH:/usr/local/php/bin

Then execute the following command

$ source ~/.bash_profile

This way, we can use the command directly without adding a directory.
Tip: How do I see which configuration file PHP is using?
$ strace-e Open php 2>&1 |grep php.ini
Open ("/usr/local/php/bin/php.ini", o_rdonly) =-1 enoent (No such file or directory)
Open ("/usr/local/php/etc/php.ini", o_rdonly) = 3

If the Strace command is not installed, use the Yum install Strace installation.
Install extension
Setup completes the basic PHP, then we need to install some extensions that meet the business needs.
Install YAF Development Framework Extension
Execute the following command to install using PECL:

$ sudo/usr/local/php/bin/pecl Install Yaf

Without exception, the above command is sufficient to complete the YAF installation, and next, you need to enable the YAF extension in the php.ini file. Edit/usr/local/php/etc/php.ini and add the following

Extension=yaf.so

Installing MySQL and mysqli extensions

Install MySQL related extensions, recommend the use of Mysqlnd library, but looking for a long time, it is not found a good way to compile the MySQL extension using the MYSQLND library, and finally see the following paragraph in the document:

The MySQL database extensions must is configured to use the MySQL Client Library. In order to use the MySQL Native Driver, PHP needs to is built specifying that MySQL database extensions are compiled With MySQL Native Driver support. This is done through configuration options prior to building the PHP source code.

It is said that if you install the MySQL extension, you can only use the MySQL Client Library (Baidu/Google has a lot of installation tutorials). If you want to use the MYSQLND library, you can only specify it when compiling PHP. As a result, it seems like you can only recompile PHP. If you have a good idea, you can exchange and communicate.

Installing Eaccelerator Extensions

$ wget Https://github.com/eaccelerator/eaccelerator/archive/master.zip-O Eaccelerator.zip
$ sudo yum install unzip
$ unzip Eaccelerator.zip
$ CD eaccelerator-master/
$ phpize
$./configure--enable-shared
$ make
$ sudo make install

To add Eaccelerator configuration information to the php.ini:

zend_extension= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/eaccelerator.so"
Eaccelerator.shm_size= "16"
Eaccelerator.cache_dir= "/tmp/eaccelerator"
eaccelerator.enable= "1"
Eaccelerator.optimizer= "1"
Eaccelerator.check_mtime= "1"
eaccelerator.debug= "0"
Eaccelerator.filter= ""
Eaccelerator.shm_ttl= "0"
eaccelerator.shm_prune_period= "0"
eaccelerator.shm_only= "0"

Executive Php-v can see

$ php-v
PHP 5.4.35 (CLI) (Built:nov 25 2014 10:40:18)
Copyright (c) 1997-2014 the PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
With Eaccelerator V1.0-dev, the Copyright (c) 2004-2012 eaccelerator, by Eaccelerator

Installing Xdebug Extensions

$ wget Http://github.com/xdebug/xdebug/archive/master.zip-O Xdebug.zip
$ unzip Xdebug.zip
$ CD Xdebug-master
$/usr/local/php/bin/phpize
$./configure--enable-xdebug
$ make
$ sudo make install

Next configure PHP.ini to join the extension

zend_extension= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
Xdebug.remote_enable=1
Xdebug.remote_host=localhost
xdebug.remote_port=9000
Xdebug.remote_connect_back=1
; xdebug.remote_autostart=1

Installing Opcache Extensions

Because Eaccelerator has not been maintained for a long time, so you can consider using Opcache.

$ wget http://pecl.php.net/get/zendopcache-7.0.3.tgz
$ TAR-ZXVF zendopcache-7.0.3.tgz
$ CD zendopcache-7.0.3
$ phpize
$ make
$ sudo make install

Next you need to configure PHP.ini to enable the extension.
Note: If used with xdebug, you need to ensure that Opcache is loaded before xdebug.

zend_extension= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/opcache.so"
Opcache.memory_ consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
Opcache.fast_shutdown=1
Opcache.enable_cli=1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.