Update: 02/01/2024 - I used these instructions for WSL in Windows and it worked!.
These are the commands I used to install laravel on my linux ubuntu using virtualbox from a windows PC. What I did I installed a fresh ubuntu 18.04 version with minimal installation. if you did not installed a minimal installation, some of the required dependencies may already be in your system and you might get a message telling you that you already have the latest version. so lets try it.
1. UPDATE:
sudo apt-get update
2. install php
sudo apt install php
For some reason, this command automatically install V7, if you need V8 take a look at this article:
https://linuxize.com/post/how-to-install-php-8-on-ubuntu-20-04/
To Update from V7 to V8: Source: https://wpfrank.com/upgrade-php7-to-php8-on-ubuntu/
sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
NOTE: Replace 8.0 to whatever version you like, for example 8.1sudo apt install php8.0 php8.0-common php8.0-cli php8.0-fpm php8.0-mysql php8.0-xml php8.0-curl php8.0-gd php8.0-mbstring php8.0-opcache php8.0-zip
php -v
Output:
PHP 8.0.30 (cli) (built: Sep 2 2023 08:04:32) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies
CONFIRM: php -v
OUTPUT:
PHP 7.2.19-0ubuntu0.18.04.1 (cli) (built: Jun 4 2019 14:48:12) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.19-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
3. install curl
sudo apt install curl
4. install GIT
sudo apt install git
5. install homebrew: https://docs.brew.sh/Homebrew-on-Linux
UPDATE: Please note, The first time I ran these commands below, brew worked on my linux ubuntu machine, however, after I restarted my machine, brew did not work, however, I ran this command to make it work again:
sudo apt install linuxbrew-wrapper
cd ~
sh -c "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install.sh)"
OUTPUT:
==> Pouring portable-ruby-3.1.4.x86_64_linux.bottle.tar.gz
Warning: /home/linuxbrew/.linuxbrew/bin is not in your PATH.
Instructions on how to configure your shell for Homebrew
can be found in the 'Next steps' section below.
==> Installation successful!
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
https://github.com/Homebrew/brew#donations
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"') >> /home/edwino85/.bashrc
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
- Install Homebrew's dependencies if you have sudo access:
sudo apt-get install build-essential
For more information, see:
https://docs.brew.sh/Homebrew-on-Linux
- We recommend that you install GCC:
brew install gcc
- Run brew help to get started
- Further documentation:
https://docs.brew.sh
#MAKE A BACKUP OF PRFOILE TO UPDATE THE PATH:
cp ~/.profile ~/.profile-BACKUP
# SEND COMMMANDS TO SET PATH:
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
DONE, YOU CAN TEST IT:
brew install hello
YOU SHOULD GET A MESSAGE LIKE THIS: (if not, run again: $ brew install hello)
Warning: hello 2.10 is already installed and up-to-date
To reinstall 2.10, run `brew reinstall hello`
6. install composer globally https://getcomposer.org/download/
Example Only: You will need to go to https://getcomposer.org/download/ to view the latest commands:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '48e3236262b34d30969dca3c37281b3b4bbe3221bda826ac6a9a62d6444cdb0dcd0615698a5cbe587c3f0fe57a54d8f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
YOU WILL GET A MESSAGE ON COMPLETION:
All settings correct for using Composer
Downloading...
Composer (version 1.8.6) successfully installed to: /home/developer/composer.phar
Use it: php composer.phar
TO RUN COMPOSER GLOBALLY: https://getcomposer.org/doc/00-intro.mdsudo mv composer.phar /usr/local/bin/composer
NOW YOU SHOULD ONLY TYPE: composer
AND YOU WILL SEE THE SAME OUTPUT AS php composer.phar
INSTALL laravel: https://laravel.com/docs/5.8/installation
composer global require laravel/installer
Success:
6 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
11 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
Using version ^4.5 for laravel/installer
I GOT THIS ERROR with composer global require laravel/installer
Changed current directory to /home/developer/.config/composer
Using version ^2.1 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for laravel/installer ^2.1 -> satisfiable by laravel/installer[v2.1.0].
- laravel/installer v2.1.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
To enable extensions, verify that they are enabled in your .ini files:
- /etc/php/7.2/cli/php.ini
- /etc/php/7.2/cli/conf.d/10-opcache.ini
- /etc/php/7.2/cli/conf.d/10-pdo.ini
- /etc/php/7.2/cli/conf.d/20-calendar.ini
- /etc/php/7.2/cli/conf.d/20-ctype.ini
- /etc/php/7.2/cli/conf.d/20-exif.ini
- /etc/php/7.2/cli/conf.d/20-fileinfo.ini
- /etc/php/7.2/cli/conf.d/20-ftp.ini
- /etc/php/7.2/cli/conf.d/20-gettext.ini
- /etc/php/7.2/cli/conf.d/20-iconv.ini
- /etc/php/7.2/cli/conf.d/20-json.ini
- /etc/php/7.2/cli/conf.d/20-phar.ini
- /etc/php/7.2/cli/conf.d/20-posix.ini
- /etc/php/7.2/cli/conf.d/20-readline.ini
- /etc/php/7.2/cli/conf.d/20-shmop.ini
- /etc/php/7.2/cli/conf.d/20-sockets.ini
- /etc/php/7.2/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.2/cli/conf.d/20-sysvsem.ini
- /etc/php/7.2/cli/conf.d/20-sysvshm.ini
- /etc/php/7.2/cli/conf.d/20-tokenizer.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.
Installation failed, deleting ./composer.json.
FIX ERROR: https://lerie.us/blog/2019/01/11/laravel-installer-v2-0-1-requires-ext-zip-the-requested-php-extension-zip-is-missing-from-your-system/
sudo apt-get -y install php7.[x]-zip
* CHANGE [x] TO WHATEVER VERSION YOU HAVE OR ELSE YOU MIGHT GET THIS ERROR: GOT ERROR:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php7.0-zip
E: Couldn't find any package by glob 'php7.0-zip'
E: Couldn't find any package by regex 'php7.0-zip'
TRY AGAIN:
7. INSTALL laravel: https://laravel.com/docs/5.8/installation
composer global require laravel/installer
COMPLETED:
Changed current directory to /home/developer/.config/composer
Using version ^2.1 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 14 installs, 0 updates, 0 removals
- Installing symfony/process (v4.3.2): Downloading (100%)
- Installing symfony/polyfill-ctype (v1.11.0): Downloading (100%)
- Installing symfony/filesystem (v4.3.2): Downloading (100%)
- Installing psr/container (1.0.0): Downloading (100%)
- Installing symfony/service-contracts (v1.1.5): Downloading (100%)
- Installing symfony/polyfill-php73 (v1.11.0): Downloading (100%)
- Installing symfony/polyfill-mbstring (v1.11.0): Downloading (100%)
- Installing symfony/console (v4.3.2): Downloading (100%)
- Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
- Installing ralouphie/getallheaders (3.0.3): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing guzzlehttp/psr7 (1.6.1): Downloading (100%)
- Installing guzzlehttp/guzzle (6.3.3): Downloading (100%)
- Installing laravel/installer (v2.1.0): Downloading (100%)
symfony/service-contracts suggests installing symfony/service-implementation
symfony/polyfill-mbstring suggests installing ext-mbstring (For best performance)
symfony/console suggests installing symfony/event-dispatcher
symfony/console suggests installing symfony/lock
symfony/console suggests installing psr/log (For using the console logger)
guzzlehttp/psr7 suggests installing zendframework/zend-httphandlerrunner (Emit PSR-7 responses)
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
Writing lock file
Generating autoload files
DONE laravel Completed Installation
8. PUT COMPOSER'S SYSTEM-WIDE VENDOR BIN DIRECTORY IN YOUR $PATH
$HOME/.config/composer/vendor/bin
For WSL in windows, i got this error message:
Error: -bash: /home/[USER]/.config/composer/vendor/bin: Is a directory
Try this: https://stackoverflow.com/questions/25373188/how-to-place-the-composer-vendor-bin-directory-in-your-path
9. CHECK for a 'vendor' directory in /home/developer/.config/composer
ls ~/.config/composer/vendor/bin
10. NOW SET YOUR BIN $PATH:
sudo nano ~/.bashrc
ADD OR CHECK FOR THIS LINE:
export PATH=~/.config/composer/vendor/bin:$PATH
RESTART SHELL:
source ~/.bashrc
11. create a projects directory:
mkdir -p ~/laravel/projects/
12. Change to the newly created projects directory:
cd ~/laravel/projects/
13. DONE: YOU ARE READY TO GO:
laravel new myfirstsite
I GOT THESE ERRORS:
Crafting application...
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for erusev/parsedown 1.7.3 -> satisfiable by erusev/parsedown[1.7.3].
- erusev/parsedown 1.7.3 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
Problem 2
- Installation request for laravel/framework v5.8.28 -> satisfiable by laravel/framework[v5.8.28].
- laravel/framework v5.8.28 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
Problem 3
- Installation request for phar-io/manifest 1.0.3 -> satisfiable by phar-io/manifest[1.0.3].
- phar-io/manifest 1.0.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 4
- Installation request for phpunit/php-code-coverage 6.1.4 -> satisfiable by phpunit/php-code-coverage[6.1.4].
- phpunit/php-code-coverage 6.1.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 5
- Installation request for phpunit/phpunit 7.5.14 -> satisfiable by phpunit/phpunit[7.5.14].
- phpunit/phpunit 7.5.14 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 6
- Installation request for theseer/tokenizer 1.1.3 -> satisfiable by theseer/tokenizer[1.1.3].
- theseer/tokenizer 1.1.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 7
- laravel/framework v5.8.28 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
- beyondcode/laravel-dump-server 1.2.2 requires illuminate/console 5.6.*|5.7.*|5.8.* -> satisfiable by laravel/framework[v5.8.28].
- Installation request for beyondcode/laravel-dump-server 1.2.2 -> satisfiable by beyondcode/laravel-dump-server[1.2.2].
12. Lets install the required dependcies:
sudo apt-get -y install php7.2-mbstring
sudo apt-get -y install php7.2-dom
13. LET"S TRY AGAIN:
rm -rf myfirstsite/
laravel new myfirstsite
NO MORE ERRORS! YOU SHOULD SEE SOMETING LIKE THIS:
Application ready! Build something amazing.
Version 10 error: (update php if need.)
Creating a "laravel/laravel" project at "./myfirstsite"
Cannot use laravel/laravel's latest version v10.3.2 as it requires php ^8.1 which is not satisfied by your platform.
Installing laravel/laravel (v9.5.2)
As there is no 'unzip' nor '7z' command installed zip files are being unpacked using the PHP zip extension.
This may cause invalid reports of corrupted archives. Besides, any UNIX permissions (e.g. executable) defined in the archives will be lost.
Installing 'unzip' or '7z' (21.01+) may remediate them.
cd myfirstsite
ls
you will see your project file!
app bootstrap composer.lock database phpunit.xml resources server.php tests webpack.mix.js
artisan composer.json config package.json public routes storage vendor yarn.lock
You are ready to start your server:
php artisan serve
You can now see the default laravel project at
http://127.0.0.1:8000
15. install visual studio code, sublime or any other text code editor
Next you might want to install Ionic if so, you will need node.js:
sudo apt install nodejs
sudo apt install npm
sudo npm install -g ionic
Start an IONIC app:
sudo npm install -g ionic
ionic start myApp tabs
cd myApp
ionic serve
Good luck!