Webserver (PHP8.1) and MySQL (8) Setup (Quick) with User and Privileges on Ubuntu (22.04+)

Lets assume you have a blank Ubuntu Server, this can be 22.04, or any later (TLS preferred) version.

First, lets become sudo.

sudo su

Then we can install some tools. We have included some other convenient defaults, including the additional needs for PHPMyAdmin.

(PHPMyAdmin is not adviced to be enabled in any production environment)

apt update && apt install -y nano htop wget curl dnsutils net-tools mysql-server php8.1 apache2 zip unzip phpmyadmin php8.1-{curl,soap,xml,mysql,gd,dom,intl,imagick,zip}

During the installation some screens will appear in the terminal, asking for selections or services to restart. Some examples and what to do.

For this one select (hit space) for apache2 as that’s what we also install in the same command.

This screen would allow some visual/interactive installation options for MySQL, however we usually select no, as not all interesting options are available through it.

Next up, lets initiate mysql(d)

mysqld --initialize-insecure

This will return without error if no issue. Then we can login so we can create a user for MySQL.

mysql

This will get you into MySQL, showing:

And lets create the user


CREATE USER 'my_username'@'%' IDENTIFIED BY 'MyP@ssw0rd';

You should replace my_username with your username, the password too of course, but maybe also the % for the host, this can be localhost or an ip like 127.0.0.1 or anywhere as it would be now (less secure)

And grant all the privileges

GRANT ALL PRIVILEGES ON *.* TO 'my_username'@'%' WITH GRANT OPTION;

Lets flush the privileges too

FLUSH PRIVILEGES;

Exit MySQL

\q

Now by the IP address of the host, you can login using the above created credentials into PHPMyAdmin: http://HOST_OR_IP/phpmyadmin

That’s really it, you have an Apache2 webserver and a MySQL server. One last common need would be some modules for Apache2, for when you install a real framework, think WordPress or something like Magento (2).

a2enmod ssl rewrite headers

And finally, don’t forget to drop your root access.

exit

Now you are really done. 😉


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *