第一步、更新yum源
yum install update
第二步、安装 apache+nginx+mysql+php
yum install httpd nginx mysql-server mysql-devel php php-fpm
第三步、启动mysql并设置初始密码
service mysqld start
mysqladmin -u root password '123456'
第四步、设置mysql远程登陆及删除user表无用信息
mysql -uroot -p
(登陆mysql)
use mysql
(打开mysql数据库)
select host,user,password from user;
(查询user表host+user+password)
delete from user where user=‘’ or host='127.0.0.1';
(删除无用记录)
update user set host='%',password=password('123456') where host='linux';
(设置远程登陆账号)
select host,user,password from user;
(再次查询)
quit
(退出mysql命令行)
service mysqld restart
测试远程连接mysql成功
第四步、测试apache和php是否可以正常运行
service httpd start
service php-fpm start
通过域名访问apache成功
接下来测试php
在/var/www/html目录下新建index.php文件内容如下
<?php
phpinfo();
?>
保存完毕
通过域名访问php成功
第五步、测试nginx和php是否可以正常运行
service httpd stop
(开启apache)
service nginx start
(开启失败报错 原因:服务器不支持ipv6)
Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)
解决方法:打开配置文件vim /etc/nginx/conf.d/default.conf
注释红框那行
保存重启nginx重启成功。
通过域名访问nginx成功
接下来测试php
清空/usr/share/nginx/html目录
rm -rf /usr/share/nginx/html/*
在/usr/share/nginx/html目录下新建index.php文件内容如下
<?php phpinfo(); ?>保存完毕
通过域名访问(访问失败 原因配置文件没有添加php的默认主页和解析)
403 Forbidden
nginx/1.10.3
解决方法:打开配置文件vim /etc/nginx/conf.d/default.conf
添加红框代码
index index.html index.htm index.php;
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;
}
保存完毕
通过域名访问php成功
注意事项:如果只用apache+php的方式不安装php-fpm是可以正确访问php的,但是如果想要nginx+php就必须安装php-fpm并正确启动否则报错404 Not Found。
第六步、下面是升级php到7.0流程
首先更新软件源
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
wget http://rpms.remirepo.net/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6.rpm epel-release-latest-6.noarch.rpm
安装php及扩展
yum install php70-php php70-php-pear php70-php-bcmath php70-php-pecl-jsond-devel php70-php-mysqlnd php70-php-gd php70-php-common php70-php-fpm php70-php-intl php70-php-cli php70-php php70-php-xml php70-php-opcache php70-php-pecl-apcu php70-php-pecl-jsond php70-php-pdo php70-php-gmp php70-php-process php70-php-pecl-imagick php70-php-devel php70-php-mbstring php70-php-mcrypt
启动php70-php-fpm
service php70-php-fpm start
重启web服务器即可。