Ubuntu 16.04 LAMP Server Guide-Configure APACHE2.4,PHP7, and mariadb (not MySQL)

Source: Internet
Author: User
Tags apache php apcu install php php development environment ssl certificate phpmyadmin

Translated from: https://www.howtoforge.com/tutorial/install-apache-with-php-and-mysql-on-ubuntu-16-04-lamp/

Ubuntu 16.04 phpmyadmin install


Yesterday I installed ubuntu server in the virtual machine, and then configured the php development environment. After referring to this article, I installed and configured everything at one time, so I want to record this article. Hope to help beginners get these configurations at once (to avoid tangling), and then you can happily program, hehe.

The following is my translated content, which is completely compared with the original text, and there is no part that I have changed (because the original text is already perfect):

 LAMP is short for Linux, Apache, MySQL, PHP. This article teaches you how to install Apache2, PHP7 (mod_php) and MySQL on ubuntu 16.04 (Xenial Xerus) server. In addition, the PHPMyAdmin tool will be installed to manage MySQL.
S etup phpmyadmin ubuntu 16.04
Explanation

In this article, I use server1.example.com as the host name, and the IP is: 192.168.1.100. If you are different from me, just replace it in the corresponding place.

Phpmyadmin not working ubuntu 16.04


I recommend using minimal Ubuntu server as the basis for this article.

I run all commands with root privileges, so make sure you are using the root account:

sudo su
Install MariaDB as a replacement for MySQL
I installed MariaDB instead of MySQL. MariaDB is a branch version of MySQL maintained by the author of MySQL, Monty Widenius. MariaDB is compatible with MySQL, and has added features to improve performance. Run the following command to install MariaDB-server and client: phpmyadmin install ubuntu 16.04

apt-get install mariadb-server mariadb-client
Then set MariaDB's root password:
Install phpmyadmin ubuntu 16.04 apache
mysql_secure_installation
Then, some prompts appear, just follow the red prompts:
How to install phpmyadmin in ubuntu 16.04 using terminal
Enter current password for root (enter for none): <-press enter
Set root password? [Y / n] <-y
New password: <-Enter the new MariaDB root password here
Re-enter new password: <-Repeat the password
Remove anonymous users? [Y / n] <-y
Disallow root login remotely? [Y / n] <-y
Reload privilege tables now? [Y / n] <-y
Use the mysql command to test whether you can log in to MariaDB:

mysql -u root -p
 Then enter the root password set above, it will appear as follows:

To leave the MariaDB shell, enter quit and enter.
Install php mysql phpmyadmin ubuntu 16.04
Install Apache 2.4
Apache 2 can be obtained directly from the Ubuntu package, as long as:

apt-get install apache2
Now open the browser, enter http://192.168.1.100, you can see the default page of Apache 2:

The Apache default article root directory is / var / www / html, and its main configuration file is: /etc/apache2/apache2.conf. The documentation for configuring the system is at /usr/share/doc/apache2/README.Debian.gz.

Install PHP 7
Install PHP 7 and Apache PHP modules:

apt-get install php7.0 libapache2-mod-php7.0
Then restart Apache

systemctl restart apache2
 

 Test PHP for some details
 The document root directory of the default web site is / var / www / html. I create an info.php file in this directory and then access it in a browser. This file can display detailed information about PHP installation.

vim /var/www/html/info.php
Enter the file content:

<? php
phpinfo ();
Change the owner of the info.php file to www-data users and groups

chown www-data: www-data /var/www/html/info.php
Now we can visit http://192.168.1.100/info.php in the browser, the results are as follows:

As you can see, PHP7.0 is running. From the Server API line, it can be seen that it is running through Apache 2.0 Handler. Continue to scroll down the page and you will see all the enabled modules. MySQL is not among them, this is because we have not added MySQL / MariaDB support to PHP.

PHP enables MySQL / MariaDB support
In order for PHP to support MySQL, you can install the php7.0-mysql package. At the same time, you can also install other required PHP modules, use the following command to search for available PHP modules:

apt-cache search php7.0
Select some modules and install them:

apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext
 Restart Apache2

systemctl restart apache2
As shown, PHP has enabled MySQL / MariaDB support.

 Install APCu PHP cache to speed up PHP operation
APCu is a free PHP opcode cacher used to cache and optimize PHP intermediate code. It is recommended to install it to speed up PHP speed.

installation:

apt-get install php-apcu
Restart Apache:

systemctl restart apache2
Refresh http://192.168.1.100/info.php and see the apcu module:

Please delete the info.php file, it will display the sensitive information of your server. Run the following command to delete:

rm -f /var/www/html/info.php
Enable Apache's SSL website support
 SSL / TLS is a security layer used to encrypt the connection between the browser and the server. Use the following command to enable https: // support

a2enmod ssl
a2ensite default-ssl
These two lines of commands enable the ssl module and add a link to /etc/apache2/sites-available/default-ssl.conf in the / etc / apache2 / sites-enabled folder to include it in the apache configuration . Then restart apache to enable the new configuration:

systemctl restart apache2
Now the browser opens https://192.168.1.100 and sees:

You see an SSL warning: The server's SSL certificate is "issued to yourself", which means that the browser does not trust the certificate, so you must accept the security warning before you can open the apache default page:

A "green lock" in front of the URL in the browser's address bar indicates that the connection is encrypted. To cancel the SSL warning, you can obtain an officially signed SSL certificate from the SSL certificate authority, and then replace the default certificate: /etc/ssl/certs/ssl-cert-snakeoil.pem.

 Install phpMyAdmin
The MySQL database can be operated through phpMyAdmin. Installation command:

apt-get install phpmyadmin
Then see these prompts and follow the red prompts to enter:

Web server to configure automatically: <-Select the option: apache2
Configure database for phpmyadmin with dbconfig-common? <-Yes
MySQL application password for phpmyadmin: <-Press enter, apt will create a random password automatically.
MariaDB enables the "unix_socket" plugin for the root user by default. This plugin prevents the root user from logging into phpmyadmin and the root user's TCP connection to MySQL. Therefore, it was disabled using the command:

echo "update user set plugin =‘ ‘where User =‘ root ’; flush privileges;" | mysql -u root -p mysql
Then enter the MariaDB root password.

After that, you can access it through http://192.168.1.100/phpmyadmin/:

 

Ubuntu 16.04 LAMP server guide-configure Apache2.4, PHP7, and MariaDB (not MySQL)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.