Gentoo under installation and configuration Nginx+ MySQL + PHP of fastcgi environment steps sharing
- 2020-05-06 12:09:31
- OfStack
1. Install Nginx
one command:
USE=fastcgi emerge nginx
New user and group:
groupadd www
useradd www -g www
After Nginx is installed, nginx group and nginx users will be added by default, but I am still used to creating www group and www users to be HTTP users. If the HTTP server is changed to apache or lighttpd in the future, the user name and user group can remain unchanged.
Ii. Install MySQL
must have MySQL installed before PHP, because MySQL operation functions in PHP require MySQL header and library support.
emerge dev-db/mysql
Initialize the database:
The default database path is/var/lib/mysql, the installation of this article put it/work db / 3306 / data.
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
Change datadir to:
datadir = /work/db/3306/data
Launch MySQL:
/etc/init.d/mysql start
Change 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
runs PHP in fastcgi mode, requiring the installation of PHP-FPM.
The last version of PHP that currently requires PHP-FPM to be installed as patch is version 5.3.0, and PHP 5.3.2 will likely be directly integrated with PHP-FPM.
I'll just use PHP 5.3.0 to install it.
Because the directory in Gentoo has not yet integrated Portage from PHP-FPM, the installation is now done directly through source code compilation.
Download PHP 5.3.0:
wget http://cn.php.net/distributions/php-5.3.0.tar.bz2
Download the PHP-FPM patch:
wget http://php-fpm.org/downloads/php-5.3.0-fpm-0.5.12.diff.gz
Unzip PHP and patch FPM:
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
The libraries required to install PHP (as required) :
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 needed) :
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 profile:
cp php.ini-production /usr/local/php/etc/php.ini
Es217en-FPM configuration file:
vim /usr/local/php/etc/php-fpm.conf
Change listen_address to socket address (socket is more efficient than IP:Port) :
<
value name="listen_address"
>
/tmp/php-fpm.sock
<
/value
>
Modify the user group and username:
Unix user of processes
<value name="user">www</value>
Unix group of processes
<value name="group">www</value>
Change PHP-FPM to Apache-Like mode:
<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 up according to actual needs. I have a virtual machine here, so it doesn't have to be too big.
Es275en-FPM startup script:
cp /usr/local/php/sbin/php-fpm /etc/init.d/php-fpm
Start the PHP - FPM
/etc/init.d/php-fpm start
Add the startup service
rc-update add nginx default
rc-update add mysql default
rc-update add php-fpm default
Test Nginx + PHP
Add the test site directory:
mkdir -p /work/www/test
echo "<?php phpinfo(); ?>" > /work/www/test/index.php
Add Nginx configuration for the test site:
vim /etc/nginx/nginx.conf
Comment out the server segment and add:
at the end of http
include sites/*.enable;
After that, the configuration files of each site are 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
Es345en.enable is configured 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 to 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/
The installation completes when the normal phpinfo information is displayed.