install_apache_mysql_php_linux_ubuntu_server
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
install_apache_mysql_php_linux_ubuntu_server [2020/06/07 19:05] – created wikiadmin | install_apache_mysql_php_linux_ubuntu_server [2020/06/08 23:14] – [Create a new admin user or new root user and password with access from any IP remotely] wikiadmin | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
- | You can install these with LAMP or XAMPP or install each separately using apt-get installer. | + | You can install these with LAMP or XAMPP. You can also install |
+ | |||
+ | As of April, May June, 2020, Let's install Apache 2.4, MySQL 8.0 and PHP 7.4 on Ubuntu 20.04 LTS. | ||
+ | |||
+ | This is done with root or sudo privilege user access to the system. | ||
+ | |||
+ | ===== Installing PHP ===== | ||
+ | |||
+ | The latest PHP 7.4 packages are available in the default repositories for Ubuntu 20.04 LTS. First Update the index and then install PHP on the Ubuntu Server operating system. | ||
+ | |||
+ | < | ||
+ | sudo apt update | ||
+ | sudo apt install -y php7.4 | ||
+ | </ | ||
+ | |||
+ | **Here are some additional PHP modules to install that may be required for your applications**. [However, before you install these modules, see the discussion below regarding additional modules required to run NextCloud.] | ||
+ | |||
+ | < | ||
+ | |||
+ | If you are planning to install NextCloud on your Ubuntu Server, then the above generally required modules are included in the expanded list of PHP modules that are recommended or required to run NextCloud from Apache and using PHP. | ||
+ | |||
+ | ===== Install the PHP Modules that are Prerequisites for NextCloud installation ===== | ||
+ | |||
+ | If you plan to install NextCloud to run on a virtual host from Apache web server, then you should install the following PHP modules that are either recommended or required as prerequisites for the proper functioning of NextCloud. | ||
+ | |||
+ | < | ||
+ | |||
+ | After the installation of these PHP modules, you may see a notice like the following: | ||
+ | |||
+ | Notice: Not enabling PHP 7.4 FPM by default. | ||
+ | Notice: To enable PHP 7.4 FPM in Apache2 do: | ||
+ | Notice: a2enmod procy fcgi set enfiv | ||
+ | Notice: a2enconf php7.4*fpm | ||
+ | Notice: You are seeing this message because you have apache2 package installed. | ||
+ | |||
+ | The apache2 package that is installed and the notice is referring to is the package that was just installed with the installation of PHP 7.4. | ||
+ | |||
+ | Note that if Apache server was already installed before you found this guide, then you should **reload Apache2 servic**e to use these newly installed PHP modules: | ||
+ | |||
+ | < | ||
+ | |||
+ | Next we will install Apache2 web server and configure Virtual Hosts. | ||
+ | |||
+ | ===== Installing Apache2 and Creating Apache VirtualHost ===== | ||
+ | |||
+ | ==== Installing Apache2 (version 2.4) ==== | ||
+ | |||
+ | < | ||
+ | sudo apt-get | ||
+ | |||
+ | sudo apt-get install apache2 | ||
+ | </ | ||
+ | |||
+ | Also install libapache2-mod-php module to work PHP with Apache2. | ||
+ | |||
+ | Enter the following command to install it: | ||
+ | |||
+ | < | ||
+ | |||
+ | Some help sites also include " | ||
+ | |||
+ | < | ||
+ | ==== Creating Apache VirtualHost ==== | ||
+ | |||
+ | In Apache on Ubuntu, the virtual host configuration files are stored under / | ||
+ | |||
+ | < | ||
+ | cd / | ||
+ | |||
+ | sudo cp 000-default.conf www1.example.com.conf | ||
+ | </ | ||
+ | |||
+ | Edit the virtual host configuration file for your requirements, | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | ServerAdmin webmaster@site1.example.com | ||
+ | ServerName www1.example.com | ||
+ | DocumentRoot / | ||
+ | |||
+ | < | ||
+ | Options FollowSymLinks | ||
+ | AllowOverride None | ||
+ | </ | ||
+ | < | ||
+ | Options Indexes FollowSymLinks MultiViews | ||
+ | AllowOverride None | ||
+ | Order allow, | ||
+ | allow from all | ||
+ | </ | ||
+ | |||
+ | ScriptAlias /cgi-bin/ / | ||
+ | < | ||
+ | AllowOverride None | ||
+ | Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch | ||
+ | Order allow, | ||
+ | Allow from all | ||
+ | </ | ||
+ | |||
+ | ErrorLog ${APACHE_LOG_DIR}/ | ||
+ | LogLevel warn | ||
+ | CustomLog ${APACHE_LOG_DIR}/ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Create the appropriate directory structure in the file system, in accordance with the path specified in the above virtual host.conf file, and assign or grant the appropriate file permissions for the Apache webserver user (namely www-data: | ||
+ | |||
+ | < | ||
+ | mkdir -p / | ||
+ | chmod 755 / | ||
+ | chown www-data.www-data / | ||
+ | </ | ||
+ | |||
+ | You can now upload your project files (website) on **/ | ||
+ | |||
+ | < | ||
+ | echo "< | ||
+ | </ | ||
+ | |||
+ | ==== Next - Enable the First VirualHost ==== | ||
+ | |||
+ | Remember that we configured the first VirtualHost file under the / | ||
+ | |||
+ | Adjust the site-name and use the following command to enable this VirtualHost so that Apache can load this enabled configuration file when the Apache service is restarted (reloaded). so, to enable the new configuration VitualHost, adjust the site-name and run the following from the command line: | ||
+ | |||
+ | < | ||
+ | |||
+ | This enables the site in **/ | ||
+ | |||
+ | To activate the new configuration by reloading Apache (to bring the site ' | ||
+ | |||
+ | < | ||
+ | |||
+ | You will need to setup DNS address entries for this ' | ||
+ | |||
+ | If you do not have the DNS ready, you can temporarily map the domain by making an entry in the /etc/hosts files. | ||
+ | |||
+ | < | ||
+ | |||
+ | 192.168.2.163 | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Creating Additional Virtual Hosts ==== | ||
+ | |||
+ | Repeat the above steps for site www1 by changing the site-name to whatever it will be, such as www2.exmample.com | ||
+ | |||
+ | ===== Install MySQL Database Server ===== | ||
+ | |||
+ | The apt repositories for Ubuntu 20.04 LTS contain MySQL server version 8.0. | ||
+ | |||
+ | Install mysql-server packages for the MySQL database. Also, install the php-mysql package to use MySQL support using PHP. Use the following command to install it. | ||
+ | |||
+ | < | ||
+ | |||
+ | The installer | ||
+ | |||
+ | Enter this command: | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | //Securing the MySQL server deployment.// | ||
+ | |||
+ | // | ||
+ | |||
+ | //VALIDATE PASSWORD COMPONENT can be used to test passwords | ||
+ | and improve security. It checks the strength of password | ||
+ | and allows the users to set only those passwords which are | ||
+ | secure enough. Would you like to setup VALIDATE PASSWORD component?// | ||
+ | |||
+ | **Press y|Y for Yes, any other key for No: y** | ||
+ | |||
+ | //There are three levels of password validation policy:// | ||
+ | |||
+ | //LOW Length >= 8// | ||
+ | |||
+ | //MEDIUM Length >= 8, numeric, mixed case, and special characters// | ||
+ | |||
+ | //STRONG Length >= 8, numeric, mixed case, special characters and dictionary file// | ||
+ | |||
+ | **Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2** | ||
+ | |||
+ | //Please set the password for root here.// | ||
+ | |||
+ | **New password: | ||
+ | |||
+ | **Re-enter new password: | ||
+ | |||
+ | //Estimated strength of the password: 100// | ||
+ | |||
+ | **Do you wish to continue with the password provided? | ||
+ | |||
+ | //By default, a MySQL installation has an anonymous user, | ||
+ | allowing anyone to log into MySQL without having to have | ||
+ | a user account created for them. This is intended only for | ||
+ | testing, and to make the installation go a bit smoother. | ||
+ | You should remove them before moving into a production | ||
+ | environment.// | ||
+ | |||
+ | **Remove anonymous users? (Press y|Y for Yes, any other key for No) : y** | ||
+ | |||
+ | // | ||
+ | |||
+ | |||
+ | //Normally, root should only be allowed to connect from | ||
+ | ' | ||
+ | the root password from the network.// | ||
+ | |||
+ | **Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y** //(n should be considered)// | ||
+ | |||
+ | // | ||
+ | |||
+ | //By default, MySQL comes with a database named ' | ||
+ | anyone can access. This is also intended only for testing, | ||
+ | and should be removed before moving into a production | ||
+ | environment.// | ||
+ | |||
+ | |||
+ | **Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y** | ||
+ | |||
+ | // - Dropping test database...// | ||
+ | |||
+ | // | ||
+ | |||
+ | ** - Removing privileges on test database...** | ||
+ | |||
+ | // | ||
+ | |||
+ | //Reloading the privilege tables will ensure that all changes | ||
+ | made so far will take effect immediately.// | ||
+ | |||
+ | **Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y** | ||
+ | |||
+ | // | ||
+ | |||
+ | //All done!// | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Installing phpMyAdmin ===== | ||
+ | |||
+ | phpMyAdmin is a web interface to manage MySQL databases and user privileges. | ||
+ | |||
+ | < | ||
+ | |||
+ | When prompted during installation, | ||
+ | |||
+ | When prompted to create the phpMyAdmin database, provide your admin user access details and take the remaining steps to complete the installation. | ||
+ | |||
+ | ===== Workaround Errors in setting up phpmyadmin@localhost with all privileges involving dbconfig-common ===== | ||
+ | |||
+ | |||
+ | Are you getting errors when trying to login to PhpMyAdmin as root? | ||
+ | |||
+ | < | ||
+ | Cannot log in to the MySQL server | ||
+ | |||
+ | mysqli_real_connect(): | ||
+ | |||
+ | Connection for controluser as defined in your configuration failed. | ||
+ | |||
+ | mysqli_real_connect(): | ||
+ | |||
+ | or | ||
+ | |||
+ | #1698 - Access denied for user ' | ||
+ | </ | ||
+ | ==== Create a new admin user or new root user and password with access from any IP remotely ==== | ||
+ | |||
+ | Using SSH access to the Ubuntu Server, log into the mysql console using as the user root with the password for root that was established when installing MySQL database server on Ubuntu. | ||
+ | |||
+ | < | ||
+ | sudo mysql -u root -p | ||
+ | </ | ||
+ | |||
+ | **Enter password: | ||
+ | |||
+ | The SSH prompt should change to the MySQL console prompt that looks like this: | ||
+ | |||
+ | < | ||
+ | |||
+ | Now, create a new MySQL admin/root user with all privileges including GRANT privileges and make sure that the user can login from any IP remotely rather than only having privileges from @localhost. There are 3 choices of commands in the code block below for creating a new user from the MySQL console prompt; however, only the third choice may actually allow for logging into PhpMyAdmin as a root user from any remote IP. | ||
+ | |||
+ | < | ||
+ | CREATE USER ' | ||
+ | |||
+ | CREATE USER ' | ||
+ | |||
+ | CREATE USER ' | ||
+ | </ | ||
+ | |||
+ | So, for example, this should work (and ensure that you are logged into the console prompt at mysql> | ||
+ | |||
+ | < | ||
+ | CREATE USER ' | ||
+ | |||
+ | </ | ||
+ | |||
+ | Now, let's grant the new user named ' | ||
+ | |||
+ | < | ||
+ | GRANT ALL PRIVILEGES ON *.* TO ' | ||
+ | </ | ||
+ | |||
+ | And lastly, run this command: | ||
+ | |||
+ | < | ||
+ | FLUSH PRIVILEGES; | ||
+ | </ | ||
+ | |||
+ | Exit the MySQL console and return to the SSH user prompt, with the exit command: | ||
+ | |||
+ | < | ||
+ | |||
+ | Now, open your web browser and log into PhpMyAdmin through a webpage on a remote device with the username ' | ||
+ |
install_apache_mysql_php_linux_ubuntu_server.txt · Last modified: 2020/06/08 23:20 by wikiadmin