1. Install Nginx
One command:
USE = fastcgi emerge nginx
Create a user and a group:
Groupadd www
Useradd www-g www
After Nginx is installed, the nginx group and nginx users are added by default. However, I still prefer to create a www group and www user as the HTTP service users. If the HTTP server is replaced with apache or lighttpd in the future, the user name and user group can remain unchanged.
Ii. Install MySQL
MySQL must be installed before PHP is installed, because MySQL operation functions in PHP require the support of MySQL header files and libraries.
Emerge dev-db/mysql
Initialize the database:
The default path of the database is/var/lib/mysql. The installation in this article places it in/work/db/3306/data.
Copy codeThe Code is as follows: mkdir-p/work/db/3306/data
Mysql_install_db -- basedir =/usr -- datadir =/work/db/3306/data -- user = mysql
Modify the configuration file:
Vim/etc/mysql/my. cnf
Modify datadir:
Datadir =/work/db/3306/data
Start MySQL:
/Etc/init. d/mysql start
Modify the root password:
Mysqladmin-uroot password hily
Test Database:
Mysql-uroot-p
Display:
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 successful!
3. install PHP
To run PHP In fastcgi mode, you need to install PHP-FPM.
Currently, the last PHP version to install the PHP-FPM in patch form is 5.3.0, and PHP 5.3.2 may be directly integrated with PHP-FPM.
Here I will use PHP 5.3.0 for installation.
Because the directory in Gentoo does not have a Portage integrated with the PHP-FPM, the following is directly installed through source code compilation.
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
Decompress PHP and install the 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 (based on your own 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 (based on your own needs ):
Copy codeThe Code is 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 codeThe Code is 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 the socket address (socket is more efficient than IP: Port ):
<Value name = "listen_address">/tmp/php-fpm.sock </value>
Modify user group and User Name:
Copy codeThe Code is as follows: Unix user of processes
<Value name = "user"> www </value>
Unix group of processes
<Value name = "group"> www </value>
Modify PHP-FPM run mode to Apache-Like mode:
Copy codeThe Code is 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 based on actual needs. I am a virtual machine here, and it is not necessary to be too large.
PHP-FPM boot script:
Cp/usr/local/php/sbin/php-fpm/etc/init. d/php-fpm
Start PHP-FPM
/Etc/init. d/php-fpm start
Add startup Service
Copy codeThe Code is as follows: rc-update add nginx default
Rc-update add mysql default
Rc-update add php-fpm default
Test Nginx + PHP
Add the test site directory:
Copy codeThe Code is as follows: mkdir-p/work/www/test
Echo "<? Php phpinfo ();?> ">/Work/www/test/index. php
Add the Nginx configuration of the test site:
Vim/etc/nginx. conf
Comment out the server segment and add the following at the end of the http segment:
Include sites/*. enable;
The configuration files of each site are stored in the/etc/nginx/sites directory as an independent file to facilitate management and maintenance.
Mkdir/etc/nginx/sites
Vim/etc/nginx/test. enable
The configuration of test. enable is as follows:
Copy codeThe Code is 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;
}
}
Create a storage log directory:
Mkdir/work/www/logs
Add a record to the local hosts:
192.168.1.10 test. local
192.168.1.10 is the IP address of my Gentoo machine.
Reload Nginx Configuration
/Etc/init. d/nginx reload
Access:
Http://test.local/
If the normal phpinfo information is displayed, the installation is complete.