美文网首页PHP经验分享
阿里云CentOS 7 LNMP 环境搭建+Laravel运行

阿里云CentOS 7 LNMP 环境搭建+Laravel运行

作者: 浪来了2016 | 来源:发表于2017-05-29 18:09 被阅读431次

目标:

在阿里云的 CentOS 7 上搭建好一套可以跑 Laravel 5.4 的环境,基础为
Nginx + PHP7 + MariaDB


概括:

1. 安装 Nginx

2. 安装MariaDB

3. 安装 PHP 7

4. 配置虚拟主机,同步 Laravel 测试


步骤:

1. 安装 Nginx

编译前要判断系统是否有安装openssl 、pcre 、pcre-devel、zlib、gcc 、gcc-c++等依赖,没有的话先提前安装
wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0e.tar.gz
tar -xvzf OpenSSL_1_1_0e.tar.gz

yum  install -y pcre pcre-devel zlib-devel gcc gcc-c++

wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar -xzvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-openssl=/root/openssl-OpenSSL_1_1_0e
make
make install

安装好了,可以测试Nginx 是否工作,这个时候,一定要记得检查 阿里云的安全组策略,80端口有没有打开,我就是一开始没检查,阿里云默认只开放 22 和3389 端口,结果,我搞了好几个小时才发现是端口给封了!!!

/usr/local/nginx/sbin/nginx  //开启服务

然后访问 IP ,看到欢迎页面说明配置生效

Nginx欢迎页面

2. 安装MariaDB

yum -y install mariadb mariadb-server
systemctl start mariadb
mysql_secure_installation  //进入配置环境

3. 安装 PHP 7

wget http://cn2.php.net/distributions/php-7.1.7.tar.gz
tar -xzvf php-7.1.7.tar.gz
cd php-7.1.7
yum install -y libxml2 libxml2  libxml2-devel  //安装一些必要的插件


yum install openssl openssl-devel //之前的openssl不起作用
ln -s /usr/lib64/libssl.so /usr/lib/

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-mysql --with-gd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl --enable-exif --enable-ctype

如果遇到一些报错
configure: error: Please reinstall the libcurl distribution -
是curl的dev包没有安装, 解决方案:
yum -y install curl-devel

编译时出现configure: error: libjpeg.(a|so) not found 错误的解决办法
yum -y install libjpeg-devel

make
make install

cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
 /usr/local/bin/php-fpm  //启动 php-fpm
/usr/local/nginx/sbin/nginx -s stop  //重启 Nginx
/usr/local/nginx/sbin/nginx

再新建一个 php 文件测试一下

phpinfo正常运行

4. 配置虚拟主机,同步 Laravel 测试

开启 Nginx 配置文件的 vhost 加载

include /usr/local/nginx/conf/vhost/*.conf;

在vhost 目录增加conf文件,如abc.conf【适合Laravel 运行的配置】

server {
        listen       80;
        server_name yah.abc.com;
        index index.html index.htm index.php;
        root  /usr/local/nginx/html/yah.xxx.com/public;  //Laravel public文件位置
        try_files $uri $uri/ @rewrite;
        location @rewrite{
            rewrite ^/(.*)$ /index.php?_url=/$1;
        }
        location ~ \.php$ {
            root           /usr/local/nginx/html/yah.xxx.com/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ /\.ht {
                deny all;
                }
        }

然后安装一个 Laravel 下来

composer create-project --prefer-dist laravel/laravel abc

记得加上相应的文件权限就可以跑了

laravel 5.4

To write:

Https 配置

相关文章

网友评论

    本文标题:阿里云CentOS 7 LNMP 环境搭建+Laravel运行

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