vmware 搭建 centos7 + nginx + php7.2 + mysql5.7 + composer + redis + laravel + swoole 开发环境

CENTOS7

打开vmware新建虚拟机就可以了,这里我用的阿里云镜像
http://mirrors.aliyun.com/centos/7.6.1810/isos/x86_64/CentOS-7-x86_64-Minimal-1810.iso

安装好虚拟机后设置挂载

设置虚拟机共享文件,右键虚拟机名称在选项、共享文件夹中设置
点击虚拟机、安装vmware tools,并需要准备gcc、gcc-c++、make、kernel-devel

yum install gcc gcc-c++ make -y
yum install kernel-devel -y
yum update kernel -y

在根目录下创建挂载目录并且挂载cd-rom

mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom

准备安装vmware tools

cd /mnt/cdrom/
cp VMwareTools-版本号.tar.gz /home/
cd /home
tar -xzvf VMwareTools-版本号.tar.gz
cd vmware-tools-distrib
./vmware-install.pl

接下来会出现一大堆提示,根据提示信息输入y或n即可
出现enjoy表示安装成功
注意:一定要正确安装gcc和kernel,并注意kernel-headers的版本与kernel-devel是否一致
这时可能还没看到/mnt/hgfs下的挂载文件

yum install open-vm-tools-devel -y
vmhgfs-fuse .host:/ /mnt/hgfs

耶!

搭建nginx环境

安装nginx最新源并且安装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 install -y nginx
systemctl enable nginx
systemctl start nginx

一般来说是指定开放某端口
这里是本地虚拟机,图省事,使虚拟机和主机之间通信,则关闭防火墙、关闭selinux

systemctl stop firewalld.service
systemctl disable firewalld.service
vi /etc/selinux/config

将 SELINUX=enforcing 改为 SELINUX=disabled
宿主机上访问给虚拟机分配的ip地址,出现welcome to nginx!
耶!

搭建php7.2

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 install -y php72w php72w-cli php72w-devel php72w-gd php72w-fpm php72w-mbstring php72w-pear php72w-xml php72w-xmlrpc php72w-common php72w-pdo

耶!

搭建MySQL5.7

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum -y install mysql-community-server
systemctl enable mysqld
systemctl start mysqld

在mysqld.log中找到mysql的默认密码

grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
<input your password>

初始化操作时需要重置密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'HelloWorld_001'; 

(可选)把密码改简单一点

set global validate_password_policy=0;  
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 
flush privileges;

然后添加远程用户访问

GRANT ALL PRIVILEGES ON *.* TO '新用户名'@'%' IDENTIFIED BY '新密码' WITH GRANT OPTION;
flush privileges;
exit;

修改默认编码

vim /etc/my.cnf

修改如下配置
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

systemctl restart mysqld

在宿主机上访问一下试试,我用的navicat,成功
ok~

配置nginx

vim /etc/nginx/nginx.conf

参考

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    keepalive_timeout  65;
    types_hash_max_size 2048;
    #gzip  on;

    include /etc/nginx/conf.d/*.conf;

    server {
    	listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /mnt/hgfs/wwwroot;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }

        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;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

项目配置在conf.d下
如lara.game.com.conf

server {
        listen       80;
        server_name  lara.game.com;
        root         /mnt/hgfs/wwwroot/lara.game.com/public;

        location / {
            index index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }

        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;
        }
}

设置php-fpm启动并开机自启动

systemctl start php-fpm
systemctl enable php-fpm

宿主机设置好host文件
访问 lara.game.com,成功

在使用clash等vpn时需要注意自己配置的域名需要在vpn的配置文件中设置一下,以免被vpn代理。
耶!

composer

cd /home
curl -sS https://getcomposer.org/installer | php
mv composer.phar  /usr/local/bin/composer
composer -v

会报提示
Do not run Composer as root/super user! See https://getcomposer.org/root for details
建议新建用户,赋予管理员权限

cd /
adduser 用户名
passwd 用户名
<input your password>
<input your password again>

添加用户名进sudoers

vim /etc/sudoers

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
用户名 ALL=(ALL) NOPASSWD:ALL

:wq! 保存退出

redis

yum install -y wget
cd /home
wget http://download.redis.io/releases/redis-4.0.1.tar.gz
mv redis-4.0.1 redis
cd redis
make && make install
cp redis.conf /etc/
redis-server -v #查看版本
redis-server /etc/redis.conf #启动redis服务

(ctrl+c)退出

vim /etc/redis.conf

修改
daemonize yes
requirepass 你的密码

vim /etc/init.d/redis

复制

#!/bin/sh
# chkconfig: 2345 10 90  
# description: Start and Stop redis   

REDISPORT=6379
EXEC=/home/redis/src/redis-server
CLIEXEC=/home/redis/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis.conf"
AUTH="你的密码"

case "$1" in
    start)
        if [ -f \$PIDFILE ]
        then
       			echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF &
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac

保存退出并设置权限并设置开机自启动

chmod 777 /etc/init.d/redis
chkconfig redis on

php-redis扩展

cd /home
wget https://github.com/nicolasff/phpredis/archive/master.zip 
yum install -y unzip
unzip master.zip
cd phpredis-master
phpize
./configure
make && make install
cd /usr/lib64/php/modules/ #可能路径不一样,安装完成后会提示这个路径,看到有redis.so

打开php.ini添加扩展

vim /etc/php.ini

添加
extension=redis.so
重启php-fpm,打开phpinfo
耶!

SWOOLE

yum install -y php72w-pear
pecl install swoole #一路回车
vim /etc/php.ini

添加
extension=swoole.so

laravel

通过 php -m 查看php扩展是否达到以下条件
PHP >= 7.0.0
PHP OpenSSL 扩展
PHP PDO 扩展
PHP Mbstring 扩展
PHP Tokenizer 扩展
PHP XML 扩展

cd /home
composer global require "laravel/installer" #记住这里的路径

切换到root用户下

vim ~/.bashrc

添加
export PATH=刚才的路径/.config/composer/vendor/bin:$PATH
保存
耶!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值