{"id":48,"date":"2022-02-25T10:40:06","date_gmt":"2022-02-25T13:40:06","guid":{"rendered":"https:\/\/rafaellfrasson.com.br\/?p=48"},"modified":"2022-02-25T10:40:07","modified_gmt":"2022-02-25T13:40:07","slug":"instalacao-de-servidor-lamp-para-ubuntu","status":"publish","type":"post","link":"https:\/\/rafaellfrasson.com.br\/index.php\/2022\/02\/25\/instalacao-de-servidor-lamp-para-ubuntu\/","title":{"rendered":"Instala\u00e7\u00e3o de Servidor Lamp para Ubuntu"},"content":{"rendered":"\n<p>How to<\/p>\n\n\n\n<p>How to Install LAMP Apache, MySQL, PHP in Ubuntu 20.04. In this guide you will learn how to install Apache2, MySQL and PHP 7.4.<\/p>\n\n\n\n<p>You will also install some common PHP extensions and adjust the PHP configurations. Finally you will secure your setup with Let\u2019s Encrypt SSL and configure HTTPS redirection.<\/p>\n\n\n\n<p>This setup is tested on Google cloud, so it will work on all cloud hosting services like AWS, Azure or any VPS or any dedicated servers running Ubuntu 20.04.<\/p>\n\n\n\n<p>Prerequisites<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Root access to your server or a sudo user.<\/code><\/pre>\n\n\n\n<p>Step 1: Setup Initialization<\/p>\n\n\n\n<p>Start by updating the packages to the latest version available using the following command.<\/p>\n\n\n\n<p>sudo apt update<br>sudo apt upgrade<\/p>\n\n\n\n<p>Once you have updated the setup you can start the setup.<br>Step 2: Install Apache<\/p>\n\n\n\n<p>Install Apache using the following command.<\/p>\n\n\n\n<p>sudo apt install apache2<\/p>\n\n\n\n<p>This will install apache2 and all required dependencies.<br>Step 3: Setup Firewall<\/p>\n\n\n\n<p>Now you can set up Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS<\/p>\n\n\n\n<p>sudo ufw app list<\/p>\n\n\n\n<p>You will see all listed applications.<\/p>\n\n\n\n<p>Output<br>Available applications:<br>Apache<br>Apache Full<br>Apache Secure<br>OpenSSH<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Apache: This profile opens port 80 (normal, unencrypted web traffic)\nApache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS\/SSL encrypted traffic)\nApache Secure: This profile opens only port 443 (TLS\/SSL encrypted traffic)\nOpenSSH: This profile opens port 22 for SSH access.<\/code><\/pre>\n\n\n\n<p>If you are not going to use SSL you need to enable only the Apache profile.<\/p>\n\n\n\n<p>Now we will enable Apache Full.<\/p>\n\n\n\n<p>sudo ufw allow &#8216;Apache Full&#8217;<\/p>\n\n\n\n<p>With this command you can view the status of UFW.<\/p>\n\n\n\n<p>sudo ufw status<\/p>\n\n\n\n<p>You will see the output as follows.<\/p>\n\n\n\n<p>Output<br>Status: active<br>To Action From<br>&#8212; &#8212;&#8212; &#8212;-<br>Apache Full ALLOW Anywhere<br>OpenSSH ALLOW Anywhere<br>Apache Full (v6) ALLOW Anywhere (v6)<br>OpenSSH (v6) ALLOW Anywhere (v6)<\/p>\n\n\n\n<p>Step: 4 Check Apache Installation<\/p>\n\n\n\n<p>Once Apache is installed is is started automatically and already be up and running.<\/p>\n\n\n\n<p>Every process in Apache is managed with the systemctl command. Check the status of Apache with the following command.<\/p>\n\n\n\n<p>sudo systemctl status apache2<\/p>\n\n\n\n<p>Output<br>\u25cf apache2.service &#8211; The Apache HTTP Server<br>Loaded: loaded (\/lib\/systemd\/system\/apache2.service; enabled; vendor preset: enabled)<br>Drop-In: \/lib\/systemd\/system\/apache2.service.d<br>\u2514\u2500apache2-systemd.conf<br>Active: active (running) since Tue 2020-01-06 03:59:34 UTC; 5min ago<br>Main PID: 10617 (apache2)<br>Tasks: 55 (limit: 667)<br>CGroup: \/system.slice\/apache2.service<br>\u251c\u250010617 \/usr\/sbin\/apache2 -k start<br>\u251c\u250010619 \/usr\/sbin\/apache2 -k start<br>\u2514\u250010620 \/usr\/sbin\/apache2 -k start<br>Jan 06 03:59:34 apache systemd[1]: Starting The Apache HTTP Server\u2026<br>Jan 06 03:59:34 apache systemd[1]: Started The Apache HTTP Server.<\/p>\n\n\n\n<p>Now we have Apache installed and configured Firewall.<br>Step 5: Install MySQL<\/p>\n\n\n\n<p>In Ubuntu 20.04 MySQL 8 is included by default in the Focal Fossa repositories, so you can install it easily using the apt install command.<\/p>\n\n\n\n<p>sudo apt install mysql-server<\/p>\n\n\n\n<p>Once the installation is completed, the MySQL service will start automatically. To verify that the MySQL server is running, type:<\/p>\n\n\n\n<p>sudo service mysql status<\/p>\n\n\n\n<p>The output should show that the service is enabled and running:<\/p>\n\n\n\n<p>\u25cf mysql.service &#8211; MySQL Community Server<br>Loaded: loaded (\/lib\/systemd\/system\/mysql.service; enabled; vendor preset: enabled)<br>Active: active (running) since Tue 2020-05-05 07:13:18 UTC; 1min 4s ago<br>Main PID: 3333 (mysqld)<br>Status: &#8220;Server is operational&#8221;<br>Tasks: 38 (limit: 2010)<br>Memory: 322.9M<br>CGroup: \/system.slice\/mysql.service<br>\u2514\u25003333 \/usr\/sbin\/mysqld<\/p>\n\n\n\n<p>Step 6: Secure MySQL<\/p>\n\n\n\n<p>MySQL installation comes with a script named mysql_secure_installation that allows you to easily improve the MySQL server security.<\/p>\n\n\n\n<p>sudo mysql_secure_installation<\/p>\n\n\n\n<p>You will be asked to configure the VALIDATE PASSWORD PLUGIN which is used to test the strength of the MySQL users passwords and improve the security.<\/p>\n\n\n\n<p>Press y if you want to set up the validate password plugin or any other key to move to the next step.<\/p>\n\n\n\n<p>There are three levels of password validation policy, low, medium, and strong.<\/p>\n\n\n\n<p>Enter 2 for strong password validation.<\/p>\n\n\n\n<p>On the next prompt, you will be asked to set a password for the MySQL root user.<\/p>\n\n\n\n<p>If you set up the validate password plugin, the script will show you the strength of your new password. Type y to confirm the password.<\/p>\n\n\n\n<p>Next, you\u2019ll be asked to remove the anonymous user, restrict root user access to the local machine, remove the test database, and reload privilege tables. You should answer y to all questions.<br>Step 7: Install PHP<\/p>\n\n\n\n<p>By default Ubuntu 20.04 has the latest PHP 7.4 repository added. So you can install PHP using the following command.<\/p>\n\n\n\n<p>sudo apt install php libapache2-mod-php php7.4-mysql php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y<\/p>\n\n\n\n<p>Once PHP is installed you can check the version using the following command.<\/p>\n\n\n\n<p>php -v<\/p>\n\n\n\n<p>Step 8: Configure PHP<\/p>\n\n\n\n<p>Now we configure PHP for Web Applications by changing some values in php.ini file.<\/p>\n\n\n\n<p>For PHP 7.4 with Apache the php.ini location will be in following directory.<\/p>\n\n\n\n<p>Hit F6 for search inside the editor and update the following values for better performance.<\/p>\n\n\n\n<p>upload_max_filesize = 32M<br>post_max_size = 48M<br>memory_limit = 256M<br>max_execution_time = 600<br>max_input_vars = 3000<br>max_input_time = 1000<\/p>\n\n\n\n<p>Once you have modified your PHP settings you need to restart your Apache for the changes to take effect.<br>Step 9: Configure Apache<\/p>\n\n\n\n<p>Disable default Apache configuration.<\/p>\n\n\n\n<p>sudo a2dissite 000-default<\/p>\n\n\n\n<p>Create website directories.<\/p>\n\n\n\n<p>sudo mkdir -p \/var\/www\/html\/domainname\/public<\/p>\n\n\n\n<p>Setup correct permissions.<\/p>\n\n\n\n<p>sudo chmod -R 755 \/var\/www\/html\/domainname<br>sudo chown -R www-data:www-data \/var\/www\/html\/domainname<\/p>\n\n\n\n<p>Create a new virtual host configuration.<\/p>\n\n\n\n<p>sudo nano \/etc\/apache2\/sites-available\/domainname.conf<\/p>\n\n\n\n<p>Paste the following configurations in the new file.<\/p>\n\n\n\n<p><br>ServerAdmin admin@domainname.com<br>ServerName domainname.com<br>ServerAlias www.domainname.com<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> DocumentRoot \/var\/www\/html\/domainname\/public\n\n &lt;Directory \/var\/www\/html\/domainname\/public&gt;\n     Options Indexes FollowSymLinks\n     AllowOverride All\n     Require all granted\n &lt;\/Directory&gt;\n\n ErrorLog ${APACHE_LOG_DIR}\/error.log \n CustomLog ${APACHE_LOG_DIR}\/access.log combined <\/code><\/pre>\n\n\n\n<p>Enable the new configuration.<\/p>\n\n\n\n<p>sudo a2ensite domainname.conf<\/p>\n\n\n\n<p>Step 10: Install Let\u2019s Encrypt SSL<\/p>\n\n\n\n<p>HTTPS is a protocol for secure communication between a server (instance) and a client (web browser). Due to the introduction of Let\u2019s Encrypt, which provides free SSL certificates, HTTPS are adopted by everyone and also provides trust to your audiences.<\/p>\n\n\n\n<p>sudo apt install python3-certbot-apache<\/p>\n\n\n\n<p>Now we have installed Certbot by Let\u2019s Encrypt for Ubuntu 20.04, run this command to receive your certificates.<\/p>\n\n\n\n<p>sudo certbot &#8211;apache &#8211;agree-tos &#8211;redirect -m youremail@email.com -d domainname.com -d www.domainname.com<\/p>\n\n\n\n<p>Select the appropriate option and hit Enter<\/p>\n\n\n\n<p>This command will install Free SSL, configure redirection to HTTPS and restarts the Apache server.<br>Step 11: Renewing SSL Certificate<\/p>\n\n\n\n<p>Certificates provided by Let\u2019s Encrypt are valid for 90 days only, so you need to renew them often. So, let\u2019s test the renewal feature using the following command.<\/p>\n\n\n\n<p>sudo certbot renew &#8211;dry-run<\/p>\n\n\n\n<p>This command will test the certificate expiry and configures the auto-renewable feature.<br>Step: 12: Test the Setup<\/p>\n\n\n\n<p>Once you have done the able steps you can create a new test PHP file in your web directory.<\/p>\n\n\n\n<p>sudo nano \/var\/www\/html\/domainname\/public\/info.php<\/p>\n\n\n\n<p>Paste the below code inside the file.<\/p>\n\n\n\n<p>&lt;?php phpinfo();<\/p>\n\n\n\n<p>Save the file.<\/p>\n\n\n\n<p>Now go ahead and check your domain name with the info.php in the url (domainname.com\/info.php).<\/p>\n\n\n\n<p>You will see that your domain got redirected to HTTPS and see the PHP information details.<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>Now you have learned how to install LAMP stack Ubuntu 20.04.<\/p>\n\n\n\n<p>Thanks for your time. If you face any problem or any feedback, please leave a comment below.<\/p>\n\n\n\n<p>Fonte: https:\/\/www.cloudbooklet.com\/how-to-install-lamp-apache-mysql-php-in-ubuntu-20-04\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to How to Install LAMP Apache, MySQL, PHP in Ubuntu 20.04. In this guide you will learn how to install Apache2, MySQL and PHP 7.4. You will also install some common PHP extensions and adjust the PHP configurations. Finally you will secure your setup with Let\u2019s Encrypt SSL and configure HTTPS redirection. This setup &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rafaellfrasson.com.br\/index.php\/2022\/02\/25\/instalacao-de-servidor-lamp-para-ubuntu\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Instala\u00e7\u00e3o de Servidor Lamp para Ubuntu&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-sem-categoria"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=48"}],"version-history":[{"count":1,"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions"}],"predecessor-version":[{"id":50,"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/posts\/48\/revisions\/50"}],"wp:attachment":[{"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rafaellfrasson.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}