2. page content
Continuation
Az on the first page we installed the MariaDB database engine and Apache web server, on this page we continue to build the LAMP server by installing and configuring PHP7 and phpMyAdmin.
Installing PHP 7
The default is Debian 9 (Stretch) PHP version is 7.0. The latest release of this is a 7.0.33.
To install Apache as a module, enter the following apt-get command:
apt-get -y install php7.0 libapache2-mod-php7.0
We will expand this server with many more in the future, including installing and deploying PHP-FPM.
Then restart the apache web server with systemctl command:
systemctl restart apache2.service
You will now have a working PHP system, but we still need to add some things to include the appropriate plugins.
Install MySQL / MariaDB support
For PHP support for our recently installed database engine, install the php7.0 mysql package:
apt-get -y install php7.0-mysql
Installing additional PHP packages
Az apt-cache Use the command to list what packages are still available for PHP 7.0:
apt-cache search php7.0
There is a big list for this, and there are a lot of them to choose from.
The following installation command is recommended for a lot of usable PHP systems:
apt-get -y install \
php-pear \
php-imagick \
php-apcu \
php-memcache \
php7.0-curl \
php7.0-gd \
php7.0-intl \
php7.0-imap \
php7.0-mcrypt \
php7.0-pspell \
php7.0-recode \
php7.0-sqlite3 \
php7.0-tidy \
php7.0-xmlrpc \
php7.0-xsl \
php7.0-zip \
php7.0-opcache
Of course, you can install additional packages later if needed at any time.
Once you've installed all the plugins we need, restart Apache:
systemctl restart apache2.service
Enable Embedded PHP Mode (Optional)
By default, Apache is configured so that only php runs PHP code in files with the extension. This is primarily for security reasons. However, we may need to run PHP code embedded in HTML files, for example. In today's modern PHP pages, CMS systems, this is no longer fashionable, but in the case of older websites, there were often such solutions, where PHP code parts were included in the HTML files.
So if you need such a need to run PHP code in HTML files, you should do the following. If we don't need it, skip this.
Create an html file in the web root:
nano /var/www/html/proba.html
And let's include the following:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <title>Próba oldal</title> </head> <body> Helló világ!<br> Itt jön egy beágyazott PHP kórdész:<br> <?PHP echo "PHP fut!"; ?> </body> </html>
And load it into your browser:
http://192.168.1.120/proba.html
As you can see, PHP code does not run in the first round. To remedy this, open the already mentioned on the first page of the description Virtual hosting our file:
nano /etc/apache2/sites-enabled/000-default.conf
And place the lines highlighted in green at the end of the VirtualHost block of the configuration file to look like this:
<VirtualHost *:80>
[...]
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Then restart Apache:
systemctl restart apache2.service
Then upgrade to our previous trial page in the browser:
And now the PHP code is running in the HTML file.
PHP testing
Finally, we test our entire PHP system. Create a php file in the web root:
nano /var/www/html/phpinfo.php
Then add the following lines:
1 2 3 <?php phpinfo(); ?>
Save and then run the server on your browser IP Address with the correct URL:
http://192.168.1.120/phpinfo.php
I have marked the Server API line with a green dot, where we can see that "Apache 2.0 Handler" indicates that PHP is currently running as an Apache module. Also, if you scroll down here, you can see all the loaded PHP modules and their settings.
If you need to set something in php.ini and find it here: /etc/php/7.0/apache2/php.ini
Installing phpMyAdmin
A phpMyAdmin allows us to conveniently manage our databases, run queries, perform maintenance, etc. on the web. To install it, run the following command:
apt-get -y install phpmyadmin
A few dialogs will appear during installation. First you ask which HTTP server we are using:
Select apache2 here.
Then, after a further installation, in the following dialog, you will be asked if you need your own database to run phpMyAdmin and whether you want to configure the phpMyAdmin automatically dbconfig-common via:
Choose yes here.
You will then be prompted for another password that the phpMyAdmin control user will work with:
With this user, phpMyAdmin does the background maintenance, structure synchronizations, etc., so we won't have to deal with it. So press an enter to do this to generate your own password.
The installation is now complete.
Allow root access
Instead of Debian 8 (Jessie) LAMP server for phpMyAdmnin installation, by default - for additional security reasons - root access is not allowed in the phpMyadmin interface, so this has to be set manually for us (this is not the same setting as discussed above). To set it up, run the following command:
echo "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';FLUSH PRIVILEGES;" | mysql -u root -p
Then prompt us for the MariaDB root password at the command prompt, enter it.
Testing phpMyAdmin
You can now log in to phpMyAdmin as root at the following address:
http://192.168.1.120/phpmyadmin
Additional security settings (optional)
If we plan to use the command line database in the future, or if we also want to use our shell scripts to manage our databases, securing command-line database use.
I wrote about this in a more general form in the linked description, so let's see what it looks like in this case.
Open as root the defaults file already created by our database engine:
nano /etc/mysql/debian.cnf
And set the database root password as highlighted in green:
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = root password = '<root jelszó>' socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = root password = '<root jelszó>' socket = /var/run/mysqld/mysqld.sock basedir = /usr
Then save it.
You can then avoid asking for the password at the command line, which allows you to automate working with databases in scripts as well. Of course, we can create such defaults files for any database user.
Accordingly, for example, if we were to run the phpMyAdmin root login configuration command now, we would do the following:
echo "UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'unix_socket';FLUSH PRIVILEGES;" | mysql --defaults-file=/etc/mysql/debian.cnf
Even if it can be run by trial, it does no harm if it is run again.
Finally, for security's sake, let's look at the permissions of our defaults file (though created by the system, so it should be fine):
ls -l /etc/mysql/debian.cnf
And this should look like this:
-rw------- 1 root root 305 jún 21 13:35 /etc/mysql/debian.cnf
This way we can be sure that only the root user can see the file.
Download virtual machine
Conclusion
So this would be a completely basic Debian 9 (Stretch) based LAMP server, from which we can now run any PHP and MySQL / MariaDB based dynamic web pages. Later, we will be adding some useful things to make them more widely available.
- Encyclopedia - LAMP Systems
- Installing Debian 8 (Jessie) LAMP Server v1.0
- Installing Debian 10 (Buster) LAMP Server v1.0
- Install v18.04 on the Ubuntu 1.0 LTS (Bionic Beaver) LAMP Server
- Install Ubuntu 20.04 LTS (Focal Fossa) LAMP Server v1.0
- Debian 11 (Bullseye) LAMP server v1.0 installation
- wiki.debian.org - LaMp
- Debian 9 LAMP Server Tutorial with Apache, PHP 7 and MariaDB
- Install Debian 9 (Stretch) Minimum Server
- Install Debian 10 (Buster) Minimum Server
- Securing command line database usage with defaults files
- Perfect server: Debian 8 (Jessie) V1.0
- Perfect server: Debian 9 (stretch) V1.0
- Perfect server: Debian 11 (Bullseye) v1.0
- Install a minimum server for Ubuntu 18.04 LTS (Bionic Beaver)
Navigation
- To post registration and login required
- 327 views