I Have to Open Xampp Again and Again From Terminal in Ubuntu 1404

Introduction

A "LAMP" stack is a grouping of open source software that is typically installed together in order to enable a server to host dynamic websites and spider web apps written in PHP. This term is an acronym which represents the Fiftyinux operating system, with the Apache spider web server. The site data is stored in a MySQL database, and dynamic content is processed by PHP.

In this guide, y'all'll fix a LAMP stack on an Ubuntu 20.04 server.

Prerequisites

In order to complete this tutorial, you will need to have an Ubuntu 20.04 server with a non-root sudo-enabled user account and a basic firewall. This tin be configured using our initial server setup guide for Ubuntu 20.04.

Step 1 — Installing Apache and Updating the Firewall

The Apache web server is amid the most popular web servers in the globe. Information technology's well documented, has an agile customs of users, and has been in wide use for much of the history of the spider web, which makes it a neat choice for hosting a website.

Outset past updating the parcel manager cache. If this is the first time y'all're using sudo inside this session, you'll exist prompted to provide your user's password to confirm you lot have the right privileges to manage system packages with apt.

                      
  1. sudo apt update

Then, install Apache with:

                      
  1. sudo apt install apache2

Y'all'll also be prompted to confirm Apache'due south installation past pressing Y, then ENTER.

Once the installation is finished, you'll need to adapt your firewall settings to allow HTTP traffic. UFW has different application profiles that you can leverage for accomplishing that. To list all currently available UFW application profiles, you tin can run:

                      
  1. sudo ufw app listing

You'll come across output like this:

                      

Output

Available applications: Apache Apache Full Apache Secure OpenSSH

Hither'due south what each of these profiles hateful:

  • Apache: This profile opens only port eighty (normal, unencrypted web traffic).
  • Apache Full: This profile opens both port eighty (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic).
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic).

For at present, it's best to allow simply connections on port eighty, since this is a fresh Apache installation and yous even so don't have a TLS/SSL certificate configured to allow for HTTPS traffic on your server.

To but allow traffic on port 80, use the Apache profile:

                      
  1. sudo ufw allow in "Apache"

Yous tin can verify the alter with:

                      
  1. sudo ufw status
                      

Output

Condition: active To Activeness From -- ------ ---- OpenSSH Allow Anywhere Apache ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) Apache (v6) ALLOW Anywhere (v6)

Traffic on port 80 is at present immune through the firewall.

Y'all tin do a spot bank check right abroad to verify that everything went equally planned by visiting your server's public IP address in your web browser (see the note nether the next heading to find out what your public IP address is if you exercise non take this information already):

          http://your_server_ip                  

You'll see the default Ubuntu twenty.04 Apache web page, which is there for advisory and testing purposes. Information technology should await something similar this:

Ubuntu 20.04 Apache default

If you see this folio, then your web server is now correctly installed and accessible through your firewall.

How To Discover your Server's Public IP Address

If you practise not know what your server's public IP accost is, there are a number of ways you can find it. Usually, this is the address you use to connect to your server through SSH.

There are a few dissimilar ways to do this from the command line. Commencement, you could use the iproute2 tools to get your IP accost past typing this:

                      
  1. ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

This volition give you two or 3 lines back. They are all correct addresses, only your figurer may only be able to employ one of them, then feel gratis to try each one.

An alternative method is to use the gyre utility to contact an outside political party to tell you how it sees your server. This is done by asking a specific server what your IP address is:

                      
  1. roll http://icanhazip.com

Regardless of the method y'all apply to become your IP address, type it into your web browser's address bar to view the default Apache folio.

Footstep 2 — Installing MySQL

Now that you have a web server up and running, you need to install the database system to be able to store and manage data for your site. MySQL is a popular database management arrangement used inside PHP environments.

Once more, use apt to acquire and install this software:

                      
  1. sudo apt install mysql-server

When prompted, confirm installation by typing Y, and and then ENTER.

