<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Eldaniz Babayev</title>
    <description>The latest articles on DEV Community by Eldaniz Babayev (@eldaniz).</description>
    <link>https://dev.to/eldaniz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F632745%2Fac7f0188-9476-468f-9591-91f01a93435a.jpg</url>
      <title>DEV Community: Eldaniz Babayev</title>
      <link>https://dev.to/eldaniz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/eldaniz"/>
    <language>en</language>
    <item>
      <title>How To Install LAMP stack on Ubuntu</title>
      <dc:creator>Eldaniz Babayev</dc:creator>
      <pubDate>Mon, 17 May 2021 12:09:37 +0000</pubDate>
      <link>https://dev.to/eldaniz/how-to-install-lamp-stack-on-ubuntu-20na</link>
      <guid>https://dev.to/eldaniz/how-to-install-lamp-stack-on-ubuntu-20na</guid>
      <description>&lt;p&gt;&lt;strong&gt;Operating System: Ubuntu 20.04&lt;br&gt;
Kernel Version: 5.8.0-48-generic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To use PHP as your local server, you have to install the &lt;strong&gt;LAMP&lt;/strong&gt; stack first. Also, there is XAMPP, I'll use LAMP to show the pure server-side in Linux. Firstly, you have to install Apache2 with dpkg package management system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the installation is finished, you have to update your firewall settings to allow &lt;code&gt;HTTP(HyperText Transfer Protocol)&lt;/code&gt; traffic. &lt;code&gt;UFW(Uncomplicated Firewall)&lt;/code&gt; has different application profiles that you can leverage for accomplishing that. To list all currently available &lt;code&gt;UFW&lt;/code&gt; application profiles, you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw app list

Output:
Available applications:
  Apache
  Apache Full
  Apache Secure
  CUPS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To only allow traffic on port &lt;code&gt;80&lt;/code&gt;, use the &lt;code&gt;Apache&lt;/code&gt; profile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo ufw allow in "Apache"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completing these steps, you can check out your localhost or &lt;a href="http://127.0.1.1/" rel="noopener noreferrer"&gt;localhost ip&lt;/a&gt; if it's working or not. You should see that page:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fns7737vjllqm23uavybq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fns7737vjllqm23uavybq.png" alt="image"&gt;&lt;/a&gt;&lt;br&gt;
If you see this page, then your web server is now correctly installed and accessible through your firewall.&lt;/p&gt;

&lt;p&gt;Now our web server is running and we have to set up our database. In general M in LAMP stand on &lt;code&gt;MySQL&lt;/code&gt;, but I'll use &lt;code&gt;MariaDB&lt;/code&gt; as my database. You can check out that &lt;a href="https://mariadb.com/kb/en/function-differences-between-mariadb-and-mysql/" rel="noopener noreferrer"&gt;link&lt;/a&gt; to look at function differences between MariaDB and MySQL.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install mariadb-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands will install MariaDB, but will not prompt you to set a password or make any other configuration changes. Because the default configuration leaves your installation of MariaDB insecure, we will use a script that the &lt;code&gt;mariadb-server&lt;/code&gt; package provides to restrict access to the server and remove unused accounts. For new MariaDB installations, the next step is to run the included security script. This script changes some of the less secure default options for things like remote root logins and sample users.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mysql_secure_installation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first prompt will ask you to enter the current database root password. Since you have not set one up yet, press &lt;code&gt;ENTER&lt;/code&gt; to indicate &lt;code&gt;none&lt;/code&gt;. You should see something like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! 
PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next prompt asks you whether you’d like to set up a database root password. On Ubuntu, the root account for &lt;code&gt;MariaDB&lt;/code&gt; is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Type &lt;code&gt;N&lt;/code&gt; and then press &lt;code&gt;ENTER&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.
Set root password? [Y/n] N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On Ubuntu systems running MariaDB 10.5.9, the root MariaDB user is set to authenticate using the unix_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (for example: phpMyAdmin) administrative rights.&lt;/p&gt;

&lt;p&gt;To this end, we will create a new account called admin with the same capabilities as the root account, but configured for password authentication. Open up the MariaDB prompt from your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mariadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After completed step in the above, you can create a new user with root privileges and password-based access. Be sure to change the username and password to match your preferences:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MariaDB [(none)]&amp;gt; GRANT ALL ON *.* TO 'eldaniz'@'localhost' IDENTIFIED BY 'admin123' WITH GRANT OPTION;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flush the privileges to be aware that they are saved and available in the current session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MariaDB [(none)]&amp;gt; FLUSH PRIVILEGES;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For testing mariadb is working or not, you should write that command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo systemctl status mariadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output of that command should be like that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;● mariadb.service - MariaDB 10.5.9 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese&amp;gt;
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Sun 2021-04-11 12:30:47 +04; 4h 28min ago
       Docs: man:mariadbd(8)
             &amp;lt;https://mariadb.com/kb/en/library/systemd/&amp;gt;
    Process: 742 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/&amp;gt;
    Process: 776 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STA&amp;gt;
    Process: 783 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] &amp;amp;&amp;amp; V&amp;gt;
    Process: 1063 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_S&amp;gt;
    Process: 1071 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/&amp;gt;
   Main PID: 881 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 9 (limit: 4513)
     Memory: 74.4M
     CGroup: /system.slice/mariadb.service
             └─881 /usr/sbin/mariadbd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If mariadb is not running, you can start it with &lt;br&gt;
&lt;code&gt;sudo systemctl start mariadb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can try connecting to the database using the &lt;code&gt;mysqladmin&lt;/code&gt; tool, which is a client that lets you run administrative commands. For example, this command says to connect to MariaDB as &lt;strong&gt;root&lt;/strong&gt; using the Unix socket and return the version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo mysqladmin version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will receive output similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mysqladmin  Ver 9.1 Distrib 10.5.9-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Server version      10.5.9-MariaDB-1:10.5.9+maria~focal
Protocol version    10
Connection      Localhost via UNIX socket
UNIX socket     /run/mysqld/mysqld.sock
Uptime:         4 hours 30 min 23 sec
Threads: 1  Questions: 58  Slow queries: 0  Opens: 32  Open tables: 25  Queries per second avg: 0.003
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last step of our LAMP stack is the PHP. We have to use dpkg package controller to install php7.4 and it’s dependencies on Ubuntu:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install php7.4 php7.4-cli php7.4-common php7.4-json php7.4-mysql php7.4-mbstring php7.4-mcrypt php7.4-zip php7.4-fpm libapache2-mod-php7.4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can check if php is working or not with that command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output should be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PHP 7.4.16 (cli) (built: May  17 2021 07:54:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.16, Copyright (c), by Zend Technologies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Thanks for reading, You can connect with me:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/eldaniiz" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/in/eldaniiz" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ubuntu</category>
      <category>php</category>
      <category>linux</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
