1024programmer Nginx gentoo system configuration and installation of LNMP environment

gentoo system configuration and installation of LNMP environment

Install Nginx
* One command to get it done:
USE=fastcgi emerge nginx
* Create new users and groups:
groupadd www
useradd www -g www
After Nginx is installed, the nginx group and nginx user will be added by default, but I am still used to creating a www group and www user for HTTP
service users. If the HTTP server is changed to apache or lighttpd in the future, the user name and user group can remain unchanged.

Install MySQL
Before installing PHP, you must install MySQL first, because the MySQL operation functions in PHP need the support of MySQL header files and libraries.
emerge dev-db/mysql
* Initialize the database:
I’m not used to installing the database in the default path /var/lib/mysql, I put it in /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
* Start MySQL:
/etc/init.d/mysql start
* Modify 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!

Install PHP
To run PHP in fastcgi mode, PHP-FPM needs to be installed.
Currently the last PHP version that requires PHP-FPM to be installed as a patch is 5.3.0, PHP 5.3.2
It will be possible to directly integrate PHP-FPM in the version.
Here I use PHP 5.3.0 to install.
Because the directory in Gentoo has not yet integrated PHP-FPM Portage, so the installation is directly compiled from source code.
* 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
* Unpack 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
* Install the library required by PHP (according to 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 (according to your own needs):
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:
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):
/tmp/php-fpm.sock
Modify user group and user name:
Unix user of
processes
www
Unix group of processes
www
Modify the PHP-FPM operating mode to Apache-Like mode:
apache-like
1
1
5
StartServers, MinSpareServers, and MaxSpareServers
Set according to actual needs, here is a virtual machine, it doesn’t need to be 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 startup service
rc-update add nginx default
rc-update add mysql default
rc-update add php-fpm default

Testing Nginx+PHP
* Add test site directory:
mkdir -p /work/www/test
echo “”>
/work/www/test/index.php
* Add the Nginx configuration of the test site:
vim /etc/nginx/nginx.conf
Comment out the server section and add at the end of the http section:
include sites/*.enable;
Afterwards, the configuration files of each site are saved in the /etc/nginx/sites directory as an independent file, which is convenient for management and maintenance.
mkdir /etc/nginx/sites
vim /etc/nginx/test.enable
The configuration of test.enable 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 new storage log directory:
mkdir /work/www/logs
* Reload Nginx configuration
/etc/init.d/nginx reload
*Create a new phpinfo information test file
vim /work/www/test/phpinfo.php
Input content:
<?php
phpinfo();
?>

* Visit: http://192.168.80.135/phpinfo.php
192.168.80.135 is the IP of my Gentoo machine.
If the normal phpinfo information is displayed, the installation is complete!

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/gentoo-system-configuration-and-installation-of-lnmp-environment/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索