When the installation is finished, it's recommended that y'all run a security script that comes pre-installed with MySQL. This script volition remove some insecure default settings and lock downward admission to your database arrangement. Commencement the interactive script by running:

                      
  1. sudo mysql_secure_installation

This volition ask if you want to configure the VALIDATE Countersign PLUGIN.

Notation: Enabling this characteristic is something of a judgment call. If enabled, passwords which don't match the specified criteria will be rejected by MySQL with an error. It is safe to leave validation disabled, but y'all should always employ strong, unique passwords for database credentials.

Reply Y for yep, or annihilation else to go along without enabling.

          VALIDATE PASSWORD PLUGIN can exist used to exam passwords and improve security. It checks the strength of password and allows the users to set up only those passwords which are secure enough. Would you like to setup VALIDATE Countersign plugin?  Printing y|Y for Yes, any other key for No:                  

If you respond "yes", you'll exist asked to select a level of password validation. Go on in mind that if you lot enter 2 for the strongest level, yous will receive errors when attempting to set whatever password which does not contain numbers, upper and lowercase letters, and special characters, or which is based on common dictionary words.

          There are three levels of password validation policy:  LOW    Length >= viii MEDIUM Length >= 8, numeric, mixed example, and special characters Stiff Length >= 8, numeric, mixed instance, special characters and lexicon              file  Please enter 0 = Low, 1 = MEDIUM and ii = STRONG:            i                  

Regardless of whether you chose to set up the VALIDATE Countersign PLUGIN, your server will next ask you to select and confirm a password for the MySQL root user. This is non to exist dislocated with the arrangement root. The database root user is an administrative user with total privileges over the database system. Fifty-fifty though the default authentication method for the MySQL root user dispenses the utilize of a password, even when one is set, you should define a strong password hither as an additional prophylactic measure. We'll talk about this in a moment.

If you enabled password validation, you'll be shown the password strength for the root password y'all but entered and your server will ask if y'all want to continue with that countersign. If yous are happy with your current password, enter Y for "aye" at the prompt:

          Estimated strength of the password:            100            Exercise you wish to keep with the password provided?(Press y|Y for Yes, any other fundamental for No) :            y                  

For the rest of the questions, press Y and hit the ENTER primal at each prompt. This will remove some anonymous users and the test database, disable remote root logins, and load these new rules so that MySQL immediately respects the changes you have made.

When you're finished, test if y'all're able to log in to the MySQL console by typing:

                      
  1. sudo mysql

This will connect to the MySQL server as the administrative database user root, which is inferred past the use of sudo when running this command. You should see output like this:

                      

Output

Welcome to the MySQL monitor. Commands cease with ; or \m. Your MySQL connectedness id is 22 Server version: 8.0.nineteen-0ubuntu5 (Ubuntu) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'aid;' or '\h' for help. Type '\c' to articulate the electric current input statement. mysql>

To exit the MySQL panel, type:

                      
  1. go out

Detect that you didn't need to provide a password to connect as the root user, even though you take divers 1 when running the mysql_secure_installation script. That is because the default hallmark method for the administrative MySQL user is unix_socket instead of password. Even though this might look like a security concern at first, it makes the database server more than secure because the merely users immune to log in equally the root MySQL user are the system users with sudo privileges connecting from the console or through an application running with the aforementioned privileges. In practical terms, that means you won't be able to utilise the authoritative database root user to connect from your PHP application. Setting a password for the root MySQL account works as a safeguard, in case the default hallmark method is inverse from unix_socket to countersign.

For increased security, it's best to have dedicated user accounts with less expansive privileges set upwardly for every database, particularly if you program on having multiple databases hosted on your server.

Notation: At the fourth dimension of this writing, the native MySQL PHP library mysqlnd doesn't support caching_sha2_authentication, the default authentication method for MySQL 8. For that reason, when creating database users for PHP applications on MySQL 8, you lot'll need to make sure they're configured to use mysql_native_password instead. We'll demonstrate how to do that in Footstep six.

Your MySQL server is at present installed and secured. Next, we'll install PHP, the final component in the LAMP stack.

