日期:2014-05-16  浏览次数:20668 次

linux 安装php+nginx+mysql
1、下载安装包;
http://www.unix-pub.net/install.tar

2、上传到服务器,解压(tar zxvf )安装包到/usr/local/src目录下,进入目录,执行
sh install.sh文件,等待一段时间(一般需要半小时以上);

3、mysql配置管理
(1)运行/usr/local/mysql/share/mysql/mysql.server start 启动mysql;
     使用/usr/local/mysql/bin/mysqladmin -u root password 123456设置密码;
     使用/usr/local/mysql/bin/mysql -u root -p,输入123456操作;

(2)以上测试mysql各个操作没问题,接下来设置远程机器访问本数据库
     防火墙打开3306端口步骤:
    设定:/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
     保存:/etc/rc.d/init.d/iptables save
    重启防火墙服务:service iptables restart
     查看开启端口:/etc/init.d/iptables status       

PS:(1)远程使用root连接如出现10060错误,一般都是防火墙没有打开端口,另一个可能用户没授权,mysql授权表里没有远程机器的权限,及需要在授权表mysql.user添加
#grant all privileges on *.* to 'root'@'远程登陆IP' identified by '远程登陆密码'
#flush privileges;
     (2)如出现 Access denied for user ''@'localhost' to database 'mysql'错误
          见:http://blog.csdn.net/tys1986blueboy/article/details/7056835
     (3)Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
        执行:scripts/mysql_install_db --user=root --datadir=/usr/local/mysql/var

4、PHP配置管理
启动PHP-FPM:#/usr/local/php/sbin/php-fpm start
可能会报用户和组相关的错误,编辑:#vi /usr/local/php/etc/php-fpm.conf
找到<value name="user">、<value name="group">标签,修改值为nobody;然后再启动;

5、nginx配置管理
nginx默认不安装的,需要进入安装/usr/local/src/nginx-0.6.36/,运行#./configure;
具体的linux的详细安装见:http://itsoul.iteye.com/admin/blogs/792201

6、php+nginx整合
打开/usr/local/nginx/conf/nginx.conf文件,找到
location ~ \.php$ {
            #root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
            include        fastcgi_params;
        }

把这些代码给注释开,/var/www/html是你存放php代码的地方;
重启nginx,访问http://localhost/index.php,一切OK。

7、远程访问该地址
如果防火墙80端口没有打开,需要设置下防火墙文件
编辑文件:#vi /etc/sysconfig/iptables
添加行:-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 80 -j ACCEPT,保存退出。
重启服务:#service iptables restart