From Zero to Laravel Hero: PHP Environment Setup on Ubuntu 22.04LTS
Published: 2024-02-22 11:39:58

It is recommended that you configure your Ubuntu environment to execute Laravel projects using a Nginx server. You appear to be able to connect your Nginx server to PHPMyAdmin. On your Ubuntu system, you can install MySQL server with PHP-8.1.

_Before Running Any Command You Need To Run_

```
sudo apt-get update && sudo apt-get upgrade
```

After running that command we have to install curl.

```
sudo apt install curl
```
Now check the curl version

```
curl --version
```
Then install the nginx server php dependencies

```
sudo apt install nginx
```
Now we can install php with fpm

```
sudo apt install php-fpm
```
Now check the PHP version

```
php -v
```
Run this again

```
sudo apt-get update
```
Install nginx repository

```
sudo add-apt-repository ppa:ondrej/nginx
```
To check the status of PHP that it has collaborated properly with the Ngnix repository

```
sudo systemctl status php8.1-fpm
```
Now Restart Nginx

```
sudo nginx -t
```
then

```
sudo systemctl restart nginx
```
Install Network Manager Now

```
sudo apt-get install php-zip && sudo apt-get install php-mbstring && sudo apt-get install php-curl
```
Install PHP Extensions

```
sudo apt-get install php-zip && sudo apt-get install php-mbstring && sudo apt-get install php-curl
```

> NB: It will automatically detect your version and do its work.

Run this again

```
sudo apt-get update
```
Install Composer

```
curl -sS https://getcomposer.org/installer -o composer-setup.php
```
Set Composer Address

```
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
```
Now Check the Composer version

```
composer
```
Run this again

```
sudo apt-get update
```
Install valet

```
composer global require cpriego/valet-linux
```
then

```
test -d /.composer && bash /.composer/vendor/bin/valet install || bash ~/.config/composer/vendor/bin/valet install
```
The command for the updated valet version

```
composer global update
```
then

```
valet install
```
Run this again

```
sudo apt-get update
```
Install MySQL Server

```
sudo apt install mysql-server -y
```
Adjusting MySQL Authentication

```
sudo mysql
```
then

```
SELECT user,authentication_string,plugin,host FROM mysql.user;
```
then

```
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
```
then

```
FLUSH PRIVILEGES;
```
Now exits by

```
exit;
```
Run this again

```
sudo apt-get update
```
Install phpmyadmin

```
sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
```
if you face any difficulties follow the link [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-phpmyadmin-on-ubuntu-20-04]

_Symlink phpmyadmin With MySQL Server_

> Now You have to go to your C Drive & open the Terminal and run this

```
sudo chmod -R 777 /var/www

```
This will give Permission to Symlink now come back to the root terminal & run this

```
ln -s /usr/share/phpmyadmin /var/www/phpmyadmin

```
then

```
sudo chmod -R 777 /var/www/phpmyadmin

```
Run this again

```
sudo apt-get update

```
Install Node JS

```
sudo apt install nodejs

```
then check nodejs version

```
node -v

```
Install NPM

```
sudo apt install npm

```
then

```
sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node

```
You are good to go, Now develop your web application in your Ubuntu by Using Laravel & PHP....

Serving Sites by Valet
Once Valet is installed, you’re ready to start serving sites. Valet provides two commands to help you serve your Laravel sites: park and link.

The Park Command
Create a new directory on your machine by running something like

```
mkdir ~/folder-name

```
Next,

```
cd ~/folder-name

```
and run

```
valet park

```
This command will register your current working directory as a path that Valet should search for folder-name. Next, create a new Laravel site within this directory: Open http://folder-name.test in your browser. That’s all there is to it. Now, any Laravel project you create within your “parked” directory will automatically be served using the http://folder-name.test convention.

The link Command
The link command may also be used to serve your Laravel sites. This command is useful if you want to serve a single site in a directory and not the entire directory.

To use the command, navigate to one of your projects, open your terminal and run

```
valet link

```
Valet will create a symbolic link in ~/.valet/Sites which points to your current working directory. After running the link command, you can access the site in your browser at http://app-name.test. To see a listing of all of your linked directories, run this command

```
valet links

```
You may use this to destroy the symbolic link.

```
valet unlink app-name
```