CentOS 7 安装 lnmp
- 本地远程连接服务器
- 安装 ssh 服务
yum install ssh
- 启动 ssh
service sshd start
chkconfig sshd on
- yum 换源
yum update
- 安装nginx
yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum repolist enabled | grep "nginx*"
yum -y install nginx
- 启动 nginx
service nginx start
- 设置 nginx 开机自启动
systemctl enable nginx.service
- 检查 nginx 自启动设置是否成功
systemctl list-dependencies | grep nginx
- 浏览器输入你的 ip 检测是否安装成功,如出现欢迎页面,则 nginx 安装成功
-
nginx 配置如下
server{ listen 80; server_name youserver; index index.html index.php; root /home/public; //你的项目路径 #charset koi8-r; #access_log logs/host.access.log main; location / { index index.html index.htm index.php; try_files $uri $uri/ /index.php?$query_string; } 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 html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { root /home/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/public$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; } }
-
安装 mysql
yum -y localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm yum repolist enabled | grep "mysql.*-community.*" yum -y install mysql-community-server install mysql-community-devel
- 启动 mysql
service mysqld start
- 检查 mysql 是否启动成功
service mysqld status 或者 ps -ef | grep mysql
- 设置 mysql 开机自启动
systemctl enable mysqld.service
- 检查 mysql 开机自启动是否设置成功
systemctl list-dependencies | grep mysqld
- 更换 mysql root 用户密码
mysql5.7 以后的争强了安全机制,所以使用yum安装,系统会自动生成一个随机的密码,并且不能设置简单密码。所以需要修改 mysql 全局参数 先用日志密码登录 mysql grep 'temporary password' /var/log/mysqld.log 会输出结果: A temporary password is generated for root@localhost: ****** 使用此密码登录后 执行 SHOW VARIABLES LIKE 'validate_password%‘; 查看 mysql 密码策略 +--------------------------------------+--------+ | Variable_name | Value | +--------------------------------------+--------+ | validate_password_check_user_name | OFF | | validate_password_dictionary_file | | | validate_password_length | 8 | | validate_password_mixed_case_count | 1 | | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +--------------------------------------+--------+ 执行 set global validate_password_policy=LOW; 修改密码策略 执行 set global validate_password_length=6; 修改验证密码长度 切换 user 库 update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root'; 重启 mysqld 服务,再用新密码登录即可 如果无法登录,提示Access denied for user 'root'@'localhost' 重新更新 root 用户的 plugin 字段 update user set plugin='mysql_native_password' where user = 'root'; 更新成功后.重新执行更新密码操作 刷新权限 flush privileges;
-
安装 php7
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 yum -y install php71w php71w-fpm yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache
- 验证 PHP 是否安装成功
php -v
- 验证 PHP 拓展是否安装成功
php -m
- 启动 PHP-fpm
service php-fpm start
- 验证 PHP 是否安装成功
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: