Sometimes, especially when you're at the beginning of your career, it can seem that you're following the instructions and getting nowhere - while everyone else seems to find it terribly easy.
It can be pretty disheartening, and I want to describe a couple of ways I experience exactly the same thing even after, well, decades. So here I am, trying to detail the stumbles and bumbles I make trying to get things to work. This is my first post on the subject, but I hope to make more.
Let's learn Laravel.
Laravel strives to provide an amazing developer experience [...]
Whether you are new to PHP web frameworks or have years of experience [...]
Laravel is touted as being the "developers' framework, at least in PHP circles, because it's more bare-bones than the others and it takes simple yet strict architecture decisions. I've done a few other PHP frameworks - Drupal 7, Drupal 8 , Symfony, WordPress, Concrete5, PrestaShop, CodeIgniter off the top of my head - so I'm not going into this unprepared.
I'll start from a barebones laptop and see how far I get.
Installing prerequisites (tldr; issues: zero, confidence: supreme)
Before creating your first Laravel application, make sure that your local machine has PHP, Composer, and the Laravel installer installed. In addition, you should install either Node and NPM or Bun so that you can compile your application's frontend assets.
OK. Not a problem. I'll apt install myself some of that PHP, get composer from... getcomposer.org, and figure out how to install the "Laravel installer" next. Aparently my distro has Node 22 out the box, or it installed when I set something else up earlier, so that should be covered.
$ composer global require laravel/installer
Boom. Done. No problems yet, we're off to a good start and confidence is at an all-time high.
Setting up a new Laravel project (tldr; issues: some, confidence: high)
$ laravel new example-app
zsh: command not found: laravel
Oh. Maybe I have to revisit that supreme confidence thing.
So it seems that composer doesn't install anything into regular binary paths and the composer installer doesn't do anything to add itself to the system path either. I've never really had to face that before, since I've directly run composer-installed binaries from whatever path they appear in. For example, with Drupal, there's vendor/drush/drush/drush or vendor/bin/drush depending on which version you're running. Do I need to add myself a symlink or alias or find the laravel binary wherever composer added it, "globally"?
I don't know, so I have to search for this.
I find some clues on a Stack Overflow answer: you can find the composer binary directory with composer global config bin-dir --absolute, and apparently in modern versions of composer everything with an executable command gets it put into that directory rather than losing itself to the hierarchy.
Good. I can add something to my startup script to put that in my path... except that command produces more than just the path...
$ composer global config bin-dir --absolute
Changed current directory to /home/moopet/.config/composer
/home/moopet/.config/composer/vendor/bin
... and I can't use that whole string as a directory. Maybe I'll need to use tail to get the last line, or something. Wait, no there's another comment on this SO answer which includes the --quiet flag. What does that do? I'll try composer --help:
Usage:
list [options] [--] []
Well, uh, turns out that running --help on a bare composer command actually gives help for the list subcommand rather than composer itself. That had me stumped for a minute.
-q --quiet Do not output any message
Hmm, that doesn't sound useful! We want some output. What else is there?
--raw To output raw command list
--format=FORMAT The output format (txt, xml, json, or md) [default: "txt"]
Maybe it's one of these?
The "--raw" option does not exist.
The "--format" option does not exist.
Nope. Like I thought, these are options to list and not general use flags.
Let's run it with --quiet anyway, just for poops and funsies:
$ composer global config bin-dir --absolute --quiet
/home/moopet/.config/composer/vendor/bin
Well, what do you know, it worked. It's just badly documented.
I'll pop that into my shell startup script with a little guard code and we can continue:
if command -v composer >/dev/null; then export PATH=$(composer global config bin-dir --absolute --quiet):$PATH fi
Setting up a new Laravel project, take 2 (tldr; issues: some, confidence: wavering)
This time laravel new example-app launches, and prompts me for a few things. I accept the defaults, since I haven't read far enough in the documentation to know the difference, except for the starter kit. I choose, "Breeze" because that's how it is in the documentation.
It starts the installation process and all looks good until:
- Root composer.json requires laravel/pint ^1.0 -> satisfiable by laravel/pint[v1.0.0, v1.1.0, v1.1.1].
- laravel/pint[v1.0.0, ..., v1.1.1] require ext-xml * -> it is missing from your system. Install or enable PHP's xml extension.
Wait, PHP needs the XML extension? That was never listed as a requirement! OK, I'll do a quick apt install php-xml.
Good, all installed. I'll run the setup again.
laravel new example-app
In NewCommand.php line 789:
Application already exists!
Oh.
So the installer got part way through, failed because it hadn't verified its dependencies, and has left the app in a broken state. That's not a good sign. Laravel's on, what, version 11?
Surely they'd have basic up-front requirements checking by now? Oh well. I'll just rm -r example-app and start again, nothing lost because I haven't really started yet.
Long story short1 the next missing dependency was the the DOM extension, or maybe the XML extension. Or maybe the cURL extension.
- phpunit/phpunit[11.0.1, ..., 11.4.3] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
- Root composer.json requires phpunit/phpunit ^11.0.1 -> satisfiable by phpunit/phpunit[11.0.1, ..., 11.4.3].
So I need to install php-dom? No. Try some others. Stack Overflow again. Turns out I need to install php-curl. Riiiight.
Onward. rm -r the directory and run through the setup wizard again.
Setting up a new Laravel project, take 3 (tldr; issues: hngg, confidence: still wavering but bolstered by recent problem-solving success)
It prompts me for which database server to use. All of them say, "Missing PDO extension" next to them.
Sigh.
I break out of the installer, delete the whole directory again, apt install php8.3-mysql because there's no direct php-pdo package and no alias for php-mysql that works either, so I've done some tiresome apt searching.
IlluminateDatabaseQueryException
SQLSTATE[HY000] [2002] Connection refused (Connection: mysql, SQL: select exists (select 1 from information_schema.tables where table_schema = 'laravel_example_app' and table_name = 'migrations' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED')) as 'exists')
What the what now? At no point has this installer asked me for connection details for a database. And it's trying to run SQL commands against... something. Who knows?
As it happens, I have a MySQL server running on another host in my LAN and was prepared to use that (even though I'll note that bringing your own database was not listed as a requirement for Laravel). I guess I should have installed SQLite, maybe that would have worked, since it won't need any credentials.
sudo apt install php8.3-sqlite
Try again.
rm -r example-app
laravel new example-app
...
Great success. Hacker voice "I'm in". For the win. Success kid.
Conclusion
I made it? I think.
But if someone had asked me how long this might take, then based off the enthusiastic documentation and reputation, I'd have said 20 minutes. If I was doing it for work, my project manager would have doubled or quadrupled that based on experience of developer estimates.
How long did it really take me? An hour or so one evening and an hour or so the next day. I wasn't rushing, but it wasn't straightforward.
And you know what? I'm not happy with it. It's not using MySQL, because that part of the installer appears to be completely broken. I'm using SQLite and that's one step further from what would be going on in a real production environment. So there're definitely some things left on the TODO list before I can get going with the actual tutorials.
But it runs. The build steps claim they went without a hitch.
I'm ready for the next phase: fixing the JsonException, Syntax error and ProcessTimedOutException that appear in the console as soon as I open the demo page in my browser.
Uh-oh.
If only things worked out the box, eh.
-
Chorus: too late ↩
The above is the detailed content of (My first time) Installing Laravel. For more information, please follow other related articles on the PHP Chinese website!

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

Key players in HTTP cache headers include Cache-Control, ETag, and Last-Modified. 1.Cache-Control is used to control caching policies. Example: Cache-Control:max-age=3600,public. 2. ETag verifies resource changes through unique identifiers, example: ETag: "686897696a7c876b7e". 3.Last-Modified indicates the resource's last modification time, example: Last-Modified:Wed,21Oct201507:28:00GMT.

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

Zend Studio 13.0.1
Powerful PHP integrated development environment