CentOS (64-bit) install PHP5.6, configure LNMP

Source: Internet
Author: User
Tags fpm gmp mcrypt pear php source code php tutorial
Determined to make the whole LNPM, for the first time in the Linux development environment, more difficult than win. Virtual machine centos6.5, online search a number of tutorials, roll up the sleeves open dry, didn't think pit one by one, from the Chinese New year before to the new year, the whole I was disgraced, from time to time hang VPN Google a bit. Fortunately, I finally got it done. Here's a look at the pits I've encountered and the whole process of solving them.

First pit: Nginx under PHP file not found.

Reason: Nginx Web execution PHP is executed through PHP-FPM, PHP5.3.3 previous PHP needs to install PHP-FPM patch package Separately, the future version is not required. Compile PHP correctly and start php-fpm, colleagues nginx.conf in the configuration is OK, the focus is Script_filename $document _root$fastcgi_script_name; This cannot be written dead, as follows:

Location ~ \.php$

{

#fastcgi_pass Unix:/tmp/php-cgi.sock;

Fastcgi_pass 127.0.0.1:9000; #fastcgi监听端口, monitoring php-fpm*/

Fastcgi_index index.php;

Fastcgi_param script_filename $document _root$fastcgi_script_name;

Include fcgi.conf; #fastcgi配置文件, modify to the following: */

}

Second pit: Connect to the database. Fatal error:call to undefined function mysql_connect ()

Because I do not know that the Linux PHP modules need to be compiled, the first time to install PHP did not care. After the/configure parameters, from the online copy of a direct execution, resulting in the database function has been unsuccessful, tossing for a week. According to the part I can read, the./configure parameter has the following meanings:

--prefix=/usr/local/php # This is the installation path for PHP

--with-mysql=/usr #这是mysql相关编译路径, here on the Internet many are--with-mysql=/usr/share/mysql, but I do, compile the prompts a Error,cannot find MySQL header files Under/usr/share/mysql, after checking, some say that because of 64-bit computers, the correct way to write is to first find the path of mysql.h by finding/-name mysql.h and then writing the prefix of the path. For example, my Computer search out path/usr/include/mysql/mysql.h, so the prefix is/usr

--with-mysql-sock--with-mysqli=/usr/lib64/mysql/mysql_config # This should be the mysqli compile configuration, the following parameters can be first find/-name Mysql_ Config, and then fill in

--ENABLE-FPM # turn on php-fpm function

The third pit: Can't find mysql.h

I installed MySQL with yum install MySQL Mysql-server, but could not find mysql.h, after checking,

Also need yum install Mysql-devel

In my solution fatal error:call to undefined function mysql_connect () process, take for granted that PHP.ini did not open mysql.so, so in the PHP source code into the CD ext/mysql/,

Executive/usr/local/php/bin/phpize

And then compile,

./configure--with-php-config=/usr/local/php/bin/php-config--with-mysql=/usr/local/mysql/--with-zlib-dir=/usr/ Local/lib

I've tried--with-mysql=/usr/local/mysql/and--with-mysql=/usr here.

Finally, the compiler-generated mysql.so is added in/usr/local/lib/php/extensions/no-debug-non-zts-20090626/, the php.ini is modified, and the extension= is added. mysql.so, restart PHP-FPM (Note: Modify the php.ini after the Linux restart Nginx is no use, need to restart PHP-FPM), or did not solve the problem.

Maybe I'm not doing it right. Finally decided to start again, I deleted the MySQL, PHP all reload. Well, finally.

The following is the installation process, because compiling PHP needs to use the MySQL path, so you must first install MySQL, there is blog write can be/usr/local/php/bin/phpize after compiling mysql.so, but I did not succeed. To reduce unnecessary hassles, install MySQL first, and then install Php,nginx when you install it.

First step: MySQL

Yum install MySQL mysql-server #询问是否要安装, enter y for automatic installation until installation is complete

/etc/init.d/mysqld Start #启动MySQL

Chkconfig mysqld on #设为开机启动

CP/USR/SHARE/MYSQL/MY-MEDIUM.CNF/ETC/MY.CNF #拷贝配置文件 (Note: If the/etc directory has a my.cnf under the default, you can directly overwrite it)

Shutdown-r now #重启系统

2. Set the password for the root account

Mysql_secure_installation

Enter, follow the prompts for Y

Enter Password 2 times, enter

Enter Y as prompted

Last appearance: Thanks for using mysql!

Step two, install Nginx

Yum install Nginx #安装nginx, follow the prompts, enter the Y installation can be installed successfully

Service Nginx Start #启动

Chkconfig Nginx on #设为开机启动

/etc/init.d/nginx Restart #重启

