linux下nginx、php和mysql安装配置

一、安装nginx

安装nginx

yum install -y epel-releaseyum 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.mevim index.htmlvim test.php

查看linux服务器的ip,因为test.actself.me并没有做域名配置,我们要把这个ip写到/etc/hosts里面才能访问这个域名

ip addr list

停止运行防火墙

systemctl stop firewalld

关闭selinux:  

setenforce 0

二、安装php

1、查看安装步骤:https://rpms.remirepo.net/

2、安装

安装php7

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmyum install http://rpms.remirepo.net/enterprise/remi-release-7.rpmyum install yum-utilsyum 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 swooleyum install php72-php-pecl-swoole2.x86_64

启动php-fpm

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

查看php-fpm的配置

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

php.ini 的配置

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

三、安装mysql

yum install mariadb-serversystemctl start mariadbsystemctl status mariadbsystemctl 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

 

相关文章