========== 安装nginx ==========
查看nginx信息:
yum info nginx
安装nginx:
yum -y install nginx
查看nginx是否存在:
which nginx
启动ngnix方式一:
/etc/init.d/nginx start
启动nginx方式二:
service nginx start
启动服务的过程中可能会报错:
Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol) [FAILED]
解决方法:修改nginx的配置:
vi /etc/nginx/conf.d/default.conf
在[::]:80这一行前面加“#”表示注释这一行,再重新启动nginx进程
查看nginx进程:
ps -ef | grep nginx
设置nginx开机自启动:
chkconfig nginx on
========== 安装php ==========
安装php和php-fpm软件包:
yum -y install php php-fpm
启动php-fpm方式一:
/etc/init.d/php-fpm start
启动php-fpm方式二:
service php-fpm start
修改nginx配置文件让PHP的请求转发到php-fpm所绑定的ip和端口上:
vim /etc/nginx/conf.d/default.conf
在server{};里面最底端输入
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;
}
【重点】重启nginx:
service nginx restart
--------------------------------------------------
验证是否处理请求PHP文件:
vim /usr/share/nginx/html/info.php
<?php
phpinfo();
---------------------------------------------------
访问IP网址:
http://外网IP/info.php
========== 安装mysql ==========
安装mysql:
yum -y install mysql mysql-server
启动mysql服务器:
service mysqld start
设置密码:
mysqladmin -u root password 123456
登录mysql测试一下:
mysql -u root -p
安装php对mysql操作的扩展:
yum -y install php-mysql
重启php-fpm进程:
service php-fpm restart
检查是否可以通过php操作mysql数据库:
vim /usr/share/nginx/html/dbConnect.php
<?php
@mysqli_connect("localhost","root”,”123456”,”mysql") or die("connect mysql failed\n");
echo "connect ok\n";
在浏览器执访问:
http://外网IP/dbConnect.php