rm-rf/usr/share/nginx/html/* #删除ngin默认测试页

Note: The above two steps are derived from http://www.osyunwei.com/archives/2353.html

If you feel that the Yum installed version is not up to date, you can download the installation package on the Nginx website and install it manually. Here's how:

In the catalog/usr/local/src/nginx-1.7.5.tar.gz

Tar zxvf nginx-1.7.5.tar.gz

CD nginx-1.7.5
./configure--prefix=/usr/local/nginx--user=nginx--group=nginx--with-http_stub_status_module--without-http_ Rewrite_module--with-http_ssl_module--with-pcre

Note:--user=nginx--group=nginx This is a group and user that runs Nginx and does not add via add


Make && make install
#启动nginx, Nginx started successfully.
/usr/local/nginx/sbin/nginx-s Reload
ln-s/usr/local/nginx/sbin/nginx/usr/sbin/nginx//Establish nginx command Soft connection
//Next modify Nginx configuration file, modify the corresponding file as needed
Vim nginx.conf

Notice to modify the user nginx, remove;

Step three: Install PHP

1. Install the required components of PHP, including pictures, mail, XML, mbstring, etc., the most important include PHP-FPM

I refer to the two blog, the composition of the content is not the same, I have two pieces of the content of the blog to do the assembly and not necessarily complete, but more detailed, installed with Yum, as follows:

Yum install-y gcc gcc-c++ autoconf php-mysql php-gd libjpeg libjpeg-devel php-imap php-ldap php-odbc php-pear php-xmlrpc Php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel libpng libpng-devel freetype freetype-devel Libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses cu RL Openssl-devel gdbm-devel db4-devel libxpm-devel libx11-devel gd-devel gmp-devel readline-devel libxslt-devel Expat-devel xmlrpc-c Xmlrpc-c-devel php-fpm

2. Install PHP with Nginx installation, you can use yum install PHP, you can download the installation package, I downloaded the php-5.6.5.tar.gz, placed under/usr/local/src/

Tar zxvf php-5.6.5.tar.gz

CD php-5.6.5

./configure--prefix=/usr/local/php--with-mysql=/usr--with-mysql-sock--with-mysqli=/usr/lib64/mysql/mysql_ Config--enable-fpm--with-ncurses--enable-soap--with-libxml-dir--with-xmlrpc--with-openssl--with-mcrypt-- With-mhash--with-pcre-regex--with-sqlite3--with-zlib--enable-bcmath--with-iconv--with-bz2--enable-calendar-- With-curl--with-cdb--enable-dom--enable-exif--enable-fileinfo--enable-filter--with-pcre-dir--enable-ftp-- WITH-GD--with-openssl-dir--with-jpeg-dir--with-png-dir--with-zlib-dir--with-freetype-dir--enable-gd-native-ttf --enable-gd-jis-conv--with-gettext--with-gmp--with-mhash--enable-json--enable-mbstring--disable-mbregex-- Disable-mbregex-backtrack--WITH-LIBMBFL--with-onig--enable-pdo--with-pdo-mysql--with-zlib-dir--with-pdo-sqlite --with-readline--enable-session--enable-shmop--enable-simplexml--enable-sockets--enable-sqlite-utf8-- Enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-wddx--with-libxml-dir--with-xsl--enaBle-zip--enable-mysqlnd-compression-support--with-pear

Note: If the compilation has an error, do not perform make, first resolve the error. I have MySQL-related error information in this step, and then I changed the--with-mysql=/usr/local/mysql to --with-mysql=/ USR (that is, mysql.h directory prefix, no mysql.h refer to previous installation)

Make && make install

Build complete.

Don ' t forget to run ' make test '.

Cp/usr/local/php/etc/php-fpm.conf.default php-fpm.conf

Duplicate a copy and rename it

/usr/local/php/sbin/php-fpm

Start PHP-FPM

Modify the FPM configuration file php-fpm.conf

Pm.max_children = 50

Pm.start_servers = 20

Pm.min_spare_servers = 5

Pm.max_spare_servers = 35

Pm.max_requests = 500

Remove the semicolon, the parameter value is set according to your own needs, this is only the recommended value

Ln-s/USR/LOCAL/PHP/SBIN/PHP-FPM/BIN/PHP-FPM

Add PHP-FPM Command

Cp/usr/local/src/php/php.ini-producsion/usr/local/php/lib/php.ini

Note: The CP step is not required. The second time I installed PHP, the make command after the wait time is very long, probably my previous installation time length of 4, 5 times times, so I suspect that the first time to install a lot of PHP modules are not installed, this time after the installation of the Phpinfo (), the display of the information is also many, Where php.ini is displayed in the/etc/directory, do not need to copy from the PHP directory, is the installation generated, and, php.ini is not mysql.so, but the MySQL function is open, so it is compiled, installed automatically, only need to install PHP when the compilation parameters, Components can be installed completely.

At this point, configure the nginx.conf local/php parameter, restart Nginx, restart MySQL, restart the PHP-FPM

Done

Reference blog:

http://www.aichengxu.com/view/35376

Http://www.osyunwei.com/archives/2353.html

The above describes the CentOS (64-bit) installation PHP5.6, configuration Lnmp, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • 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.