DEV Community

Sabbir Alam
Sabbir Alam

Posted on

From Zero to Laravel Hero: PHP Environment Setup on Ubuntu 22.04LTS

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
Enter fullscreen mode Exit fullscreen mode

After running that command we have to install curl.

sudo apt install curl
Enter fullscreen mode Exit fullscreen mode

Now check the curl version

curl --version
Enter fullscreen mode Exit fullscreen mode

Then install the nginx server php dependencies

sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode

Now we can install php with fpm

sudo apt install php-fpm
Enter fullscreen mode Exit fullscreen mode

Now check the PHP version

php -v
Enter fullscreen mode Exit fullscreen mode

Run this again

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install nginx repository

sudo add-apt-repository ppa:ondrej/nginx
Enter fullscreen mode Exit fullscreen mode

To check the status of PHP that it has collaborated properly with the Ngnix repository

sudo systemctl status php8.1-fpm
Enter fullscreen mode Exit fullscreen mode

Now Restart Nginx

sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

then

sudo systemctl restart nginx
Enter fullscreen mode Exit fullscreen mode

Install Network Manager Now

sudo apt-get install php-zip && sudo apt-get install php-mbstring && sudo apt-get install php-curl
Enter fullscreen mode Exit fullscreen mode

Install PHP Extensions

sudo apt-get install php-zip && sudo apt-get install php-mbstring && sudo apt-get install php-curl
Enter fullscreen mode Exit fullscreen mode

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

Run this again

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install Composer

curl -sS https://getcomposer.org/installer -o composer-setup.php
Enter fullscreen mode Exit fullscreen mode

Set Composer Address

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
Enter fullscreen mode Exit fullscreen mode

Now Check the Composer version

composer
Enter fullscreen mode Exit fullscreen mode

Run this again

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install valet

composer global require cpriego/valet-linux
Enter fullscreen mode Exit fullscreen mode

then

test -d /.composer && bash /.composer/vendor/bin/valet install || bash ~/.config/composer/vendor/bin/valet install
Enter fullscreen mode Exit fullscreen mode

The command for the updated valet version

composer global update
Enter fullscreen mode Exit fullscreen mode

then

valet install
Enter fullscreen mode Exit fullscreen mode

Run this again

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install MySQL Server

sudo apt install mysql-server -y
Enter fullscreen mode Exit fullscreen mode

Adjusting MySQL Authentication

sudo mysql
Enter fullscreen mode Exit fullscreen mode

then

SELECT user,authentication_string,plugin,host FROM mysql.user;
Enter fullscreen mode Exit fullscreen mode

then

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Enter fullscreen mode Exit fullscreen mode

then

FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

Now exits by

exit;
Enter fullscreen mode Exit fullscreen mode

Run this again

sudo apt-get update
Enter fullscreen mode Exit fullscreen mode

Install phpmyadmin

sudo apt install phpmyadmin php-mbstring php-zip php-gd php-json php-curl
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

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

Enter fullscreen mode Exit fullscreen mode

then

sudo chmod -R 777 /var/www/phpmyadmin

Enter fullscreen mode Exit fullscreen mode

Run this again

sudo apt-get update

Enter fullscreen mode Exit fullscreen mode

Install Node JS

sudo apt install nodejs

Enter fullscreen mode Exit fullscreen mode

then check nodejs version

node -v

Enter fullscreen mode Exit fullscreen mode

Install NPM

sudo apt install npm

Enter fullscreen mode Exit fullscreen mode

then

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Next,

cd ~/folder-name

Enter fullscreen mode Exit fullscreen mode

and run

valet park

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

You may use this to destroy the symbolic link.

valet unlink app-name
Enter fullscreen mode Exit fullscreen mode

Top comments (0)