1. 程式人生 > >linux下nginx、php和mysql安裝配置

linux下nginx、php和mysql安裝配置

一、安裝nginx

安裝nginx

yum install -y epel-release
yum install nginx -y

檢視nginx軟體包包括了哪些檔案

rpm -ql nginx

啟動nginx

systemctl start nginx

檢視nginx是否啟動成功

systemctl status nginx

設定nginx開機自啟動

systemctl enable nginx

檢視nginx主配置

vim /etc/nginx/nginx.conf

新建一個站點

vim /etc/nginx/conf.d/test.actself.me.conf

內容如下:

server {
    listen 80;
    server_name test.actself.me;
    root /var/www/test.actself.me;
    index index.html;

    location \ {
    }

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

檢視 fastcgi 相關的配置指令

view /etc/nginx/fastcgi_params

reload nginx,使新建的站點配置生效

systemctl reload nginx

建立網站目錄

mkdir -p /var/www/test.actself.me

進入網目錄,建立index.html和test.php兩個檔案

cd /var/www/test.actself.me
vim index.html
vim test.php

檢視linux伺服器的ip,因為test.actself.me並沒有做域名配置,我們要把這個ip寫到/etc/hosts裡面才能訪問這個域名

ip addr list

停止執行防火牆

systemctl stop firewalld

二、安裝php

1、檢視安裝步驟:https://rpms.remirepo.net/

2、安裝

安裝php7

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum install -y php72.x86_64 php72-php-cli.x86_64 php72-php-fpm.x86_64 php72-php-json.x86_64 php72-php-mbstring.x86_64 php72-php-mysqlnd.x86_64 php72-php-opcache.x86_64 php72-php-pdo.x86_64 php72-php-pecl-amqp.x86_64 php72-php-pecl-igbinary.x86_64 php72-php-pecl-mcrypt.x86_64 php72-php-pecl-memcached.x86_64 php72-php-pecl-msgpack.x86_64 php72-php-pecl-mysql.x86_64 php72-php-pecl-redis.x86_64 php72-php-pecl-yac.x86_64 php72-php-pear.noarch php72-php-pecl-zip.x86_64

 安裝php swoole擴充套件

yum search php72 | grep swoole
yum install php72-php-pecl-swoole2.x86_64

啟動php-fpm

systemctl start php72-php-fpm
systemctl status php72-php-fpm
systemctl enable php72-php-fpm

檢視php-fpm的配置

rpm -ql php72-php-fpm
vim /etc/opt/remi/php72/php-fpm.conf
vim /etc/opt/remi/php72/php-fpm.d/www.conf

php.ini 的配置

vim /etc/opt/remi/php72/php.ini

三、安裝mysql

yum install mariadb-server
systemctl start mariadb
systemctl status mariadb
systemctl enable mariadb

寫個測試mysql的php程式碼:

vim mysql.php

內容如下:

<?php
$dsn = 'mysql:dbname=test;host=127.0.0.1';
$user = 'root';
$password = '';
$dbh = new \PDO($dsn, $user, $password);

$sql = 'SELECT version();';
$result = $dbh->query($sql);

foreach($result as $row)
{
    var_dump($row);
}

驗證:

php72 mysql.php