阿里云CentOS 6.5 -Nginx, MySQL, PHP 环境配置
step1:安装epel、remi两个资源库
sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
step2:安装mysql
sudo yum install mysql mysql-server
安装后重启
sudo /etc/init.d/mysqld restart
mysql安全向导
sudo /usr/bin/mysql_secure_installation
询问当前root密码,因为刚安装,没有密码,所以直接回车
Enter current password for root (enter for none): OK, successfully used password, moving on...
设置一个新的密码,输入‘y’,然后就是一连串关于mysql信息建立的问题
By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] y ... Success! By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
step3:安装nginx
sudo yum install nginx
启动nginx
sudo /etc/init.d/nginx start
step4:安装php
安装php需要用到第一步的资源库,这里需要激活并安装php-fpm,安装过程需要一点时间
sudo yum --enablerepo=remi install php-fpm php-mysql
安装完成,请按自己需要配置php.ini文件
sudo vi /etc/php.ini
php扩展文件路径
/usr/lib64/php/modules
step5:配置nginx
sudo vi /etc/nginx/nginx.conf
将worker processes工作进程设置为自己需要的,这里我设置的为4,接着打开默认的站点配置文件
sudo vi /etc/nginx/conf.d/default.conf
如果你是独立的单个站点,修改注释后配置信息如下(红色部分为修改的):
# # The default server # server { listen 80; server_name localhost; location / { root /home/www; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/$fastcgi_script_name; include fastcgi_params; } }
1.设置域名或ip:youname.com
2.设置默认文档:index.php
3.设置默认路径:我的设置是/home/www,请根据需要自己设置
4.去掉‘location ~ \.php$’部分的注释
修改好后,保存并退出。
配置php-fpm
sudo vi /etc/php-fpm.d/www.conf
修改用户和组,请自行配置
[...] ; Unix user/group of processes ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache Choosed to be able to access some dir as httpd user = nginx ; RPM: Keep a group allowed to write in log dir. group = nginx [...]
配置好后,重启php-fpm
sudo service php-fpm restart
step6:测试php
建立一个phpinfo()的php文件到目录
sudo service nginx restart
访问测试文件,配置成功。
注意几点:
centos6*的系统对epel、remi的两个资源库的版本有要求,最好用新的版本,不然会报错
nginx的default.conf文件配置会容易报错,尤其配置rewrite的时候
参考链接:
浙公网安备 33010602011771号