Step 3 — Installing PHP

You have Apache installed to serve your content and MySQL installed to store and manage your data. PHP is the component of our setup that will procedure code to display dynamic content to the final user. In addition to the php parcel, you'll need php-mysql, a PHP module that allows PHP to communicate with MySQL-based databases. You'll also need libapache2-mod-php to enable Apache to handle PHP files. Core PHP packages will automatically be installed equally dependencies.

To install these packages, run:

                      
  1. sudo apt install php libapache2-mod-php php-mysql

Once the installation is finished, you can run the following control to confirm your PHP version:

                      
  1. php -v
                      

Output

PHP 7.iv.three (cli) (built: Jul v 2021 xv:thirteen:35) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.iv.3, Copyright (c), by Zend Technologies

At this point, your LAMP stack is fully operational, but before y'all can test your setup with a PHP script, it's best to prepare up a proper Apache Virtual Host to hold your website's files and folders. Nosotros'll do that in the next step.

Step iv — Creating a Virtual Host for your Website

When using the Apache spider web server, you tin create virtual hosts (like to server blocks in Nginx) to encapsulate configuration details and host more than i domain from a single server. In this guide, we'll set up a domain chosen your_domain, only you should replace this with your own domain name.

Note: In case you are using DigitalOcean as DNS hosting provider, you can check our product docs for detailed instructions on how to prepare a new domain name and signal it to your server.

Apache on Ubuntu 20.04 has one server cake enabled past default that is configured to serve documents from the /var/www/html directory. While this works well for a single site, it tin can become unwieldy if yous are hosting multiple sites. Instead of modifying /var/world wide web/html, we'll create a directory structure within /var/www for the your_domain site, leaving /var/www/html in place as the default directory to be served if a client asking doesn't friction match any other sites.

Create the directory for your_domain every bit follows:

                      
  1. sudo mkdir /var/world wide web/your_domain

Next, assign ownership of the directory with the $USER environment variable, which will reference your current arrangement user:

                      
  1. sudo chown -R $USER : $USER /var/www/your_domain

Then, open a new configuration file in Apache'due south sites-available directory using your preferred command-line editor. Here, nosotros'll utilise nano:

                      
  1. sudo nano /etc/apache2/sites-available/your_domain.conf

This will create a new bare file. Paste in the following bare-bones configuration:

/etc/apache2/sites-bachelor/your_domain.conf

          <VirtualHost *:80>     ServerName            your_domain            ServerAlias world wide web.your_domain            ServerAdmin webmaster@localhost     DocumentRoot /var/www/your_domain            ErrorLog ${APACHE_LOG_DIR}/error.log     CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>                  

Salvage and close the file when you lot're done. If y'all're using nano, you can do that past pressing CTRL+Ten, so Y and ENTER.

With this VirtualHost configuration, we're telling Apache to serve your_domain using /var/world wide web/your_domain equally the spider web root directory. If yous'd like to test Apache without a domain proper noun, you tin can remove or annotate out the options ServerName and ServerAlias by adding a # character in the outset of each pick'southward lines.

You lot can at present utilise a2ensite to enable the new virtual host:

                      
  1. sudo a2ensite your_domain

You might want to disable the default website that comes installed with Apache. This is required if you lot're non using a custom domain name, because in this case Apache'due south default configuration would overwrite your virtual host. To disable Apache'south default website, type:

                      
  1. sudo a2dissite 000-default

To make sure your configuration file doesn't contain syntax errors, run:

                      
  1. sudo apache2ctl configtest

Finally, reload Apache and so these changes take result:

                      
  1. sudo systemctl reload apache2

Your new website is now agile, merely the spider web root /var/www/your_domain is still empty. Create an index.html file there so that we tin can test that the virtual host works as expected:

                      
  1. nano /var/world wide web/your_domain/alphabetize.html

Include the following content in this file:

/var/www/your_domain/index.html

          <html>   <caput>     <title>your_domain            website</championship>   </head>   <body>     <h1>Howdy Earth!</h1>      <p>This is the landing folio of <strong>your_domain</strong>.</p>   </body> </html>                  

