Ali cloud today to buy a server for routine development test (new nine dollars six months). System Version CentOS 6.5 64 bits.
First install nginx:
yum install nginx
Reference documents:
LNMP built environment on CentOS 6
After installation is complete, use the service nginx start command to start the nginx error
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
Solution see:
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
Compiled and installed php-5.6.29:
./configure --prefix=/usr/local/php --enable-fpm --enable-debug
(Source installation is recommended - prefix to specify the installation path, on the one hand does not pollute the system directory, easy to unload on the other hand.)
Prompt an error:
configure: error: xml2-config not found. Please check your libxml2 installation.
It seems something missing:
yum install libxml2-devel
Continue:
./configure --prefix=/usr/local/php --enable-fpm --enable-debug
make && make install
Successful installation.
Subsequent successful installation steps:
# Copy the php.ini cp the php.ini-Development / usr / local / PHP / lib / the php.ini cp /usr/local/php/etc/php-fpm.conf.default / usr / local / PHP / etc / PHP - fpm.conf # Run PHP - FPM / usr / local / PHP / sbin / PHP- FPM # Php command will be added to the global we / root / .bash_profile The # / usr / local / PHP / bin added to the end, separated by a: PATH=$PATH:$HOME/bin:/usr/local/php/bin # Reboot source /root/.bash_profile
References:
centos6.5 install php development environment
Another problem: Because the source code is installed php, php-fpm and therefore will not be added to the system services.
Solution:
// into the source installation directory cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php- FPM chmod + the X-/etc/init.d/php-fpm
Now you can operate php-fpm through a service command.
Reference article:
Nginx and PHP-FPM start / restart script
Next also you need to do some configuration, so that nginx can parse php.
First, we add a new user to the system www.
useradd www;
groupadd www;
Nginx modify the configuration file (/etc/nginx/nginx.conf) of user entries,
user www www;
Php-fpm modified configuration file (/usr/local/php/etc/php-fpm.conf), where mainly modify the user, group entries. I direct my configuration posted just great:
[global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = notice [www] user = www group = www listen = 127.0.0.1:9000 listen.owner = www listen.group = www listen.mode = 0660 pm = static pm.max_children = 1 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 20
In order to test nginx can resolve php, we create a file in / usr / share / nginx under / html directory index.php, content
<?php echo "this is php index file"; ?>
(This directory there is a file index.html, it corresponds to our common nginx welcome page)
The last thing we need to do is to change the nginx configuration file. You can directly modify nginx.conf file, you can also modify files in the conf.d directory default.conf, of course, you can own a new file, it can be loaded into nginx as long as you can.
This article default.conf directly modify files in the conf.d directory.
The core reads as follows:
server { listen 80; server_name your_server_name; root /usr/share/nginx/html; index index.html index.htm index.php; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Here, all the work is complete.
(If you keep your index.php in a different directory, make sure www user can gain access to this file)
Browser and enter your_server_name / index.php, you can display the contents of index.php file we just created in the.
Reproduced in: https: //www.cnblogs.com/gattaca/p/6234534.html