sudo yum install mysql mysql-server
sudo /etc/init.d/mysqld restart
配置mysql:
sudo /usr/bin/mysql_secure_installation
会出现:
Enter current password for root (enter for none):
OK, successfully used password, moving on...
因为没有密码,所有直接按回车
下面的设置基本都是y
4
安装nginx
我的是CentOS 6,先执行:
rpm-ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
如果是CentOS 5,就用下面的源:
rpm-ivh http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm
如果是Red Hat Enterprise Linux 6:
rpm -ivhhttp://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
如果是Red Hat Enterprise Linux 5:
rpm -ivhhttp://nginx.org/packages/rhel/5/noarch/RPMS/nginx-release-rhel-5-0.el5.ngx.noarch.rpm
yum install nginx
service nginx start
查看内网ip地址命令:
ifconfig eth0 | grep inet | awk '{ print $2 }'
5
安装php
sudo yum install php-fpm php-mysql
配置php:
sudo vi /etc/php.ini
设置:cgi.fix_pathinfo=0
设置的原因为:If this number is kept as a 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process
the exact file path—a much safer alternative. Save and Exit.
6
配置nginx
sudo vi /etc/nginx/nginx.conf
打开后会发现:包含文件:/etc/nginx/conf.d/default.conf
然后:
sudo vi /etc/nginx/conf.d/default.conf
复制下面到文件:
server {
listen 80;
server_name example.com;
location / {
root /usr/share/nginx/html;
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 /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[...]
; 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
[...]
把上面出现的apache换成nginx
重启php-fpm
sudo service php-fpm restart
然后重启nginx
sudo service nginx restart
8
设置开机启动:
sudo chkconfig --levels 235 mysqld on
sudo chkconfig --levels 235 nginx on
sudo chkconfig --levels 235 php-fpm on
9
检测环境会发现: