目录:
一、安装nginx
二、安装mysql(其实是mariadb)
三、安装php7
四、修改nginx配置文件
五、验证是否安装完成环境
一、安装nginx
1、yum install nginx(过程中有询问的地方,直接输入y即可);
2、service nginx start,启动nginx服务,可以用 ps -ef|grep nginx 命令来检查是否已经启动;
3、测试nginx服务器是否正常运行,输入 wget http://127.0.0.1或者在浏览器中直接输入该实例的ip看看是否能访问;
二、安装mysql(其实是mariadb)
1、yum install mariadb mariadb-server(这种是centos的版本在7.0以后的,安装的是mariadb),或者yum install mysql mysql-server mysql-devel(这种是centos的版本在7.0以下的,安装的是mysql);
2、启动mysql服务,7.0后的版本为service mariadb start,7.0以下的版本 service mysqld start;
3、输入mysql即可进入mysql;
4、use mysql;select user,host,password from user;
5、删除空的用户 drop user ''@localhost;
6、修改root用户的密码,update user set password = PASSWORD('要修改的密码') where user = 'root';
7、重新加载 flush privileges或者重启mysql服务也行;
三、安装php7.x
1、需要升级yum,因为可能是久版本会导致失败,命令为(不同版本有不同的升级方法):
centos 7.x:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
centos6.x:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm
2、yum安装php7.x,命令为:yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
四、修改nginx配置文件
1、找到nginx的配置文件,并编辑,nginx -t; vi 目录文件(一般为 /etc/nginx/nginx.conf);
2、修改nginx配置:(红色部分即为需要修改的部分)
server { listen 80; root /usr/share/nginx/html; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; location / { index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.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$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } #支持rewrite模式,如果写了上面的,则无需填写这个 location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } } 3、配置完成,重启服务, service nginx restart; 五、验证是否安装完成环境 1、创建php文件,在网站的根目录(在nginx配置中设置),vim /usr/share/nginx/html/index.php 2、随便写点内容 <?php echo phpinfo(); ?>