I. Installation of Nginx
An order to fix:
USE=FASTCGI emerge Nginx
New Users and Groups:
Groupadd www
Useradd www-g www
Nginx installed by default will add Nginx group and Nginx users, but I am still accustomed to create a new www group and WWW users to do HTTP service users. If future HTTP servers are replaced with Apache or LIGHTTPD, user names and user groups can be unchanged.
Second, the installation of MySQL
You must install MySQL before installing PHP, because the MySQL operation function in PHP requires the support of MySQL header files and libraries.
Emerge Dev-db/mysql
Initialize database:
The default path for the database is/var/lib/mysql, and the installation of this article puts it in/work/db/3306/data.
Copy Code code as follows:
Mkdir-p/work/db/3306/data
mysql_install_db--basedir=/usr--datadir=/work/db/3306/data--user=mysql
To modify a configuration file:
Vim/etc/mysql/my.cnf
Modify the DataDir to:
DataDir =/work/db/3306/data
Start MySQL:
/etc/init.d/mysql start
To modify the root password:
Mysqladmin-uroot Password hily
Test database:
Mysql-uroot-p
Show:
Gentoo Setup # Mysql-uroot-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server version:5.0.84-log Gentoo Linux mysql-5.0.84-r1
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>
Test success!
Third, the installation of PHP
To run PHP in fastcgi mode, you need to install PHP-FPM.
The last version of PHP that needs to be installed in patch format PHP-FPM is the 5.3.0,php 5.3.2 version that will potentially integrate PHP-FPM directly.
Here I will use PHP 5.3 0来 installation.
Because the directory in the Gentoo has not yet integrated the PHP-FPM Portage, the following is installed directly through the source code compilation form.
Download PHP 5.3.0:
wget http://cn.php.net/distributions/php-5.3.0.tar.bz2
Download PHP-FPM Patch:
wget http://php-fpm.org/downloads/php-5.3.0-fpm-0.5.12.diff.gz
Unzip PHP and play FPM Patch:
Tar jxf php-5.3.0.tar.bz2
GZIP-CD php-5.3.0-fpm-0.5.12.diff.gz | Patch-d PHP-5.3.0-P1
Install the library required by PHP (depending on your needs):
Emerge libpng
Emerge JPEG
Emerge FreeType
use= "png jpeg TrueType" emerge GD
or directly:
use= "png jpeg TrueType" emerge GD
Configure and compile PHP (as appropriate):
Copy Code code as follows:
CD php-5.3.0
./configure--prefix=/usr/local/php--with-config-file-path=/usr/local/php/etc
--WITH-MYSQL=/USR--with-mysqli=/usr/bin/mysql_config--enable-fpm--enable-sockets
--enable-pdo--with-pdo-mysql=/usr--with-gd--with-jpeg-dir--with-png-dir
--with-freetype-dir--with-zlib
Make && make install
PHP configuration file:
Copy Code code as follows:
CP Php.ini-production/usr/local/php/etc/php.ini
PHP-FPM configuration file:
Vim/usr/local/php/etc/php-fpm.conf
Modify listen_address to socket address (socket is more efficient than Ip:port):
<value name= "Listen_address" >/tmp/php-fpm.sock</value>
To modify user groups and user names:
Copy Code code as follows:
Unix User of processes
<value name= "User" >www</value>
Unix Group of processes
<value name= "group" >www</value>
Modify the PHP-FPM run mode to Apache-like mode:
Copy Code code as follows:
<value name= "Style" >apache-like</value>
<value name= "Startservers" >1</value>
<value name= "Minspareservers" >1</value>
<value name= "Maxspareservers" >5</value>
Startservers, Minspareservers and maxspareservers are set according to actual needs, I am here a virtual machine, not necessarily too big.
PHP-FPM Startup script:
cp/usr/local/php/sbin/php-fpm/etc/init.d/php-fpm
Start PHP-FPM
/ETC/INIT.D/PHP-FPM start
Add Start Service
Copy Code code as follows:
Rc-update Add nginx Default
Rc-update Add MySQL Default
Rc-update Add php-fpm Default
Test nginx+php
To add a test Site Directory:
Copy Code code as follows:
Mkdir-p/work/www/test
echo "<?php phpinfo ();?>" >/work/www/test/index.php
To add a Nginx configuration for a test site:
Vim/etc/nginx/nginx.conf
Comment out the server segment, and at the end of the HTTP segment, add:
Include sites/*.enable;
The configuration files for each site are then saved in a separate file in the/etc/nginx/sites directory for easy management and maintenance.
Mkdir/etc/nginx/sites
Vim/etc/nginx/test.enable
The test.enable configuration is as follows:
Copy Code code as follows:
server {
Listen 80;
server_name test.local;
Access_log/work/www/logs/test.access.log main;
Error_log/work/www/logs/test.error.log;
Location/{
Root/work/www/test;
Index index.html index.htm index.php;
}
Location ~ \.php$ {
Root/work/www/test;
Fastcgi_index index.php;
Fastcgi_param script_filename $document _root$fastcgi_script_name;
Include Fastcgi_params;
Fastcgi_pass Unix:/tmp/php-fpm.sock;
}
}
New Storage Log directory:
Mkdir/work/www/logs
Add records in local hosts:
192.168.1.10 test.local
192.168.1.10 is the IP of my Gentoo machine.
Reload Nginx Configuration
/etc/init.d/nginx Reload
Access:
http://test.local/
Displays the normal phpinfo information, the installation is complete.