linux 安装php+nginx+mysql

本文介绍了如何在Linux环境下安装并配置PHP、MySQL、Nginx,包括下载安装包、上传到服务器、解压安装、配置MySQL、设置防火墙规则等步骤,并提供了详细的命令和操作流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、下载安装包;
[url]http://www.unix-pub.net/install.tar[/url]

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

(3)修改密码:
mysql> UPDATE mysql.user SET password=PASSWORD(’新密码’) WHERE User=’root’;
mysql> FLUSH PRIVILEGES;
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'错误
见:[url]http://blog.youkuaiyun.com/tys1986blueboy/article/details/7056835[/url]
(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配置管理
下载php5.2.17安装包
执行
./configure --prefix=/usr/local/php --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect 
32
--enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear


再执行make & make install

PS:make时候报错:
ext/gd/libgd/gdkanji.c:350: undefined reference to `libiconv_open
错误,执行vim Makefile 找到EXTRA_LIBS 加上 -liconv

#cp php.ini-dist /usr/local/php/etc/php.ini
启动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的详细安装见:[url]http://itsoul.iteye.com/blog/792201[/url]

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值