linux下nginxphp和mysql安装配置
Posted 郑楚周
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux下nginxphp和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
关闭selinux:
setenforce 0
二、安装php
1、查看安装步骤:https://rpms.remirepo.net/
2、安装
安装php7
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm yum install -y 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 -y 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 -y 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
以上是关于linux下nginxphp和mysql安装配置的主要内容,如果未能解决你的问题,请参考以下文章