Now go to your browser and admission your server's domain proper noun or IP accost over again:

          http://server_domain_or_IP                  

Y'all'll see a page like this:

Apache virtual host test

If you see this page, it ways your Apache virtual host is working equally expected.

You can leave this file in place every bit a temporary landing page for your application until you set up an index.php file to replace information technology. In one case you exercise that, recall to remove or rename the index.html file from your document root, as it would take precedence over an index.php file by default.

A Note About DirectoryIndex on Apache

With the default DirectoryIndex settings on Apache, a file named index.html volition e'er take precedence over an index.php file. This is useful for setting upwardly maintenance pages in PHP applications, by creating a temporary index.html file containing an informative message to visitors. Because this page will take precedence over the alphabetize.php page, it will then go the landing page for the application. Once maintenance is over, the index.html is renamed or removed from the document root, bringing back the regular awarding page.

In case yous desire to modify this behavior, you'll need to edit the /etc/apache2/mods-enabled/dir.conf file and alter the order in which the alphabetize.php file is listed within the DirectoryIndex directive:

                      
  1. sudo nano /etc/apache2/mods-enabled/dir.conf

/etc/apache2/mods-enabled/dir.conf

          <IfModule mod_dir.c>         DirectoryIndex            index.php            index.html index.cgi alphabetize.pl index.xhtml index.htm </IfModule>                  

Afterwards saving and closing the file, you lot'll need to reload Apache so the changes accept effect:

                      
  1. sudo systemctl reload apache2

In the adjacent step, we'll create a PHP script to examination that PHP is correctly installed and configured on your server.

Stride v — Testing PHP Processing on your Spider web Server

Now that you have a custom location to host your website'south files and folders, we'll create a PHP test script to confirm that Apache is able to handle and process requests for PHP files.

Create a new file named info.php inside your custom web root binder:

                      
  1. nano /var/world wide web/your_domain/info.php

This volition open up a blank file. Add the following text, which is valid PHP lawmaking, inside the file:

/var/www/your_domain/info.php

                                    <?php              phpinfo              (              )              ;                              

When you are finished, relieve and shut the file.

To examination this script, become to your spider web browser and access your server's domain name or IP address, followed by the script name, which in this case is info.php:

          http://server_domain_or_IP/info.php                  

You'll see a page like to this:

Ubuntu 20.04 PHP info

This page provides information about your server from the perspective of PHP. Information technology is useful for debugging and to ensure that your settings are being applied correctly.

If you can come across this folio in your browser, then your PHP installation is working as expected.

After checking the relevant information most your PHP server through that page, it's all-time to remove the file you created as it contains sensitive data virtually your PHP environs and your Ubuntu server. Yous can use rm to exercise so:

                      
  1. sudo rm /var/www/your_domain/info.php

Y'all can always recreate this page if yous need to admission the information again later.

Step 6 — Testing Database Connection from PHP (Optional)

If you want to test whether PHP is able to connect to MySQL and execute database queries, you can create a examination table with dummy data and query for its contents from a PHP script. Earlier we can do that, we demand to create a test database and a new MySQL user properly configured to access it.

At the fourth dimension of this writing, the native MySQL PHP library mysqlnd doesn't back up caching_sha2_authentication, the default authentication method for MySQL 8. Nosotros'll need to create a new user with the mysql_native_password authentication method in order to exist able to connect to the MySQL database from PHP.

Nosotros'll create a database named example_database and a user named example_user, but you tin supplant these names with different values.

Showtime, connect to the MySQL console using the root account:

                      
  1. sudo mysql

To create a new database, run the post-obit control from your MySQL console:

                      
  1. CREATE DATABASE example_database ;

Now yous tin create a new user and grant them total privileges on the custom database you've merely created.

The following control creates a new user named example_user , using mysql_native_password as default authentication method. We're defining this user's password every bit countersign , just you lot should supervene upon this value with a secure password of your own choosing.

                      
  1. CREATE USER 'example_user'@'%' IDENTIFIED WITH mysql_native_password By 'countersign' ;

