Debian apache php mariadb

LAMP, Linux Apache MySQL PHP

Before starting the installation, make sure your distribution is up to date (the ‘#’ indicates that you should do this as root):

MariaDB

Next install MariaDB using the following command:

# apt install mariadb-server mariadb-client

Immediately after you have installed the MariaDB server, you should run the next command to secure your installation.

# mysql_secure_installation

The previous script change root password and make some other security improvements.

You must never use your root account and password when running databases. The root account is a privileged account which should only be used for admin procedures. You will need to create a separate user account to connect to your MariaDB databases from a PHP script. You can add users to a MariaDB database by using a control panel like phpMyAdmin to easily create or assign database permissions for users.

apache2

The web server can be installed as follows:

# apt install apache2 apache2-doc

Configuring user directories for Apache Web Server

Configure Apache module userdir in /etc/apache2/mods-enabled/userdir.conf as follows:

 UserDir public_html UserDir disabled root AllowOverride All Options MultiViews Indexes SymLinksIfOwnerMatch Order allow,deny Allow from all Order deny,allow Deny from all  

From apache 2.4 and later use instead:

 UserDir public_html UserDir disabled root AllowOverride All Options MultiViews Indexes SymLinksIfOwnerMatch Require all granted Require all denied  

Create directory as user (not as root):

$mkdir /home/$USER/public_html

Change group as root (substitute your username) and restart web server:

# chgrp www-data /home//public_html # service apache2 restart

If you get a Forbidden error when accessing home folder through Apache check /home/username has permissions drwxr-xr-x. If the permissions are wrong correct them as such:

To be able to serve PHP (PHP needs to be installed as per instructions) check that /etc/apache2/mods-available/php5.conf is correct:

  SetHandler application/x-httpd-php Require all granted SetHandler application/x-httpd-php-source Require all denied # To re-enable php in user directories comment the following lines # (from to .) Do NOT set it to On as it # prevents .htaccess files from disabling it. # # # php_admin_value engine Off # # 

Place some web content in ~/public_html and see the results at http://localhost/~username

The «P» part

Installing the PHP subset of LAMP in Debian is quite simple, you just type this as root in an console (the # is the root prompt symbol):

Читайте также:  Python for номер текущей итерации

If you prefer Perl, then you might consider:

# apt install perl libapache2-mod-perl2

If you prefer Python, then you might consider:

# apt install python3 libapache2-mod-python

Configuration

Apache2 configuration file: /etc/apache2/apache2.conf

You can edit this file when needed, but for most simple applications, this should not be necessary as most stuff is now done using conf.d.

Test PHP

To test the PHP interface, edit the file /var/www/html/test.php:

and insert the following code.

Afterwards, point your browser to http:///test.php to start using it.

phpMyAdmin

Probably you also want to install phpMyAdmin for easy configuration:

To have access to phpMyAdmin on your website (i.e. http://example.com/phpmyadmin/ ) all you need to do is include the following line in /etc/apache2/apache2.conf (needed only before Squeeze, since 6.0 it will be linked by the package install script to /etc/apache2/conf.d/phpmyadmin.conf -> ../../phpmyadmin/apache.conf automatically):

Include /etc/phpmyadmin/apache.conf

Go to http:///phpmyadmin/ to start using it. (Use the IP or name of your PC/server instead of (The localhost IP is always 127.0.0.1).)

PHP: /etc/php5/apache2/php.ini

A usual issue with PHP configuration is to enable MySQL. Just edit the file and uncomment the following line (tip: search for mysql)

Note that this should not be needed anymore as conf.d is now used.

MySQL : /etc/mysql/my.cnf

You can find configuration examples in /usr/share/doc/mysql-server/examples

Источник

How to Install Linux, Apache, MariaDB, PHP (LAMP) Stack on Debian 10

Install LAMP Stack Debian 10

LAMP (stands for Linux, Apache, MariaDB, PHP) is a collection of open-source software that is used to create dynamic websites and web-based applications. It uses Linux as the OS, Apache as a web server to serve web content over simple URLs, MariaDB as a database server to store websites and applications data, and PHP as the scripting language to serve dynamic content. Usually, the Lamp stack uses MySQL as a database server, however, for Debian systems; MariaDB is now the default MySQL server.

In this post, we will demonstrate how to install Linux, Apache, MariaDB, and PHP (LAMP) Stack on Debian 10.

Pre-requisites

Step 1: Installing Apache

First, update the apt index using the below command in Terminal:

Then to install Apache, issue this command:

Once the installation is completed, the Apache service will start running automatically. Here is the command to verify the status of the Apache service:

$ sudo systemctl status apache2

Now if a firewall is enabled on your system, you will need to allow Apache port through it. The Debian system comes with different profiles for Apache which can be used to adjust the firewall settings. To view the list of all application profiles, issue the below command in Terminal:

Читайте также:  Using css to center

We will enable the “WWW Full” profile for Apache that will allow the traffic on both port 80(HTTP) and port 443(HTTPS). To view information about the “WWW Full” profile, execute the below command in Terminal:

$ sudo ufw app info "WWW Full"

To enable the “WWW Full” profile, execute the below command in Terminal:

$ sudo ufw allow in "WWW Full"

To verify if the rule has been added successfully, execute the below command in Terminal:

Now to check if Apache is working and can serve web pages, try to open Apache’s default webpage in your web browser:

Replace the ip-address with the IP address of your own system.

Alternatively, you can also access Apache’s default webpage using the curl command in your Terminal:

Step 2 — Installing MariaDB

Now, we will install the MariaDB database that will be used to store data for our site. Execute the below command in Terminal to install MariaDB database:

$ sudo apt install mariadb-server

Now execute the security script to implement some security features. Use the below command in Terminal to execute the script:

$ sudo mysql_secure_installation

You will be presented with a few questions to configure some options for MariaDB. When you are asked to provide the password for root, hit n. Then it will ask you to set the root password, again hit N, and then Enter. Then for all the next questions, hit y and then Enter to answer yes and accept the default values.

Now connect to MariaDB console as a root user. You can do so using this command in Terminal:

Now create a database let’s say “test“.

Now create a user along with a password and give it full permission to the “test” database. Execute the below command to do so:

GRANT ALL ON test.* TO tin@'localhost' IDENTIFIED BY 'tintin' WITH GRANT OPTION;

We have created a user ‘tin’ with password ‘tintin’.

Now reload the privileges using the below command:

Now try logging in to the MariaDB console using the new user credentials you have set in the previous step.

Now enter the password for this user (in our case, it was “tintin”).

To view the database “test” that you have created in the previous step, execute the below command in Terminal:

Читайте также:  Css ease in out анимации

To leave the console, execute the below command in Terminal:

Step 3: Installing PHP

In this, we will install PHP to connect with the MariaDB database and retrieve the required information. PHP also connects with the Apache server to hand over the processed information for displaying over the web.

In order to install PHP, issue this command in Terminal:

$ sudo apt install php libapache2-mod-php php-mysql

Usually, when a user requests something from the Apache server, it first searches it in the index.html file. In order to make the server first look for the requested item in the index.php file, you will need to make a little change in the dir.conf file for Apache. Execute the below command in Terminal to edit this file:

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

Find the below line in the dir.conf file:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

From the above line, cut index.php entry and paste it after the DirectoryIndex as shown in the following screenshot.

Then save and close the dir.conf file and reload Apache’s configuration using the below command.

$ sudo systemctl reload apache2

Then execute the below command to verify the status of Apache and to make sure there is no error:

$ sudo systemctl status apache2

Step 4— Testing PHP Processing on Apache

Now in this step, we will check if Apache is configured properly and can process requests for PHP files. To do so, create a new info.php file inside the /var/www/html directory using the below command in Terminal:

$ sudo nano /var/www/html/info.php

Then add the below lines of code in the info.php file:

After that save and close the info.php file.

Open the below address in your web browser:

Replace the ip-address with the IP address of your own system.

If you see the below page, then it verifies that the Apache is configured correctly to serve the PHP content.

This page also shows some information about PHP so it is recommended to remove this page. Issue the below command in Terminal to do so:

$ sudo rm /var/www/html/info.php

That is all there is to it! In this post, you have learned how to install the LAMP stack (Linux, Apache, MariaDB, and PHP ) in your Debian system. We hope you find this post helpful!

Ummara Mushtaq is a Telecommunication engineer with two years of experience in server support and networking. She writes technical articles based on Linux system administration for LinuxWays.

Источник

Оцените статью