{"id":26308,"date":"2023-03-07T07:17:35","date_gmt":"2023-03-07T07:17:35","guid":{"rendered":"http:\/\/localhost\/helpold\/?p=26308"},"modified":"2024-11-12T09:12:13","modified_gmt":"2024-11-12T05:42:13","slug":"lamp-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.arvancloud.ir\/help\/en\/lamp-on-ubuntu\/","title":{"rendered":"Installing LAMP on Ubuntu"},"content":{"rendered":"<p>LAMP refers to using a combination of Linux, Apache, MySQL, and PHP to host websites that have dynamic content or web applications. This collection uses Apache as a web service, PHP to handle dynamic content, and MySQL to store data and serve as a database.<\/p>\n<h2>Requirements<\/h2>\n<p>You will need a server running the Ubuntu 18.04 operating system and a user having sudo permissions for this tutorial.<\/p>\n<h2>How to Install LAMP?<\/h2>\n<p>Your first step will be installing the Apache web server. To install this program, you can use apt. First, you must update the repositories which apt uses:<\/p>\n<pre><code>sudo apt-get update<\/code><\/pre>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-25735 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-1-jpeg.webp\" alt=\"\" width=\"1024\" height=\"239\" \/><br \/>\nNext, install apache with the following command:<\/p>\n<pre><code>sudo apt-get install apache2<\/code><\/pre>\n<p><img decoding=\"async\" class=\"size-full wp-image-25737 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-2-jpeg.webp\" alt=\"\" width=\"1024\" height=\"244\" \/><br \/>\nOnce you have installed this program, the service will automatically start. You can enter your instance IP address in the browser to view the default Apache page. Its default screen is as shown below:<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-25739 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-3-jpeg.webp\" alt=\"\" width=\"800\" height=\"586\" \/><br \/>\nWhen the steps of installation are correctly performed, but you are not seeing the default screen, use the following command to check the status of the service first:<\/p>\n<pre><code>sudo systemctl status apache2<\/code><\/pre>\n<p>If the output of the command is as shown in the image below, it indicates that the service was not started properly:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-%D9%88-%D8%B1%D8%A7%D9%87%E2%80%8C%D8%A7%D9%86%D8%AF%D8%A7%D8%B2%DB%8C-LAMP-%D8%B1%D9%88%DB%8C-Ubuntu-5933256309404_lmap-ubuntu-4-jpeg.webp\" \/><br \/>\nEnter the following command to start the service and re-check the status of the service:<\/p>\n<pre><code>sudo systemctl start apache2<\/code><\/pre>\n<p>When the service is properly set up, and you still are not seeing the default page, chances are that the firewall configured on the instance is blocking traffic to the web server. Assuming you are using ufw as your firewall, type the following command to allow incoming web server traffic:<\/p>\n<pre><code>sudo ufw allow in \"Apache Full\"<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25743 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-5-jpeg.webp\" alt=\"\" width=\"1024\" height=\"50\" \/><br \/>\nNow, restart the Apache service using the following command. After you have run this command, the default Apache screen can be seen:<\/p>\n<pre><code>sudo systemctl restart apache2<\/code><\/pre>\n<p>The next step is to install MySQL. You can use apt to install this program as well:<\/p>\n<pre><code>sudo apt-get install mysql-server<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25745 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-6-jpeg.webp\" alt=\"\" width=\"1024\" height=\"241\" \/><br \/>\nYou can run a script with the following command after the installation is complete. By running this script, you will remove default settings that can pose security problems:<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>The first section will ask you if you would like to set up the VALIDATE PASSWORD plugin. With this plugin, you can determine the security of the passwords you choose for MySQL. You can press the y key to set up the plugin, and any other key to not change the current settings (if you want to set up the plugin, you will be prompted for the amount of accepted credit):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25747 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-7-jpeg.webp\" alt=\"\" width=\"1024\" height=\"192\" \/><br \/>\nYou will be asked to choose a password for root in the next step. This user will be similar to the root user in Linux concerning importance and access; for this reason, the password you will choose for the root must be sufficiently strong.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25749 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-8-jpeg.webp\" alt=\"\" width=\"1024\" height=\"118\" \/><br \/>\nThe subsequent questions will be used to remove unknown users or modify the default settings. Answer y to all the following questions:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25751 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-9-jpeg.webp\" alt=\"\" width=\"1024\" height=\"29\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25753 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-10-jpeg.webp\" alt=\"\" width=\"1024\" height=\"34\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25755 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-11-jpeg.webp\" alt=\"\" width=\"1024\" height=\"24\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25757 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-12-jpeg.webp\" alt=\"\" width=\"1024\" height=\"21\" \/><\/p>\n<p>You can now install PHP and any plugins you need to allow PHP, MySQL, and Apache to communicate with each other using the following command:<\/p>\n<pre><code>sudo apt install php libapache2-mod-php php-mysql<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-25759\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-13-jpeg.webp\" alt=\"\" width=\"1024\" height=\"221\" \/><\/p>\n<blockquote><p><strong>Note<\/strong>: To use multiple different domains in the instance, you must configure the Virtual Host settings. To do this, at least one domain name that is configured for the instance is required.<\/p><\/blockquote>\n<p>You can see how to make these settings in the following. For this tutorial, we will use the example.com domain. Use your domain name instead of it in all virtual host settings.<br \/>\nBy default, the Apache web server will display the files in the var\/www\/html\/ path. To begin, use the following command to create a similar path for your domain:<\/p>\n<pre><code>sudo mkdir \/var\/www\/example.com<\/code><\/pre>\n<p>Then, run the following command. With this command, you will change the ownership of the above path to the USER variable value:<\/p>\n<pre><code>sudo chown -R $USER:$USER \/var\/www\/example.com<\/code><\/pre>\n<p>Use the following command to set the required permissions:<\/p>\n<pre><code>sudo chmod -R 755 \/var\/www\/example.com<\/code><\/pre>\n<p>The next thing you should do is to create a file like the default one, which can be found at var\/www\/html\/. This is the file that you will see after setup is complete and when you search for your domain name:<\/p>\n<pre><code>nano \/var\/www\/example.com\/index.html<\/code><\/pre>\n<p>Insert the following text into the file you created. Then save the file and exit:<\/p>\n<pre><code>&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Welcome to example.com!&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;h1&gt;your setup is working!&lt;\/h1&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>Now you have to create a virtual-host file that points to the file you created in the previous step. Use the Apache sample file to do this:<\/p>\n<pre><code>sudo cp \/etc\/apache2\/sites-available\/000-default.conf \/etc\/apache2\/sites-available\/example.com.conf<\/code><\/pre>\n<p>Change the values of the ServerAdmin and DocumentRoot variables in the new file. The ServerAdmin variable value has to be the email address that the administrator will have access to, and the DocumentRoot value must be the address of the file you created earlier, which is var\/www\/example.com\/:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25761 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-14-jpeg.webp\" alt=\"\" width=\"1024\" height=\"158\" \/><br \/>\nNow, activate the created file by using the following command:<\/p>\n<pre><code>sudo a2ensite example.com.conf<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25763 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-15-jpeg.webp\" alt=\"\" width=\"1024\" height=\"59\" \/><br \/>\nRunning the following command will deactivate the default file:<\/p>\n<pre><code>sudo a2dissite 000-default.conf<\/code><\/pre>\n<p>To verify that the settings are correct, use the following command. Assuming the settings are correct, the output of the command will be like the following image:<\/p>\n<pre><code>sudo apache2ctl configtest<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25765 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-16-jpeg.webp\" alt=\"\" width=\"1024\" height=\"22\" \/><br \/>\nIf so, restart the Apache service to apply the settings:<\/p>\n<pre><code>sudo systemctl restart apache2<\/code><\/pre>\n<p>When you enter the configured domain name into the browser, you can see the message that is written in the file.<br \/>\nTo verify that the stack settings are correct, consider writing a simple script in php language. Once you have configured the domain name and virtual host settings, you can insert this script into the var\/www\/example.com\/ path, or into the default path otherwise, i.e. var\/www\/html\/. You can use, for example, the following script (create the script with the name info.php in the path you want):<\/p>\n<pre><code>&lt;?php\nphpinfo ();\n?&gt;<\/code><\/pre>\n<p>Now, when you enter the address http:\/\/example.com\/info.php (with the virtual host settings) or http:\/\/your_IP\/info.php, you will see the following page:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-25767 aligncenter\" src=\"https:\/\/www.arvancloud.ir\/help\/wp-content\/uploads\/2023\/02\/-\u0648-\u0631\u0627\u0647\u200c\u0627\u0646\u062f\u0627\u0632\u06cc-LAMP-\u0631\u0648\u06cc-Ubuntu-5933256309404_lmap-ubuntu-17-jpeg.webp\" alt=\"\" width=\"800\" height=\"540\" \/><br \/>\nNote that if you have followed the settings regarding the virtual host and used the default path for the above settings, then you won&#8217;t see the displayed page since the default path settings are disabled, and you must re-enable the default mode:<\/p>\n<pre><code>sudo a2ensite 000-default.conf\nsudo systemctl restart apache2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>LAMP refers to using a combination of Linux, Apache, MySQL, and PHP to host websites that have dynamic content or web applications. This collection uses Apache as a web service, PHP to handle dynamic content, and MySQL to store data and serve as a database. Requirements You will need a server running the Ubuntu 18.04 [&hellip;]<\/p>\n","protected":false},"author":79,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"r1_post_views_count":"720","feedback_yes":"","feedback_no":"","ads_id_sidebar":"","ads_id_content":"","footnotes":""},"categories":[251,245],"tags":[],"class_list":["post-26308","post","type-post","status-publish","format-standard","hentry","category-app-development","category-cloud-server"],"lang":"en","translations":{"en":26308},"pll_sync_post":[],"_links":{"self":[{"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/posts\/26308","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/users\/79"}],"replies":[{"embeddable":true,"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/comments?post=26308"}],"version-history":[{"count":0,"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/posts\/26308\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/media?parent=26308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/categories?post=26308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.arvancloud.ir\/help\/wp-json\/wp\/v2\/tags?post=26308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}