At present we need to give this user permission over the example_database database:

                      
  1. GRANT ALL ON example_database.* TO 'example_user'@'%' ;

This will give the example_user user full privileges over the example_database database, while preventing this user from creating or modifying other databases on your server.

At present exit the MySQL shell with:

                      
  1. exit

You lot can test if the new user has the proper permissions by logging in to the MySQL console again, this time using the custom user credentials:

                      
  1. mysql -u example_user -p

Notice the -p flag in this command, which will prompt y'all for the countersign used when creating the example_user user. Later logging in to the MySQL console, confirm that yous accept access to the example_database database:

                      
  1. SHOW DATABASES;

This will give you lot the following output:

                      

Output

+--------------------+ | Database | +--------------------+ | example_database | | information_schema | +--------------------+ 2 rows in gear up (0.000 sec)

Next, we'll create a test table named todo_list. From the MySQL console, run the following statement:

                      
  1. CREATE TABLE example_database.todo_list (
  2. item_id INT AUTO_INCREMENT,
  3. content VARCHAR( 255 ),
  4. Master KEY(item_id)
  5. ) ;

Insert a few rows of content in the test table. You might want to repeat the next command a few times, using unlike values:

                      
  1. INSERT INTO example_database.todo_list (content) VALUES ( "My first important item" ) ;

To confirm that the data was successfully saved to your tabular array, run:

                      
  1. SELECT * FROM example_database.todo_list ;

You lot'll run into the post-obit output:

                      

Output

+---------+--------------------------+ | item_id | content | +---------+--------------------------+ | one | My first important detail | | two | My second important detail | | 3 | My third important item | | 4 | and this 1 more affair | +---------+--------------------------+ 4 rows in set up (0.000 sec)

After confirming that you have valid data in your test table, yous can exit the MySQL console:

                      
  1. exit

Now you can create the PHP script that will connect to MySQL and query for your content. Create a new PHP file in your custom web root directory using your preferred editor. Nosotros'll use nano for that:

                      
  1. nano /var/www/your_domain/todo_list.php

The post-obit PHP script connects to the MySQL database and queries for the content of the todo_list tabular array, exhibiting the results in a list. If there's a problem with the database connectedness, it will throw an exception. Copy this content into your todo_list.php script:

/var/www/your_domain/todo_list.php

                                    <?php              $user              =              "example_user"              ;              $password              =              "password"              ;              $database              =              "example_database"              ;              $table              =              "todo_list"              ;              try              {              $db              =              new              PDO              (              "mysql:host=localhost;dbname=                  $database                "              ,              $user              ,              $password              )              ;              echo              "<h2>TODO</h2><ol>"              ;              foreach              (              $db              ->              query              (              "SELECT content FROM                                  $tabular array                "              )              every bit              $row              )              {              echo              "<li>"              .              $row              [              'content'              ]              .              "</li>"              ;              }              repeat              "</ol>"              ;              }              catch              (              PDOException              $e              )              {              impress              "Error!: "              .              $e              ->              getMessage              (              )              .              "<br/>"              ;              die              (              )              ;              }                              

Relieve and close the file when you're done editing.

You can now access this page in your web browser by visiting the domain proper name or public IP address configured for your website, followed by /todo_list.php:

          http://your_domain_or_IP/todo_list.php                  

You should meet a page like this, showing the content y'all've inserted in your examination table:

Example PHP todo list

That means your PHP surroundings is ready to connect and interact with your MySQL server.

Conclusion

In this guide, we've congenital a flexible foundation for serving PHP websites and applications to your visitors, using Apache as web server and MySQL as database system.

As an immediate next step, you should ensure that connections to your web server are secured, by serving them via HTTPS. In society to achieve that, you can use Let's Encrypt to secure your site with a costless TLS/SSL document.

leblancthasente.blogspot.com

Source: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04

0 Response to "I Have to Open Xampp Again and Again From Terminal in Ubuntu 1404"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel