Skip to content

Instantly share code, notes, and snippets.

@elcheco
Last active August 31, 2022 10:57
Show Gist options
  • Save elcheco/d7eebcaa8bb2b8afb6171a9ce24e923a to your computer and use it in GitHub Desktop.
Save elcheco/d7eebcaa8bb2b8afb6171a9ce24e923a to your computer and use it in GitHub Desktop.
Laravel Homestead - how to compile openssl on apple silicon m1 - arm64 - add this at the end of your after.sh file
#!/bin/bash
OPENSSL_VERSION=$(openssl version)
if [[ $OPENSSL_VERSION == *"OpenSSL 1.1.1m"* ]]; then
sudo DEBIAN_FRONTEND=noninteractive echo 'OpenSSL already compiled to the correct version' ;
else
cd /home/vagrant
mkdir build
mkdir build/openssl
wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1m.tar.gz.sha256
tar -zxf openssl-1.1.1m.tar.gz --directory build/openssl
cd build/openssl/openssl-1.1.1m/
./config --prefix=/opt/openssl --openssldir=/opt/openssl/ssl
make
sudo make install
sudo mv /usr/bin/openssl /usr/bin/openssl.old
sudo mv /usr/bin/c_rehash /usr/bin/c_rehash.old
sudo ln -s /opt/openssl/bin/openssl /usr/bin/openssl
sudo ln -s /opt/openssl/bin/c_rehash /usr/bin/c_rehash
sudo touch /etc/profile.d/openssl.sh
sudo chmod +x /etc/profile.d/openssl.sh
sudo tee -a /etc/profile.d/openssl.sh > /dev/null <<EOT
#!/bin/sh
export LD_LIBRARY_PATH=/opt/openssl/lib:${LD_LIBRARY_PATH}
EOT
echo "Updating configs"
echo "source /etc/profile.d/openssl.sh" | sudo tee -a /etc/bash.bashrc
echo "source /etc/profile.d/openssl.sh" | sudo tee -a /etc/zsh/zprofile
cd /home/vagrant
rm openssl-1.1.1m.tar.gz
rm openssl-1.1.1m.tar.gz.sha256
fi
@elcheco
Copy link
Author

elcheco commented Feb 2, 2022

There's a known unresolved bug in OpenSSL 1.1.1f for arm64 processors which is used in the following:
ubuntu-20.04.2-live-server-arm64.iso
ubuntu-20.04.3-live-server-arm64.iso

This makes issues also in the Laravel Homestead ARM64 version:

You get Segmentation fault error messages just by calling curl command on the command line, also php-curl, guzzlehttp is affected.

This could be fixed by recompiling openssl higher then 1.1.1l (probably), but to recompile openssl exited for many users with following error openssl: symbol lookup error: openssl: undefined symbol: EVP_md2, version OPENSSL_1_1_0.

I found some workaround - add the above script into you after.sh in your homestead directory. Be aware that after.sh file have to start with #!/bin/bash and not #!/bin/sh. If you vagrant reload --provision or vagrant up --provision (or destroy and up) your vagrant, it will compile and set the latest OpenSSL 1.1.1m version and everything works fine. There will be build directory in the homestead home directory.

@skliarovartem
Copy link

mv: rename /usr/bin/openssl to /usr/bin/openssl.old: Operation not permitted
mv: rename /usr/bin/c_rehash to /usr/bin/c_rehash.old: No such file or directory
ln: /usr/bin/openssl: Operation not permitted
ln: /usr/bin/c_rehash: Operation not permitted
touch: /etc/profile.d/openssl.sh: No such file or directory
chmod: /etc/profile.d/openssl.sh: No such file or directory
tee: /etc/profile.d/openssl.sh: No such file or directory
Updating configs
source /etc/profile.d/openssl.sh
tee: /etc/zsh/zprofile: No such file or directory
source /etc/profile.d/openssl.sh
./install_openssl: line 33: cd: /home/vagrant: No such file or directory
rm: openssl-1.1.1m.tar.gz: No such file or directory
rm: openssl-1.1.1m.tar.gz.sha256: No such file or directory

@elcheco
Copy link
Author

elcheco commented Feb 11, 2022

On which Linux distro are you using it? On Vagrant?

@skliarovartem
Copy link

MacOS Monterey

@elcheco
Copy link
Author

elcheco commented Feb 11, 2022

Laravel Homestead - is a pre-build virtual machine using Linux Ubuntu 20.04 for ARM64 - the issue is that OpenSSL doesn't work inside this VM. - i's not code which works on macOS, but in VM running on macOS...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment