一、nginx安装
获取nginx源
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装
yum -y install nginx
启动
systemctl start nginx
设置开机自启
systemctl enable nginx
二、php安装
获取yum源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装模块
yum -y install php71w php71w-fpm php71w-mbstring php71w-common php71w-gd php71w-mcrypt php71w-mysql php71w-xml php71w-cli php71w-devel php71w-pecl-memcached php71w-pecl-redis php71w-opcache
php71w-mysql安装失败时,可以安装mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
验证是否安装成功
php -v
启动
systemctl start php-fpm.service
设置开机自启
systemctl enable php-fpm
nginx与php连通
修改nginx配置文件
vim /etc/nginx/nginx.conf 在server里添加
location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
重启nginx
systemctl reload nginx
创建php文件
vim /usr/share/nginx/html/1.php
<?php
phpinfo();
?>
三、mysql安装
移除mariadb
rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
yum remove mariadb-libs-5.5.60-1.el7_5.x86_64
安装mysql源
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server install mysql-community-devel
启动mysql
systemctl start mysqld.service
设置开机自启
systemctl enable mysqld.service
查看密码
grep "password" /var/log/mysqld.log
登入mysql修改密码
mysql -uroot -p
set global validate_password_policy=0;
set global validate_password_length=1;
alter user 'root'@'localhost' identified by '123456';
mysql与php连通
vim /usr/share/nginx/html/2.php
<?php
$servername = "localhost";
$username = "root";
$password = "123456";
try {
$conn = new PDO("mysql:host=$servername;dbname=mysql;port=3306", $username, $password);
echo "successful";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>