Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
deploy_laravel_application_on_a_linux_vds [2025/05/13 07:47] – [Step 2: Run the Secure Installation Script] kkaragozdeploy_laravel_application_on_a_linux_vds [2025/05/13 07:48] (current) kkaragoz
Line 119: Line 119:
  
 Once these DNS records are pointing to your server's IP address, you will configure your web server (Nginx) in the next section to respond to requests for these domain names. Once these DNS records are pointing to your server's IP address, you will configure your web server (Nginx) in the next section to respond to requests for these domain names.
- 
 ===== 4- Nginx Installation & Configuration ===== ===== 4- Nginx Installation & Configuration =====
 [[https://nginx.org|nginx]] ("engine x") is an HTTP web server, reverse proxy, content cache, load balancer, TCP/UDP proxy server, and mail proxy server. Before nginx installation we should be ensure about apache/apache2 is not running and enabled. [[https://nginx.org|nginx]] ("engine x") is an HTTP web server, reverse proxy, content cache, load balancer, TCP/UDP proxy server, and mail proxy server. Before nginx installation we should be ensure about apache/apache2 is not running and enabled.
Line 383: Line 382:
 Now, try accessing your ''%%domain.xyz%%'' site to see the expected page that you can prepared. Now, try accessing your ''%%domain.xyz%%'' site to see the expected page that you can prepared.
  
-===== 7- Database Installation (MariaDB) ===== +===== 7- MySQL Installation ===== 
-For your Laravel application, you will need a database server. We will install MariaDB, which is the default database system in Debian 12 and a popular, community-developed fork of MySQL. [[https://www.debian.org/releases/bookworm/amd64/release-notes/ch-whats-new.en.html|Debian 12 Release Notes]], [[https://mariadb.org/about/standards/mysql-compatibility/|MariaDB MySQL Compatibility]], [[https://wiki.debian.org/MariaDB|Debian Wiki: MariaDB]] +For installing MariaDB, you can follow the instructions given [[https://mariadb.org/download/?t=repo-config&d=Debian+12+%22Bookworm%22&v=11.4&r_m=agdsn|on their page]]. Select your operating system and follow the instructionsHere is the brief installation guide.
- +
-==== Step 1: Install MariaDB Server ==== +
-You can install the MariaDB server and client packages directly from the Debian 12 repositoriesThis will typically install MariaDB version 10.11. [[https://www.debian.org/releases/bookworm/amd64/release-notes/ch-whats-new.en.html|Debian 12 Release Notes]], [[https://packages.debian.org/bookworm/mariadb-server|Debian Packages: mariadb-server]]+
  
 +==== Step 1: Install MariaDB ====
 +With the given command, you will be able to access MySQL.
 <code bash> <code bash>
-sudo apt update +sudo apt-get update 
-sudo apt install mariadb-server mariadb-client -y+sudo apt-get install mariadb-server
 </code> </code>
-The ''%%-y%%'' flag automatically confirms prompts during installation. +After installation you should run the ''%%mysql_secure_installation%%''
- +
-==== Step 2: Run the Secure Installation Script ==== +
-After installation, it is crucial to run the ''%%mysql_secure_installation%%'' script to improve the security of your MariaDB installation by setting a root password, removing anonymous users, disallowing remote root login, and removing the test database.+
  
 +==== Step 2: MySQL Secure Installation ====
 +Run the following command:
 <code bash> <code bash>
 sudo mysql_secure_installation sudo mysql_secure_installation
 </code> </code>
-The script will guide you through several prompts: +It will ask you for ''%%root%%'' password
- +
-*   **Enter current password for root (enter for none):** If this is a fresh installation and you haven't set a MariaDB root password yet, just press ''%%Enter%%''.+
 <code bash> <code bash>
 In order to log into MariaDB to secure it, we'll need the current In order to log into MariaDB to secure it, we'll need the current
Line 412: Line 407:
 # Press Enter # Press Enter
 </code> </code>
-*   **Set root password? [Y/n]:** Type ''%%Y%%'' and press ''%%Enter%%'' to set a strong password for the MariaDB root user. Enter the password when prompted+ 
-    <code bash>+Then maybe after some questions, it will ask you for setting a new ''%%root%%'' password.  
 +<code bash>
 Change the root password? [Y/n] Y Change the root password? [Y/n] Y
-New password: # Enter a Strong Root Password+New password: # Enter a New Root Password
 Re-enter new password: # Enter Again the New Root Password Re-enter new password: # Enter Again the New Root Password
 Password updated successfully! Password updated successfully!
-    </code> +</code>
-*   Follow the remaining prompts, pressing ''%%Y%%'' and ''%%Enter%%'' for each to remove anonymous users, disallow root login remotely, and remove the test database.+
  
-When you see the message "All done!", your MariaDB installation should be more secure.+Then when you see the following message, it means the installation of MySQL is done and ready to go: 
 +<code bash> 
 +All done!  If you've completed all of the above steps, your MariaDB 
 +installation should now be secure.
  
-==== Step 3: Log in to MariaDB ==== +Thanks for using MariaDB! 
-You can log in to the MariaDB command-line interface as the ''%%root%%'' user using ''%%sudo%%'', as the system's ''%%root%%'' user has privileges to manage the database by default after secure installation.+</code>
  
 +==== Step 3: Create a User ====
 +Let's enter into the MySQL engine with the following command:
 <code bash> <code bash>
-sudo mariadb+sudo mysql -u root -p<ENTER_ROOT_PASSWORD>
 </code> </code>
-You can also log in using the ''%%root%%'' password you just set+Now we need to create a user
-<code bash+<code mysql
-mariadb -u root -p +CREATE USER 'USER_NAME'@'localhost' IDENTIFIED BY 'PASSWORD';
-# Enter the root password when prompted+
 </code> </code>
  
-To exit the MariaDB prompt, type ''%%exit;%%'' and press ''%%Enter%%''+After creating the user you can control the user from the following table:
- +
-==== Step 4: Create a Database and User for your Laravel Application ==== +
-Now, let's create a dedicated database and user for your Laravel application. This is more secure than using the ''%%root%%'' user for your application. +
- +
-Log back into the MariaDB prompt (e.g., using ''%%sudo mariadb%%''). +
- +
-Create the database. You can replace ''%%laravel_db%%'' with a name of your choice.+
 <code mysql> <code mysql>
-CREATE DATABASE laravel_db;+SHOW DATABASES; 
 +USE mysql; 
 +SHOW TABLES; 
 +SELECT * FROM user;
 </code> </code>
 +Then it will display the users. Now the next step is creating a new database for the Laravel project and set grant privileges to the user that we created on the database.
  
-Create a new user and set a strong password. Replace ''%%your_laravel_user%%'' and ''%%your_strong_password%%'' with your desired username and password. The ''%%'localhost'%%' part means this user can only connect from the server itself, which is standard for web applications on the same server.+==== Step 4: Create a New Database ====
 <code mysql> <code mysql>
-CREATE USER 'your_laravel_user'@'localhost' IDENTIFIED BY 'your_strong_password';+CREATE DATABASE laravel_db
 </code> </code>
 +You can change the database name however you want. For the tutorial I set the name as ''%%laravel_db%%''.
  
-Grant the new user full privileges on the database you just created.+==== Step 5: Grant Privileges ==== 
 +Now we should set grant privileges to user on the ''%%laravel_db%%'' database.
 <code mysql> <code mysql>
-GRANT ALL PRIVILEGES ON `laravel_db`.* TO 'your_laravel_user'@'localhost';+GRANT ALL PRIVILEGES ON `laravel_db`.* TO 'USER_NAME'@'localhost';
 </code> </code>
- +It's good practice to flush the privileges to ensure the changes take effect immediately without needing to restart the MySQL server.
-Apply the privilege changes immediately:+
 <code mysql> <code mysql>
 FLUSH PRIVILEGES; FLUSH PRIVILEGES;
 </code> </code>
- +Now, if you get Query OK message, it's time to exit.
-Exit the MariaDB prompt:+
 <code mysql> <code mysql>
 exit; exit;
 </code> </code>
  
-==== Step 5Verify MariaDB Service Status ==== +==== Step 6MySQL Service Chech ==== 
-On Debian, the MariaDB service is typically named ''%%mariadb.service%%''. You can check its status and ensure it's running and enabled to start automatically on boot. [[https://packages.debian.org/bookworm/mariadb-server|Debian Packages: mariadb-server]] +Now it is time to check the service:
 <code bash> <code bash>
-sudo systemctl status mariadb.service+sudo systemctl status mysql 
 +sudo systemctl status mariadb
 </code> </code>
-It should show as ''%%active (running)%%''If not, or if you need to ensure it starts on boot:+ 
 +If they are not activated and enabledwe should do:
 <code bash> <code bash>
-sudo systemctl enable mariadb.service +sudo systemctl enable mysql 
-sudo systemctl start mariadb.service+sudo systemctl start mysql 
 +sudo systemctl enable mariadb 
 +sudo systemctl start mariadb
 </code> </code>
- 
-**Next Steps:** Remember to update your Laravel application's ''%%.env%%'' file with the database name (''%%laravel_db%%''), username (''%%your_laravel_user%%''), and password (''%%your_strong_password%%'') you just created. You will do this in a later step when configuring the application. 
  
 ===== 8- Install Composer ===== ===== 8- Install Composer =====
Line 655: Line 652:
 php artisan migrate php artisan migrate
 </code> </code>
- 
Back to top