LNAMP Linux Nginx Apache Mysql PHPphp
Nginx + PHP(fast CGI)html
能夠理解爲一個php加速的一個接口mysql
Php-fpm 能夠實現fastcgi協議須要的進程池,php-fpm實現的fastcgi進程叫php-cgi,因此php-fmp實際上是他自身的fastcgi 或 php-cgi進程管理器linux
Ngix+FastCGI安裝nginx
前期準備工做:sql
#yum install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mariadb mariadb-server mariadb-devel -yjson
[root@nginx php-5.3.10]# systemctl start mariadb.service
[root@nginx php-5.3.10]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.api
注意:若是碰到如下的錯誤,查看一下解決方案session
配置以前須要作一個軟連接php7
由於在64位的linux系統中,libmysqlclient 默認安裝到了 /usr/lib64/mysql/ 目錄下,可是php編譯時,要去/usr/lib目錄下查找
# ln -s /usr/lib64/mysql/libmysqlclient.so.18.0.0 /usr/lib/libmysqlclient.so
不然會報錯:
configure: error: Cannot find libmysqlclient under /usr.
Note that the MySQL client library is not bundled anymore!
#使用編譯安裝php-fast
下載php7.1.12
解壓---配置---
[root@nginx ]# tar xvf php-7.1.12.tar.gz
[root@nginx php-7.1.12]# ./configure --prefix=/usr/local/php7.1 --enable-fpm --enable-debug --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-curl --with-mysqli=/usr/bin/mysql_config
---編譯---安裝---
[root@nginx php-7.1.12]# make
[root@nginx php-7.1.12]# make install
[root@nginx php-7.1.12]# cp php.ini-production /usr/local/php7.1/lib/php.ini
[root@nginx ~]# cp /usr/local/php7.1/etc/php-fpm.conf.default /usr/local/php7.1/etc/php-fpm.conf
#配置文件
[root@nginx php-7.1.12]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#啓動腳本文件
[root@nginx ~]# chmod o+x /etc/init.d/php-fpm
#加權限
[root@nginx ~]# /etc/init.d/php-fpm start
Starting php-fpm done
[root@nginx ~]# ps -ef | grep php
root 3223 1 0 17:39 ? 00:00:00 php-fpm: master process (/usr/local/php7.1/etc/php-fpm.conf)
nobody 3224 3223 0 17:39 ? 00:00:00 php-fpm: pool www
nobody 3225 3223 0 17:39 ? 00:00:00 php-fpm: pool www
root 3227 2877 0 17:39 pts/0 00:00:00 grep --color=auto php
報錯:
[root@nginx ~]# /etc/init.d/php-fpm start
Starting php-fpm [29-Nov-2017 16:43:01] WARNING: Nothing matches the include pattern '/usr/local/php7.1/etc/php-fpm.d/*.conf' from /usr/local/php7.1/etc/php-fpm.conf at line 125.
[29-Nov-2017 16:43:01] ERROR: No pool defined. at least one pool section must be specified in config file
[29-Nov-2017 16:43:01] ERROR: failed to post process the configuration
[29-Nov-2017 16:43:01] ERROR: FPM initialization failed
failed
解決:
[root@nginx php-fpm.d]# pwd
/usr/local/php7.1/etc/php-fpm.d
[root@nginx php-fpm.d]# cp www.conf.default www.conf
若是還有報錯多是配置文件php-fpm.conf最後一行,默認是註釋的,去掉註釋便可。
include=/usr/local/php7.1/etc/php-fpm.d/*.conf
安裝完成:
Wrote PEAR system config file at: /usr/local/php7.1/etc/pear.conf
You may want to add: /usr/local/php7.1/lib/php to your php.ini include_path
/root/php-7.1.12/build/shtool install -c ext/phar/phar.phar /usr/local/php7.1/bin
ln -s -f phar.phar /usr/local/php7.1/bin/phar
Installing PDO headers: /usr/local/php7.1/include/php/ext/pdo/
[root@nginx php7.1]# tree /usr/local/php7.1/ | grep php-fpm
│?? ├── php-fpm.conf.default
│?? └── php-fpm.d
│?? │?? └── php-fpm.8
│?? └── php-fpm
其餘連接:
https://www.howtoforge.com/tutorial/how-to-install-php-7-on-debian/
[root@nginx ~]# vi /usr/local/nginx/nginx.conf
[...]
#C
server {
listen 80;
server_name www.doudou0826c.com;
location / {
root html/c;
index index.html index.htm;
}
#PHP
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/c$fastcgi_script_name;
include fastcgi_params;
}
}
[...]
[root@nginx ~]# cat /usr/local/nginx/html/c/index.php
<?php
phpinfo();
?>
[root@nginx ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
[root@nginx ~]# /usr/local/nginx/sbin/nginx -s reload
nginx的配置文件記錄
[root@nginx nginx]# cat nginx.conf
user nginx nginx;
worker_processes 1;
error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
#A
server {
listen 80;
server_name doudou0826a.com www.doudou0826a.com dd0826a.com ;
location / {
root html/a;
index index.html index.htm;
expires 3d;
}
if ($host != 'www.doudou0826a.com') {
rewrite ^/(.*) http://www.doudou0826a.com/$1 permanent;
}
#rewrite ^/$ http://www.doudou0826a.com/index.html permanent;
if ( !-e $request_filename )
{
rewrite ^/(.*)$ /index.php last;
}
}
#B
server {
listen 80;
server_name www.doudou0826b.com;
location / {
root html/b;
index index.html index.htm;
}
if ($http_user_agent ~* "wget" ) { return 404; }
location ~* \.(gif|jpg|png|swf|flv)$ {
valid_referers none blocked *.doudou0826b.com;
root /html/b ;
if ($invalid_referer) {
return 403;
}
}
location /NginxStatus {
stub_status on;
}
}
#C
server {
listen 80;
server_name www.doudou0826c.com;
location / {
root html/c;
index index.html index.htm;
}
#PHP
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/c$fastcgi_script_name;
include fastcgi_params;
}
}
}
其餘:
./configure --prefix=/usr/local/php7.1 --enable-fpm --disable-rpath --with-pear --disable-debug --with-openssl --with-pcre-regex --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --enable-inline-optimization --with-gd --enable-gd-native-ttf --with-gettext --with-imap --with-imap-ssl --with-kerberos --with-ldap --enable-mbstring --enable-mbregex --with-mcrypt --with-mysql --with-mysqli --enable-pcntl --enable-pdo --with-pdo-firebird --with-pdo-mysql --with-pdo-pgsql --with-pgsql --enable-shmop --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --enable-wddx --with-xmlrpc --with-xsl --enable-zip --with-pic --enable-ftp --enable-dom --enable-xmlwriter --enable-xmlreader --enable-tokenizer --enable-simplexml --enable-session --enable-posix --enable-phar --enable-libxml --enable-json --with-iconv --enable-filter --enable-fileinfo --enable-dba --enable-ctype