At this writingUbuntu LTS 22.04in the editionLaravelWe will talk about installing the library and publishing the sample site.
If you need to install Laravel, you need to know what Laravel is, but let's start with a brief description.
Laravel:It is a completely open source web library that runs on PHP. Among its prominent features are security and facilitating the work of software developers.
LaravelIt is a PHP framework that has been offered to programmers and system developers with its easy, flexible structure and speed in the web application development life cycle with its own features.
There are structures in Laravel that we can easily perform functions related to session management, cache management and user authorization mechanisms. You must have guessed that many such mechanisms are built according to a specific architecture. Here also the model-view-controller (MVC) architecture in Laravel can be mentioned. Again, an open source library, in Java technologies in the 90s, in the Microsoft .Net platform in the 2000s, and in the MVC design model, we often hear about design patterns in general.Model: contains the design of the data on which the application runs. The design here is not a visual interface, but a database, etc. represents the plan.Controller: It is the model layer where the data resides and the layer that transports the functions performed by the user through the interfaces, receives and transmits the information and performs all the functions that come from the user.ViewOn the other hand, as we can guess, GUIs, template, table, button etc. which the user can see now. is the layer that contains all HTML objects.
Another thing I benefit from knowing before proceeding with the installation is the Composer Package Manager. Composer, which is one of the components we will install on our ubuntu server during installation. It will provide package management used in functions with PHP. In short, we can say that it is a solution to gather and facilitate the management of all the packages that we might use in our Laravel project.
Maybe we can look at the structure of Laravel, how it works, its history or different aspects from other libraries in a different article, but in this article, let's go into practice without going further into the theoretical knowledge.
Article Tag:
- Server version used: Ubuntu 22.04 LTS
- Web Server: Apache
- PHP version: Stable latest version
- Database: Mysql Community
- Laravel Package Manager : Composer
- Installing Laravel with Composer
Install Apache
First of all, to use our Laravel library, we need to install a web server on our server. I prefer Apache and after updating my server I install Apache with the command below.
root@laravel-server:# apt-get update && upgrade -y
root@laravel-server:# sudo apt install apache2
After the installation is complete, I check the status with the following command to see that the apache installation completed successfully.
root@laravel-server:# systemctl status apache2
PICTURE 1
After successfully installing Apache, if the firewall is going to be actively used on the server, we will need to add apache as a uwf rule. We add ufw the necessary permissions for apache as follows.
root@laravel-server:# ufw enable "Apache Full"
If ufw is disabled, you can skip the above command.
FIGURE-2
If there is no problem with the Apache installation, the default Apache page should be displayed when the server IP address is accessed from a browser on the server or on the same network. Since I tested the installation via the virtual machine on my desktop, I won't bother accessing through the browser and checking if the default Ubuntu page comes with Curl from the terminal. After I see the HTML codes coming, I see that the Apache installation is successful, I continue.
root@☺laravel-server:# curl 10.0.2.15
PHP installation
After installing Apache, we will install PHP and necessary components with the command below.
root@laravel-server:# sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip php-bcmath php-tokenizer php-pearson
We can check the version with the php -v command in the terminal to see if the installation is OK. If you see the php version as in the picture, no problem. Of course, there are many methods to confirm if the installation is smooth, but in some critical scenarios, it may be your choice to check if the php-related files are formed from the files in /etc/apache2/modules-available.
root@laravel-server:# php -v
FIGURE-3
Another common method we can do to make sure that PHP runs smoothly on our server and that the plugins that come with PHP install without problems is to create a phpinfo file in Apache's default directory (/var/www/html/) and call this file from the browser and check it. First, let's go to the relevant directory. Next, let's create the phpinfo.php file and insert the php code in which we can see the info information.
root@laravel-server:# cd /var/www/html/
root@laravel-server:# αγγίξτε phpinfo.php
root@laravel-server:# sudo vi phpinfo.php
FIGURE-4
In the editor we opened with vi, we enter the editing mode with the letter i. After writing the above phpinfo code, let's close it with +wq and restart our apache server.
root@laravel-server:# systemctl restart apache2
When we go to the server ip address/phpinfo.php from the browser, we can view the info page with information about PHP and its components.
NOTE: Since the risk is considered in the collection phase of the cybersecurity vulnerability analysis, delete the phpinfo.php file from the server after it is completed.
Install MYSQL
We installed Apache and then PHP on our server. As you are used to from the classic LAMP installation, MYSQL Server is next. We can install mysql with below command.
root@laravel-server:# apt-get install mysql-server
Ubuntu 20.04 doesn't ask us to create separate username and password in mysql installation in new versions like 22.04. It does not ask us for this information during installation. We will be able to access mysql with root user and server password. However, we will also create a separate user for mysql after installation.
After we have finished installing Mysql, let's check the status to see if it has been installed successfully.
root@laravel-server:# systemctl status mysql
FIGURE-5
Now let's go to the mysql shell and create a new user, we will use this user in the env file in laravel, so let's not continue with the root user. Let's use the following command to open the user to localhost access. We can continue with the root information when logging into mysql.
root@laravel-server:# mysql -u root -p
mysql> CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'localhost' WITH GRANT OPTION.
mysql> PRIVILEGE FLUSH.
Let's not forget that we have to put a question mark (?) at the end of every command while performing operations in MySql Shell.
Considering that the same user can access mysql remotely with the localhost access command above, let's create a remote user now.
mysql> CREATE USER 'dbuser'@'%' IDENTIFIED BY 'passcode';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'dbuser'@'%' WITH GRANT OPTION.
mysql> PRIVILEGE FLUSH.
After this stage, we made our mysql user accessible both internally and externally. These users are written in the user table in mysql database, now let's run the following command to see our users.
mysql> show databases.
FIGURE-6
To continue using the mysql database:
mysql> use mysql.
To view the tables in the mysql database:
mysql> show tables.
The classic opt-in question to engage our users:
mysql> select user, host from user;
FIGURE-7
Exit MySql Shell screen. We can go with After doing the basic exercises for MySql, we can now proceed to install Composer.
Composer installation
root@laravel-server:# curl -sS https://getcomposer.org/installer | php
The above command will install the composer component manager on our server. The following command is required to run composer from anywhere in ubuntu.
root@laravel-server:# mv composer.phar /usr/local/bin/composer
Let's give the necessary permissions that allow access from anywhere on the server.
root@laravel-server:# chmod +x /usr/local/bin/composer
Install Laravel
We can now complete the Laravel installation.
root@laravel-server:# composer create-project --prefer-dist laravel/laravel Το FirstLaravelProject μου
With the above command, we create a Laravel project environment named My FirstLaravelProject. This process may take some time.
Now we can specify our IP and Port with the following command to see the default Laravel screen, but that won't add anything to us for now. The default Laravel screen will call "My First LaravelProject". However, we aim to complete the installation and publish a real application in Laravel. So after this section it includes functions like publish, disable default apache configuration file, enable laravel configuration file.
Now let's go to the directory named "My FirstLaravelProject" and see the default page by assigning ip port.
Note: With pwd we can see which directory we are in.
root@laravel-server:# cd My FirstLaravelProject
root@laravel-server:# php artisan serve --host=10.0.2.15 --port=8000
FIGURE-8
After viewing the default (blank) Laravel page from our browser, we can now proceed to publish a real project with Laravel. For this, first, let's get the project file we created above to the directory where the apache web server is running.
root@laravel-server:# mv My FirstLaravelProject /var/www/html/
Next, let's give the necessary permissions to this folder to run smoothly.
root@laravel-server:# chgrp -R www-data /var/www/html/My FirstLaravelProject/
root@laravel-server:# chmod -R 775 /var/www/html/My FirstLaravelProject/storage
Just like when managing classic Apache or Nginx, when a new website is included or if it is necessary to create a virtual host in the first installation, we need to create a virtual host configuration file for Laravel.
Let's open the config file we will create with the vi editor, enter the following virtual host configuration, save and exit. You can add the same for 443 SSL. This is exactly the same with Apache and Nginx. The SSL file path should also not be forgotten.
root@laravel-server:# cd /etc/apache2/sites-available
root@laravel-server:# vi laravel_virtual.conf
ServerName domain.com ServerAdmin web@domain.com DocumentRoot /var/www/html/My FirstLaravelProje/public AllowOverride All ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log συνδυασμένο
We now have a configuration file that will allow Laravel to respond via Apache, but since Apache is still reading the default (000-default.conf) virtual file, we need to disable it as I mentioned earlier and tell it to read the above file configuration.
root@laravel-server:# a2dissite 000-default.conf
Let's activate the new file.
root@laravel-server:# a2ensite laravel_virtual
Now let's restart the Apache rewrite module and then restart apache2 for all these changes to take effect.
root@laravel-server:# a2enmod rewrite
root@laravel-server:# systemctl restart apache2
Yes, if you have made it this far without making mistakes and keeping logic in your head, it means you have published your first laravel project. Now, since Apache will read the file that laravel points to as the virtual host file, any laravel project located in the DocumentRoot and Directory field on the virtual host will be able to run. That is, we gave access to port 8000 to see the Default Laravel screen in the previous parts, it's not necessary, it's like publishing a site in classic apache or nginx.
As long as the index.php file in My First LaravelProject sees VirtualHost as DocumentRoot and the config in VirtualHost sees LaravelProject as Directory, it will work fine. Database functions and mail functions etc. In order for the add-ons to run smoothly, the env file in My First LaravelProject should be arranged according to you. This article does not cover the database creation and env file editing phase.
Your questions about this topicYou can ask using the comment field at the bottom.
BIBLIOGRAPHICAL REFERENCES
www.mshowto.org
labels: Laravel, php, mysql, ubuntu, ubuntu 22, php 8, mysql-server, mvc, composer, Laravel Installation
FAQs
How to install laravel in Ubuntu 22.04 step by step? ›
- 1: System update.
- Install LAMP on Ubuntu 22.04.
- Secure MySQL and create a Database.
- Install PHP Composer for Laravel.
- Download the Laravel framework project.
- Install Laravel on Ubuntu 22.04.
- Create the Laravel environment configuration file.
- Introduce. ...
- Step 1: Install Apache web server on Ubuntu. ...
- Step 2: Install PHP and additional PHP extensions. ...
- Step 3: Create Database for Laravel Application. ...
- Step 4: Install Composer. ...
- Step 5: Install Laravel on Ubuntu. ...
- Step 6: Configure Apache to serve the Laravel site.
- Step 1: Update the System Repositories.
- Step 2: Install and Configure apache2 Web Server.
- Step 3: Create and Configure a Database for Laravel.
- Step 4: Install PHP With Essential Dependencies.
- Step 5: Install Composer.
- Step 6: Install Laravel.
- Install Apache Web Server. For Laravel to work, you'll need Apache. ...
- Install PHP. The next step is to install PHP. ...
- Download and Install a Database Manager. ...
- Install Composer. ...
- Install Laravel on Ubuntu Using Composer.
- Step 1 - Boot Ubuntu ISO. ...
- Step 2 - Choose Language for Ubuntu Installer. ...
- Step 3 - Keyboard Configuration. ...
- Step 4 - Choose Type of Install. ...
- Step 5 - Configure Network Connections. ...
- Step 6 - Configure Proxy. ...
- Step 7 - Configure Ubuntu Archive Mirror. ...
- Step 8 - Update Installer (Optional)
- Via Laravel Installer. First, download the Laravel installer using Composer: ...
- Via Composer Create-Project. ...
- Local Development Server. ...
- Public Directory. ...
- Configuration Files. ...
- Directory Permissions. ...
- Application Key. ...
- Additional Configuration.
To install release 11 of OpenJDK, use the command sudo apt-get install openjdk-11-jdk . Use sudo apt-get install openjdk-18-jdk to install release 18. To see all available editions of OpenJDK, search the apt libraries using the apt-cache search openjdk command.
How to install mysql for laravel in Ubuntu? ›- Step 1: Install Apache web server: ...
- Step 2: Install PHP and additional PHP extensions: ...
- Step 3: Create Database for Laravel Application: ...
- Step 4: Install Composer: ...
- Step 5: Install Laravel 8 on Ubuntu:
- Step 1 – Installing PHP Modules. Before installing Laravel, we need some important PHP modules for the framework. ...
- Step 2 – Creating a Database for the Application. ...
- Step 3 – Creating a New Laravel App. ...
- Step 4 – Laravel Configuration. ...
- Step 5 – Setting up Nginx. ...
- Step 6 – Customizing the Main Page.
- Step 1: Install Laravel. composer global require "laravel/installer"
- Step 2: Add composer to path to access laravel globally. ...
- Step 3: Create a new Laravel application. ...
- Step 4: Install missing packages and their dependencies. ...
- Step 5: Test the application. ...
- Step 6: Stop server.
How to install phpMyAdmin in Ubuntu 22.04 using terminal? ›
- phpMyAdmin Requirements. ...
- Update Ubuntu 22.04 Server. ...
- Install the LAMP server. ...
- Install phpMyAdmin on Ubuntu 22.04. ...
- Add Blowfish cipher string. ...
- Create Apache Vhost configuration file. ...
- Access the phpMyAdmin web interface.
- Start off by updating the apt package index and installing the tasksel tool with these Linux commands. ...
- Next, select the GUI you wish to install. ...
- Once you have selected the GUI you wish to install on Ubuntu, execute the following tasksel command.
- Step 1: Install Apache web server. ...
- Step 2: Install PHP and additional PHP extensions. ...
- Step 3: Create Database for Laravel Application. ...
- Step 4: Install Composer. ...
- Step 5: Install Laravel 8 on Ubuntu. ...
- Step 6: Configure Apache to serve Laravel site. ...
- Step 7: Access Laravel from a browser.
Open the command line terminal on your system. Navigate to your Laravel application directory. Then execute the following PHP artisan command to check the Laravel version. The above output shows that you are running Laravel Framework 7.17.
How to run PHP Artisan command in Ubuntu? ›- Login to ubuntu machine using putty or any other ssh client.
- Run command: sudo -s.
- Run command: cd /opt/lamp/htdocs/<Laravel project directory name>
- Run command: sudo vi start-laravel-project-name-queue.sh.
- Click “i” for insert mode.
Ubuntu 22.04.2 LTS
2 GHz dual-core processor or better. 4 GB system memory. 25 GB of free hard drive space.
- Download Unetbootin from here.
- Run Unetbootin.
- Now, from the drop-down menu under Type: select Hard Disk.
- Next select the Diskimage. ...
- Press OK.
- Next when you reboot, you will get a menu like this:
- Download an Ubuntu Image. You can download an Ubuntu image here. ...
- Create a Bootable USB stick. ...
- Boot from USB flash drive. ...
- Installation Setup. ...
- Type of installation. ...
- Ready to install. ...
- Choose your Location. ...
- Create Your Login Details.
- PHP >= 5.4, PHP < 7.
- Mcrypt PHP Extension.
- OpenSSL PHP Extension.
- Mbstring PHP Extension.
- Tokenizer PHP Extension.
Install Laravel
Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravel command in your terminal. Once installed, the simple laravel new command will create a fresh Laravel installation in the directory you specify.
How to install Laravel 9 step by step? ›
- Sign up or log in to the Cloudways Platform.
- Click Launch Now to add a new server.
- Select your server and application.
- Choose the Laravel server size as per your website traffic.
- Select your Server Location according to your preferred region.
- Access to a user account with sudo or root privileges. ...
- Install Git from the default Ubuntu repository by running: sudo apt install git.
- Allow the process to complete. ...
- The output states the program version if it has been installed correctly.
- Apt update cache. ...
- Command to install sudo on Debian or Ubuntu server. ...
- Create a new user. ...
- Add a new user to the sudo group in Debian. ...
- Switch to new user.
- Open the terminal (Ctrl+Alt+T) and update the package repository to ensure you download the latest software version: sudo apt update.
- Then, you can confidently install the latest Java Development Kit with the following command: sudo apt install default-jdk.
The Laravel framework has a few system requirements: PHP >= 5.4, PHP < 7. Mcrypt PHP Extension. OpenSSL PHP Extension.
What PHP extensions are required for Laravel? ›The Laravel server requirements specify the PHP extensions, including BCMath , Ctype , cURL , DOM , Fileinfo , JSON , Mbstring , OpenSSL , PCRE , PDO , Tokenizer , and XML , are required. These extensions are usually included and enabled during a PHP installation.
How to install PHP 8 Laravel on Ubuntu? ›- Step 1: Update System Dependencies.
- Step 2: Add PHP PPA.
- Step 3: Install PHP 8. x for Apache.
- Step 4: Install PHP 8. x Extensions.
- Step 5: Verify PHP Version.
- Step 6: Configure PHP 8. x.
- Step 7: Conclusion.
- PHP >= 7.3.
- BCMath PHP Extension.
- Ctype PHP Extension.
- Fileinfo PHP Extension.
- JSON PHP Extension.
- Mbstring PHP Extension sudo apt-get install php-mbstring.
- OpenSSL PHP Extension.
- PDO PHP Extension.
- Via Laravel Installer. First, download the Laravel installer using Composer: ...
- Via Composer Create-Project. ...
- Local Development Server. ...
- Public Directory. ...
- Configuration Files. ...
- Directory Permissions. ...
- Application Key. ...
- Additional Configuration.
- Install PHP 8.2: sudo apt install php8.2.
- Install PHP 8.1: sudo apt install php8.1.
- Install PHP 7.4: sudo apt install php7.4.
- Install PHP 5.6 (EOL): sudo apt install php5.6.
How to install all php packages in Ubuntu? ›
- Install the tool with apt-get and pecl: sudo apt-get update sudo ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev sudo pecl install sqlsrv sudo pecl install pdo_sqlsrv.
- Edit the /opt/bitnami/php/etc/php.ini file and add the lines below to it: extension=sqlsrv.so extension=pdo_sqlsrv.so.
- Install the Apache2 HTTP server, the PHP5 engine, the MySQL 5.0 database server, and the PHP5-MySQL module. ...
- Specify the Document Root for the Apache2 HTTP server.
- Configure the MySQL database server.
- Install and enable the XDebug 2.0 debugger.
If you already have laravel/installer required globally on your local machine, you can update the latest version of laravel/installer with any of the following approaches: Update to ^4.0 via composer require. Uninstall and re-install the package via Composer. Update the global composer.
How to install PHP in Ubuntu 20.04 using terminal? ›- Install a few dependencies required by this tutorial with the below-mentioned command: sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https.
- Add the Ondrej PPA to your system, which contains all versions of PHP packages for the Ubuntu systems.
- Step 1: Download the Installation Media.
- Step 2: Create Bootable USB. Option 1: Make a Bootable USB Drive on Ubuntu. Option 2: Make a Bootable USB Drive on Windows.
- Step 3: Boot up Ubuntu from the USB.
- Step 4: Try Ubuntu.
- Step 5: Install Ubuntu 22.04 LTS Desktop. Choose Keyboard Layout. Choose Updates and Starting Applications.
- Step-1: Download the latest Ubuntu 22.04.
- Step-2: Bootable DVD/USB.
- Step-3: Start the Ubuntu 22.04 LTS Installation.
- Step-4: Keyboard Layout.
- Step-5: Updates And Other Software.
- Step-6: Installation Type.
- Step-7: Choose Location/Region.
- Step-8: User creation and host name settings.
- Check the installed release . ...
- Since using SSH port 22, select another free port to connect for updating the server. ...
- Install update-manger-core . ...
- Start the update to ubuntu 22 now. ...
- The update tool will calculate all the changes and provide a summary.
- Via Laravel Installer. First, download the Laravel installer using Composer: ...
- Via Composer Create-Project. ...
- Local Development Server. ...
- Public Directory. ...
- Configuration Files. ...
- Directory Permissions. ...
- Application Key. ...
- Additional Configuration.
- Download the installer to the current directory.
- Verify the installer SHA-384 which you can also cross-check here.
- Run the installer.
- Remove the installer.
- Open the terminal prompt and then type the following commands.
- Login to the remote server using the ssh command. ...
- To check PHP version, run: php --version OR php-cgi --version.
- To print PHP 7 version, type: php7 --version OR php7-cgi --version.
How to check if dependency is installed Ubuntu? ›
The dpkg-query command can be used to show if a specific package is installed in your system. To do it, run dpkg-query followed by the -l flag and the name of the package you want information about.
How to deploy php code in Ubuntu? ›- sudo apt-get install php5-curl apache2 libapache2-mod-php5. ...
- extension=/usr/lib/php5/20121212/dbr.so. ...
- sudo chgrp -R www-data /var/www/html/reader sudo chmod -R g+rw /var/www/html/reader. ...
- sudo service apache2 start #sudo service apache2 stop // if you want to stop Apache.
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component. To view a list of all available Artisan commands, you may use the list command: php artisan list.
How to enable php module in Ubuntu? ›Enabling PHP Modules
Use phpenmod command followed by module name to enable specific PHP module on your system. In the below example, the first command is an example and the second command will enable mbstring module for all installed PHP versions and all SAPI.
- Install Apache Web Server. For Laravel to work, you'll need Apache. ...
- Install PHP. The next step is to install PHP. ...
- Download and Install a Database Manager. ...
- Install Composer. ...
- Install Laravel on Ubuntu Using Composer.
- Prerequisites.
- Deploy Laravel application with Apache on Ubuntu. Log-In via SSH. Windows Install SSH Client. Linux and Mac. Logging Into Our Server. Update the Package Installer. Install Apache. Install MySQL. Secure MySQL. Install PHP. Configure PHP. ...
- What Next?
- Conclusion.
- Step 1: Add PPA for PHP 8.1. ...
- Step 2: Install PHP 8.1 FPM. ...
- Step 3: Install Apache. ...
- Step 4: Configure Apache with PHP-FPM. ...
- Step 6: Configure Apache Virtual Hosts. ...
- Step 7: Verify PHP-FPM with Apache.
- Step 1: Install Laravel. composer global require "laravel/installer"
- Step 2: Add composer to path to access laravel globally. ...
- Step 3: Create a new Laravel application. ...
- Step 4: Install missing packages and their dependencies. ...
- Step 5: Test the application. ...
- Step 6: Stop server.
- Installing Apache. To install Apache, install the latest meta-package apache2 by running: sudo apt update sudo apt install apache2. ...
- Creating Your Own Website. By default, Apache comes with a basic site (the one that we saw in the previous step) enabled. ...
- Setting up the VirtualHost Configuration File.
- Install or enable PHP's curl extension. sudo apt install phpy-curl.
- Install or enable PHP's simplexml extension. sudo apt install php-xml.
- Install or enable PHP's gd extension. sudo apt-get install php-gd.
- Install or enable PHP's zip extension. sudo apt install php-zip.
How to check PHP install in Ubuntu? ›
- Open the terminal prompt and then type the following commands.
- Login to the remote server using the ssh command. ...
- To check PHP version, run: php --version OR php-cgi --version.
- To print PHP 7 version, type: php7 --version OR php7-cgi --version.