LNMP Laravel环境搭建
LNMP 安装
1, 一键安装 LNMP
2,从 git 仓库 clone 代码到本地 (同时检查 .env 配置是否正确)
3,执行 composer update -o -vvv
安装第三方依赖
如果报错
[Symfony\Component\Process\Exception\RuntimeException] The Process class relies on proc_open, which is not available on your PHP installation.
则修改 /usr/local/php/etc/php.ini
文件
sudo vim /usr/local/php/etc/php.ini
搜索 disable_functions
找到 proc_open 删除
这里同时打开报错提醒,方便排除其它问题
搜索 display_errors,设置为 On
4,配置虚拟主机
执行 nmp vhost add
添加 server,根据提示一步步设置好(比如这里设置了 darren.test 域名)
编辑生成的 server 文件,参考(注意不要直接粘贴,很有可能会导致编码错误)
这里直接记录修改过后测试可用的配置文件如下
server
{
listen 80;
#listen [::]:80;
server_name blog.test ;
index index.html index.htm index.php default.html default.htm default.php;
root /home/tt/Code/MyBlog/public;
include rewrite/other.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/blog.test.log;
}
修改 hosts 文件,添加一行 127.0.0.1 darren.test
重启浏览器访问 darren.test
通常会报错 500, 具体修复参考
在Thinkphp、codeigniter、Laravel等框架下,网站目录一般是在public下,但是public下的程序要跨目录调用public上级目录下的文件,因为LNMP默认是不允许跨目录访问的,所以都是必须要将防跨目录访问的设置去掉,有时候这些框架类的程序提示500错误也可能是这个问题引起的。
具体操作分为两步:
1- 删除站点 public 目录下的 .user.ini 文件
cd 网站目录/public
chattr .user.ini
rm .user.ini
2-修改 /usr/local/nginx/conf/fastcgi.conf
sudo vim /usr/local/nginx/conf/fastcgi.conf
注释掉 fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/" 这一行,或直接删除
其它
-
如果安装composer时使用了sudo,则需要修改
/home/用户名
目录下的.composer
目录的所属用户组sudo chown 当前用户组:当前用户名 -R 站点目录
-
安装php扩展
sudo apt install php7.1-mysql mcrypt php7.1-mcrypt php7.1-mbstring php7.1-xml openssl
git托管代码
-
本机生成SSH Key
ssh-keygen -t rsa -C "your_email@example.com"
-
查看生成的公钥,并设置到github账户中
cat ~/.ssh/id_rsa.pub
- 登陆github帐户。然后 Account Settings -> 左栏点击 SSH Keys -> 点击 Add SSH key
-
修改本地的ssh remote url. 不用https协议,改用git 协议
查看当前仓库地址: git remote -v
-
设置仓库地址: git remote set-url origin git@github.com:用户名/项目名.git
-
如果失败,可以清空所有的key-pair再试
ssh-add -D rm -r ~/.ssh
-
为git设置代理(只设置国外仓,不影响国内仓速度,这里使用的代理是socks5)
- git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
- git config --global https.https://github.com.proxy socks5://127.0.0.1:1080
参考:https://www.zhihu.com/question/27159393
ubuntu 18.04
1,站点打开空白、无报错
编辑 php.ini 文件:sudo vi /etc/php/7.1/fpm/php.ini
打开 display_errors: 修改display_errors = On
2,compoer一直失败报错 composer Content-Length mismatch
更换源: composer config repo.packagist composer https://packagist.phpcomposer.com
3,缺少的php扩展(mbstring, xml)
sudo apt-get install php7.1-mbstring
sudo apt-get install php7.1-xml
本地搭建Homestead 环境时报错
$ vagrant up
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'lc/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'lc/homestead' is up to date...
==> homestead-7: Setting the name of the VM: homestead-7
==> homestead-7: Clearing any previously set network interfaces...
==> homestead-7: Preparing network interfaces based on configuration...
homestead-7: Adapter 1: nat
homestead-7: Adapter 2: hostonly
==> homestead-7: Forwarding ports...
homestead-7: 80 (guest) => 8000 (host) (adapter 1)
homestead-7: 443 (guest) => 44300 (host) (adapter 1)
homestead-7: 3306 (guest) => 33060 (host) (adapter 1)
homestead-7: 4040 (guest) => 4040 (host) (adapter 1)
homestead-7: 5432 (guest) => 54320 (host) (adapter 1)
homestead-7: 8025 (guest) => 8025 (host) (adapter 1)
homestead-7: 27017 (guest) => 27017 (host) (adapter 1)
homestead-7: 22 (guest) => 2222 (host) (adapter 1)
==> homestead-7: Running 'pre-boot' VM customizations...
==> homestead-7: Booting VM...
==> homestead-7: Waiting for machine to boot. This may take a few minutes...
homestead-7: SSH address: 127.0.0.1:2222
homestead-7: SSH username: vagrant
homestead-7: SSH auth method: private key
homestead-7:
homestead-7: Vagrant insecure key detected. Vagrant will automatically repla
ce
homestead-7: this with a newly generated keypair for better security.
homestead-7:
homestead-7: Inserting generated public key within guest...
homestead-7: Removing insecure key from the guest if it's present...
homestead-7: Key inserted! Disconnecting and reconnecting using new SSH key.
..
==> homestead-7: Machine booted and ready!
==> homestead-7: Checking for guest additions in VM...
==> homestead-7: Setting hostname...
==> homestead-7: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
/sbin/ifdown 'eth1' || true
/sbin/ip addr flush dev 'eth1'
# Remove any previous network modifications from the interfaces file
sed -e '/^#VAGRANT-BEGIN/,$ d' /etc/network/interfaces > /tmp/vagrant-network-in
terfaces.pre
sed -ne '/^#VAGRANT-END/,$ p' /etc/network/interfaces | tac | sed -e '/^#VAGRANT
-END/,$ d' | tac > /tmp/vagrant-network-interfaces.post
cat \
/tmp/vagrant-network-interfaces.pre \
/tmp/vagrant-network-entry \
/tmp/vagrant-network-interfaces.post \
> /etc/network/interfaces
rm -f /tmp/vagrant-network-interfaces.pre
rm -f /tmp/vagrant-network-entry
rm -f /tmp/vagrant-network-interfaces.post
/sbin/ifup 'eth1'
Stdout from the command:
Stderr from the command:
bash: line 5: /sbin/ifdown: No such file or directory
bash: line 21: /sbin/ifup: No such file or directory
此时是可以 vagrant ssh 登录虚拟机的,解决方案有两种:
1,登录虚拟机执行 sudo apt-get install ifupdown
,重启虚拟机
2,更新本地vagrant版本(未尝试)