在 CentOS 7 系统上:
$ sudo rpm --import http://nginx.org/keys/nginx_signing.key
$ sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ sudo yum install nginx
$ sudo systemctl start nginx
$ sudo systemctl enable nginx
$ sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
$ sudo firewall-cmd --reload
#--sql
$ sudo yum install mariadb-server
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
$ sudo mysql_secure_installation
#--php
$ sudo yum install php php-fpm php-mysql php-curl php-mbstring php-gd
$ sudo systemctl start php-fpm
$ sudo systemctl enable php-fpm
在 CentOS 6 系统上:
$ sudo rpm --import http://nginx.org/keys/nginx_signing.key
$ sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
$ sudo yum install nginx
$ sudo service nginx start
$ sudo chkconfig nginx on
$ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
$ sudo service iptables save
#--mysql
$ sudo yum install mysql-server
$ sudo service mysqld start
$ sudo chkconfig mysqld on
#--mariadb
#cat /etc/yum.repos.d/mariadb.repo
# MariaDB 5.5 CentOS repository list - created 2014-03-04 11:20 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
#--php#默认会把apache当成依赖条件自动安装
$ sudo yum --enablerepo=remi install php php-fpm php-mysql php-curl php-mbstring php-gd
$ sudo chkconfig php-fpm on
$ sudo service php-fpm start
在 CentOS 6 系统中,安装 REMI仓库中最新的 php-mysql 模块时,MySQL 的服务端包和客户端包会被当做一部分依赖包而自动的更新。
在 CentOS 6 和 CentOS 7 中,在安装 PHP 包的同时会把 Apache web 服务器(即 httpd)当做它的依赖包一起安装。这会跟 nginx web 服务器起冲突。这个问题会在下一节来讨论。
取决于您的使用情况,可以使用 yum 命令来定制您的 PHP 引擎,也许会想安装下面的任意一个扩展 PHP 模块包。
php-cli: PHP 的命令行界面。从命令行里测试 PHP 时非常有用。
php-gd: PHP 的图像处理支持。
php-bcmath: PHP 的数学支持。
php-mcrypt: PHP 的加密算法支持 (例如 DES、Blowfish、CBC、 CFB、ECB ciphers 等)。
php-xml: PHP 的 XML 解析和处理支持。
php-dba: PHP 的数据抽象层支持。
php-pecl-apc: PHP 加速器/缓存支持。
----------------------------------------------
$ sudo vi /etc/nginx/conf.d/default.conf
server {
listen 80 default;
server_name _;
server_name www.example.com blog.example.com
#rewrite ^.* http://www.jk409.com permanent;
return 500; #禁止IP访问
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
# nginx passes PHP scripts to FastCGI server via a TCP/9000 socket
# this setting much be consistent with /etc/php-fpm.d/www.conf
# try_files prevents nginx from passing bad scripts to FastCGI server
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
----------------------------------------------根据需要修改
vi /etc/php5/fpm/pool.d/www.conf
listen = /var/run/php5-fpm.sock
改成
listen = 127.0.0.1:9000
******************************************************************************
#apt-get install nginx 或 apache2
#apt-get install mariadb-server 或 mysql-server
#apt-get install php5-fpm php5-mysql php5-cgi php5-dev php5-gd php5-curl php5-cli apache2#apt-get install php5 libapache2-mod-php5 libapache2-mod-auth-mysql php5-mysql php5-gd php5-curl php5-dev
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
1.nginx虚拟主机模板
vi ./sites-enabled/t2
#---------------------------配置一----------------------------------------- server { server_name www.t2.com; listen 80; root /data/www/t2; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { try_files $uri =404; fastcgi_pass 127.0.0.1:9001; #fastcgi_pass unix:/var/run/php5-fpm.sock fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #location /RequestDenied { # proxy_pass http://127.0.0.1:8080; #} #error_page 404 /404.html; # #error_page 500 502 503 504 /50x.html; #location = /50x.html { # root /usr/share/nginx/html; #} } #---------------------------配置二------------------------------------------ server { listen 80; server_name ~^(.+)?\.howtocn\.org$; index index.html; if ($host = test.com){ rewrite ^ http://www.test.com permanent; } root /data/wwwsite/test.com/$1/; } #实现一个server可以配置多个二级域名; #例如kkk.test.com会自动的匹配到/data/wwwsite/test.com/kkk/目录下
2.设置apache虚拟主机的配置模板:
#yum install httpd
添加/etc/httpd/conf/httpd.conf
LoadModule php5_module modules/libphp5.so AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps #-----追加 DirectoryIndex index.html index.html.var index.php
sudo vi sites-enabled/t2.conf
#sudo apt-get install php5 libapache2-mod-php5 #sudo apt-get install libapache2-mod-auth-mysql #sudo apt-get install php5-mysql #sudo vi sites-enabled/t2.conf #注意创建apache虚拟主机的文件必须以.conf结尾,(nginx虚拟文件没有限制) <VirtualHost *:8080> ServerName www.t2.com ServerAdmin webmaster@localhost DocumentRoot /data/www/t2 DirectoryIndex index.php #默认首页 #ErrorLog ${APACHE_LOG_DIR}/error.log #CustomLog ${APACHE_LOG_DIR}/access.log combined #网站根目录访问权限(apache2.4) <Directory /data/www/t2> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost>
3.apache2的负载
<VirtualHost *:80> ServerName www.test.com ProxyPass / balancer://mytest <Proxy balancer://mytest> BalancerMember http://192.168.0.1:8081/ loadfactor=1 route=node1 BalancerMember http://192.168.0.2:8081/ loadfactor=1 route=node2 BalancerMember http://192.168.0.3:8081/ loadfactor=1 route=node3 BalancerMember http://192.168.0.4:8081/ loadfactor=1 route=node4 ProxySet lbmethod=byrequests </Proxy> </VirtualHost>
4.windos php环境:
确认windos已安装:vcredist_86或vcredist_64 下载的php版本(windos一般NTP非线程安全):http://php.net/downloads.php 下载nginx版本(windos版本):http://nginx.org/en/download.html 直接解压就OK,nginx+php和linux一样, 运行fastcgis: c:/php/php-cgi.exe -b 127.0.0.1:9000 -c c:/php/php.ini d:/nginx-1.9.0/nginx.exe