nginx安裝:php
1 yum update 2 yum install nginx 3 systemctl start nginx 4 systemctl enable nginx
MariaDB安裝:html
1 vi /etc/yum.repos.d/MariaDB.repo 2 3 [mariadb] 4 name = MariaDB 5 baseurl = http://yum.mariadb.org/10.1/centos7-amd64 6 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB 7 gpgcheck=1
1 yum install MariaDB-server MariaDB-client 2 systemctl start mariadb 3 mysql_secure_installation 4 systemctl enable mariadb
php7的安裝:mysql
輸入一下命令進行指定php版本安裝 nginx
1 rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm 2 yum install php70w
注:此處安裝的是php7.0,若是安裝php7.1,將 yum install php70w 修改成 yum install php71w 便可web
1 yum install php
1 yum install php70w-xml php70w-soap php70w-xmlrpc php70w-mbstring php70w-json php70w-gd php70w-mcrypt php70w-mysql php70w-intl php70w-tidy php-pecl-mongodb php70w-fpm php70w-devel php70w-pear php70w-pecl-apcu php70w-opcache
1 vi /etc/php.ini 2 cgi.fix_pathinfo=1 --> cgi.fix_pathinfo=0
1 vi /etc/php-fpm.d/www.conf 2 3 1. 4 listen = /var/run/php-fpm/php-fpm.sock 5 2. 6 listen.owner = nginx 7 listen.group = nginx 8 3. 9 user = nginx 10 group = nginx
1 systemctl start php-fpm 2 systemctl enable php-fpm
修改nginx的配置文件:sql
1 vi /etc/nginx/conf.d/default.conf 2 server { 3 listen 80; 4 server_name localhost; 5 6 # note that these lines are originally from the "location /" block 7 root /usr/share/nginx/html; 8 index index.php index.html index.htm; 9 10 location / { 11 try_files $uri $uri/ =404; 12 } 13 error_page 404 /404.html; 14 error_page 500 502 503 504 /50x.html; 15 location = /50x.html { 16 root /usr/share/nginx/html; 17 } 18 19 location ~ \.php$ { 20 try_files $uri =404; 21 fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; 22 fastcgi_index index.php; 23 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 24 include fastcgi_params; 25 } 26 }
若是出現了「502 Bad」頁面,請更改目錄權限:mongodb
1 chown nginx:nginx /var/run/php-fpm/php-fpm.sock 2 chown nginx:nginx -R /usr/share/nginx/html
檢測:數據庫
在網站目錄下,輸入info.php,輸入以下代碼,查看頁面的返回json
1 <?php 2 phpinfo();