: This article describes how to install PHP5.6 on centos (64-bit) and configure LNMP. if you are interested in the PHP Tutorial, refer to it. The first time I made up my mind to build a development environment on Linux on LNPM, it was much harder than win. The virtual machine centos6.5, I searched some tutorials online and picked up my sleeves to work. I didn't expect one from the beginning of the Chinese New Year to the new year, from time to time, google the vpn. Fortunately, I finally got it done. The following describes the pitfalls I encountered and the entire solution process.
First pitfall: php file not found in nginx.
Cause: nginx web php is executed through php-fpm. PHP versions earlier than PHP5.3.3 need to install the php-fpm patch package separately. later versions are not required. Compile PHP correctly and start php-fpm. just configure it in colleague nginx. conf, with emphasis on SCRIPT_FILENAME $ document_root $ fastcgi_script_name. this cannot be written to death, as shown below:
Location ~ \. Php $
{
# Fastcgi_pass unix:/tmp/php-cgi.sock;
Fastcgi_pass 127.0.0.1: 9000; # fastcgi listening port, listening to php-fpm */
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fcinclude GI. conf; # fastcgi configuration file, changed to the following content */
}
Second challenge: connect to the database. Fatal error: Call to undefined function mysql_connect ()
I do not know that all PHP modules in Linux need to be compiled. The first installation of PHP does not matter. the parameter after/configure is copied from the Internet for direct execution, resulting in database function failure for a week. According to what I can understand, the./configure parameter has the following meanings:
-- Prefix =/usr/local/php # This is the php installation path.
-- With-mysql =/usr # This is the mysql-related compilation path. many of them are online -- with-mysql =/usr/share/mysql, but I do this, after compilation, an error is prompted, Cannot find MySQL header files under/usr/share/mysql. after investigation, it is found that it is caused by a 64-bit computer, the correct syntax is to use find/-name mysql first. h. find mysql. h path, and then write the prefix of the path. For example, the path/usr/include/mysql. h is found on my computer, so the prefix is/usr.
-- With-mysql-sock -- with-mysqli =/usr/lib64/mysql/mysql_config # This should be mysqli compilation configuration. the following parameters can be found/-name mysql_config first, and then filled in
-- Enable-fpm # enable the php-fpm function
Third pitfall: mysql. h not found
I used yum install mysql-server to install mysql, But mysql. h cannot be found,
Yum install mysql-devel is also required
In the process of solving Fatal error: Call to undefined function mysql_connect (), php is taken for granted. mysql is not enabled in ini. so, go to the cd ext/mysql /,
Run/usr/local/php/bin/phpize
Then compile,
. /Configure -- with-php-config =/usr/local/php/bin/php-config -- with-mysql =/usr/local/mysql/-- with-zlib-dir = /usr/local/lib
Here I have tried -- with-mysql =/usr/local/mysql/and -- with-mysql =/usr
Finally, the compiled mysql is added in/usr/local/lib/php/extensions/no-debug-non-zts-20090626. so, modify php. ini, add extension = mysql. so, restart php-fpm (note: modify php. it is useless to restart nginx in Linux after ini. you need to restart php-fpm.
Maybe my method is incorrect. Finally, I decided to try again. I deleted all mysql and php reinstalls. Finally.
The following is the installation process. because mysql path is required to compile PHP, mysql must be installed first. you can compile mysql by using/usr/local/php/bin/phpize. so, but I failed. To reduce unnecessary troubles, install mysql first and then PHP. nginx can be installed whenever necessary.
Step 1: mysql
Yum install mysql-server # ask if you want to install it. enter Y to install it automatically until the installation is complete.
/Etc/init. d/mysqld start # start MySQL
Chkconfig mysqld on # set to boot
Cp/usr/share/mysql/my-medium.cnf/etc/my. cnf # Copy the configuration file (note: If there is a my. cnf under the/etc directory by default, directly overwrite it)
Shutdown-r now # restart the system
2. set a password for the root account
Mysql_secure_installation
Press enter and enter Y as prompted.
Enter the password twice and press enter.
Enter Y as prompted
Thanks for using MySQL!
Step 2: install nginx
Yum install nginx # install nginx. enter Y as prompted to install nginx.
Service nginx start # start
Chkconfig nginx on # set to boot
/Etc/init. d/nginx restart # restart
Rm-rf/usr/share/nginx/html/* # Delete the default ngin test page
Note: The above two steps are from the http://www.osyunwei.com/archives/2353.html
If you think the yum installation version is not the latest, you can download the installation package from the nginx official website and then install it manually. The method is as follows:
In the directory/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 is the group and user that runs nginx. it is not added through add.
Make & make install
# Start nginx. nginx is started successfully.
/Usr/local/nginx/sbin/nginx-s reload
Ln-s/usr/local/nginx/sbin/nginx/usr/sbin/nginx // create nginx command soft connection
// Modify the nginx configuration file as needed.
Vim nginx. conf
Pay attention to modifying user nginx; remove it;
Step 3: install PHP
1. install components required for php, including images, emails, xml, and mbstring. The most important components include php-fpm.
I have referenced two blogs and wrote different component content. I have integrated the component content of the two blogs, which is not necessarily complete, but for more details, I have installed them using yum, as shown below:
Yum install-y gcc-c ++ autoconf php-mysql php-gd libjpeg-devel php-imap php-ldap php-odbc php-pear php-xmlrpc php-mbstring php -unzip php-bcmath php-mhash unzip kernel-devel libpng-devel freetype-devel libpng-devel libxml2 libxml2-devel zlib-devel glibc-devel glib2 glib2-devel kernel bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c-devel php-fpm
2. install php with nginx. you can use yum install php or download the installation package. I downloaded php-5.6.5.tar.gz and put it 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-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 an error occurs during compilation, do not execute make. Solve the error first. In this step, I encountered mysql-related error information. then I changed -- with-mysql =/usr/local/mysql to -- with-mysql =/usr (that is, mysql. h directory prefix, no mysql. h refer to the 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
// Copy and rename
/Usr/local/php/sbin/php-fpm
// Start php-fpm
Modifying the FPM profile 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 and set the parameter value according to your needs. this is only the recommended value.
Ln-s/usr/local/php/sbin/php-fpm/bin/php-fpm
Add the php-fpm command
Cp/usr/local/src/php. ini-producsion/usr/local/php/lib/php. ini
Note: cp is not required. When I installed php for the second time, the wait time after the make command was very long, probably four or five times the length of my previous installation, therefore, I suspect that many php modules have not been installed for the first time. after this installation, I checked phpinfo () and found a lot more information, including php. ini is displayed in the/etc/directory and does not need to be copied from the php Directory. it is generated by installation and php. ini does not have mysql either. so, but the mysql function is enabled, so it is also compiled and installed automatically. you only need to install all the compilation parameters and components when installing php.
So far, configure the local/php parameters of nginx. conf, restart nginx, mysql, and php-fpm.
Success
Refer to blog:
Http://www.aichengxu.com/view/35376
Http://www.osyunwei.com/archives/2353.html
The preceding section describes how to install PHP5.6 on centos (64-bit) and configure LNMP, including related content. if you are interested in the PHP Tutorial.