美文网首页我爱编程
centos 7 安装系统+安装php环境

centos 7 安装系统+安装php环境

作者: 背木剑的温小二 | 来源:发表于2016-11-07 15:45 被阅读236次

    1 下载centos7.2 镜像

    2 制作启动u盘

    下载 ultraiso
    选择iso文件用ultraiso 点击写入磁盘映像

    3 安装系统

    开机启动按f12 选择u盘
    进入系统选择第一个 按e

    将vmlinuz initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet 改为:
     vmlinuz initrd=initrd.img inst.stage2=hd:/dev/sdb4 quiet 
    

    ok一步一步走 走到

    Paste_Image.png

    设置安装位置 和 选择软件选择里的 桌面版
    大工告成·····

    4 安装环境

    初始化系统
    设置软件源
    aliyun , remi, mysql

    设置aliyun库$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo# 设置 remi 库, 设置 mysql 库$ yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm# 由于mysql 版权方面的限制, centos 7 没有内置mysql 服务器, 必须从mysql 官方进行安装$ yum install http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

    设置 nginx 源

    源地址: nginx: Linux packages创建 vi/etc/yum.repos.d/nginx.repo
    , 并且填充以下内容来安装 yum repository 库
    [nginx]name=nginx repobaseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/gpgcheck=0enabled=1

    替换OS
    为 “rhel” 或 “centos”替换OSRELEASE
    为 5”, “6”, 或“7”
    更新元数据

    更新元数据$ yum makecache

    安装软件
    常用软件和nmp 软件

    更新系统$ yum update# 安装常用软件$ yum install vim git supervisor redis# 安装 php 基于 remi , 所以需要安装 remi 源$ yum install --enablerepo=remi-php70 php php-pdo php-fpm php-mbstring php-mcrypt php-gd php-mysqli php-zip# 安装 nginx$ yum install nginx --enablerepo=nginx# 安装 mysql server$ yum install mysql-server

    启动服务

    启动服务$ systemctl start php-fpm mysqld nginx supervisord

    开机自启动

    开机启动$ systemctl enable php-fpm mysqld nginx supervisord

    初始化数据库
    启动mysql并且获取密码
    $ systemctl start mysqld# mysql 5.7 在安装完成的时候会生成一个临时密码, 我们需要找到错误日志 /var/log/mysqld.log来获取这个临时密码# use below command to see the password:$ grep 'temporary password' /var/log/mysqld.log [Note] A temporary password is generated for root@localhost: _ab3BAKulW?r

    **初始化 mysql **
    $ mysql_secure_installationSecuring the MySQL server deployment.Enter password for user root: ******New password: ******Re-enter new password: ******The 'validate_password' plugin is installed on the server.The subsequent steps will run with the existing configurationof the plugin.Using existing password for root.Estimated strength of the password: 100 Change the password for root ? ((Press y|Y for Yes, any other key for No) : *Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : yBy default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : YSuccess.Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N... skipping.By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N ... skipping.Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : YSuccess.All done!

    设置密码的方法
    $ mysql -uroot -p******mysql> set password for 'root'@'localhost' = password('markzhao123456');mysql> exit

    软件配置
    配置nginx
    配置 nginx 时候的运行组

    /etc/nginx/nginx.confuser nginx nginx;

    配置nginx虚拟主机
    server{ listen 80; # 如果这里是 IP, 则才会允许访问, 否则, 扯破牛蛋也访问不到 server_name www.domain.com ; index index.php index.html index.htm default.html default.htm default.php; root /webdata/www/domain/public; # 这里注意和服务器自带不同的是 # fastcgi_param SCRIPT_FILENAME /scripts/$fastcgi_script_name; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # 会导致 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream 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; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .*.(js|css)?$ { expires 12h; } access_log /webdata/logs/domain_access.log; error_log /webdata/logs/domain_error.log;}

    配置php
    配置 php-fpm

    /etc/php-fpm.d/www.confuser = nginxgroup = nginx

    配置 php.ini

    时区date.timezone = Asia/Shanghai

    配置 session 是可写状态
    $ chown -R nginx:nginx /var/lib/php/session/

    配置系统允许访问

    配置 http$ firewall-cmd --permanent --zone=public --add-service=http# 配置 3306$ firewall-cmd --permanent --zone=public --add-port=3306/tcp# 重启 防火墙$ firewall-cmd --reload

    配置数据库用户
    CREATE USER 'remote'@'%' IDENTIFIED WITH mysql_native_password AS 'UOSy)iKk$XO9dMB';GRANT ALL PRIVILEGES ON . TO 'remote'@'%' REQUIRE NONE WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;GRANT ALL PRIVILEGES ON 1dailian\_v2. TO 'remote'@'%' WITH GRANT OPTION;FLUSH PRIVILEGES

    补充
    下载安装mysql
    获取最新下载地址:http://dev.mysql.com/downloads/mysql/
    下载地址:http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.13-1.el7.i686.rpmhttp://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.13-1.el7.i686.rpm

    下载$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.13-1.el7.i686.rpm$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.13-1.el7.i686.rpm# 安装yum localinstall mysql-community-client.rpmyum localinstall mysql-community-server.rpm

    参考文章
    How To Install Nginx on CentOS 7(很及时, 解决了无法使用IP连接上服务器的问题)
    Nginx安装(官网翻译)
    nginx FastCGI错误Primary script unknown解决办法

    相关文章

      网友评论

        本文标题:centos 7 安装系统+安装php环境

        本文链接:https://www.haomeiwen.com/subject/jaofuttx.html