{"id":186,"date":"2022-12-24T19:39:52","date_gmt":"2022-12-24T19:39:52","guid":{"rendered":"https:\/\/www.axencloud.com\/blog\/?p=186"},"modified":"2022-12-24T20:03:33","modified_gmt":"2022-12-24T20:03:33","slug":"install-apache-php-mysql-in-vps-hosting-axencloud","status":"publish","type":"post","link":"https:\/\/www.axencloud.com\/blog\/?p=186","title":{"rendered":"Install Apache PHP Mysql In VPS Hosting AxenCloud"},"content":{"rendered":"\r\n<p class=\"p1 wp-block-paragraph\">LAMP stands for Linux, Apache, MySQL, and PHP. It is a stack of open-source software. The first layer of the LAMP stack is the well-known Linux Operating System, which offers numerous configuration options and strict security. The LAMP stack is straightforward, reliable, and powerful. The second tier in the stack, Apache, provides support for compiled modules for popular programming languages like PHP, Perl, Python, Node.js, etc. Through the internet, this HTTP web server distributes web content. When deploying a LAMP stack, you have two options for the database layer. As a Relational Database Management System (RDMS) for your online applications, you can choose between MySQL and MariaDB. PHP is the last package on the list. To construct static or dynamic websites, you may simply embed this programming language in HTML documents.<\/p>\r\n<p class=\"p1\">LAMP is commonly used to build dynamic web applications. Here&#8217;s a brief overview of each component:<\/p>\r\n<p class=\"p1\">Linux: This is the operating system that runs the LAMP stack. It provides a stable, secure, and scalable platform for running web applications.<\/p>\r\n<p class=\"p1\">Apache: This is the web server software that serves web pages to users over the internet. It listens for incoming HTTP requests and sends back the appropriate response.<\/p>\r\n<p class=\"p1\">MySQL: This is a relational database management system that stores and retrieves data for web applications. It allows you to store structured data, such as user information, product catalogs, and more.<\/p>\r\n<p class=\"p1\">PHP: This is a programming language that is used to build dynamic web applications. It can be used to generate HTML, process form data, and interact with databases like MySQL.<\/p>\r\n<p class=\"p1\">Together, these four components form the LAMP stack, which is a popular choice for building web applications due to its flexibility, ease of use, and low cost.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\"><b>\u00a0 \u00a0 \u00a0 \u00a01. How to Install Apache Webserver<\/b><\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>\r\n<p class=\"p1\">SSH into your Ubuntu server as a non-root user, then upgrade your packages and the package information index.<\/p>\r\n<p class=\"p2\"><strong>$ sudo apt update &amp;&amp; sudo apt -y upgrade<\/strong><\/p>\r\n<p class=\"p1\">To install the Apache Web server, run the command listed below.<\/p>\r\n<p class=\"p2\"><strong>$ sudo apt install -y apache2<\/strong><\/p>\r\n<p class=\"p1\">Enter the public IP address of your server or domain name in place of <b>(192.0.2.1)<\/b> when accessing the URL below in a web browser.<\/p>\r\n<p class=\"p4\"><strong><span class=\"s1\"><a href=\"http:\/\/127.0.0.1\">http:\/\/127.0.0.1<\/a><\/span><\/strong><\/p>\r\n<p class=\"p1\">You should see the standard Apache web page as displayed below.<\/p>\r\n<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">\u00a0 <img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-191\" src=\"https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/Apache-300x274.jpg\" alt=\"\" width=\"540\" height=\"493\" srcset=\"https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/Apache-300x274.jpg 300w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/Apache-1024x936.jpg 1024w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/Apache-768x702.jpg 768w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/Apache-1536x1405.jpg 1536w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/Apache.jpg 1612w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/> \u00a0 \u00a0<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><b>\u00a0 \u00a02.How to Install a Database Server<\/b><\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 \u00a0When deploying a LAMP stack, you can choose between installing MySQL or MariaDB server.<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 \u00a0Run the command below to set up the MySQL server.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0<strong> \u00a0$ sudo apt install -y mysql-server<\/strong><\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 \u00a0Execute the command listed below to configure a MariaDB server.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0 \u00a0<strong>$ sudo apt install -y mariadb-server mariadb-client<\/strong><\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 \u00a0Run the command listed below to secure your database, whichever one you&#8217;ve selected.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0 \u00a0$ sudo mysql_secure_installation<\/p>\r\n<p>&nbsp;<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0Enter the below choices and press <b>(ENTER)<\/b> in each prompt to proceed.<\/p>\r\n<p class=\"p1\"><b>\u00a0 \u00a0 \u00a0MySQL Server<\/b><\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 (<\/p>\r\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0Would you like to setup VALIDATE PASSWORD component?<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Press y|Y for Yes, any other key for No: n<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>Please set the password for root here.<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>New password: EXAMPLE_PASSWORD<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Re-enter new password: EXAMPLE_PASSWORD<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Remove anonymous users? (Press y|Y for Yes, any other key for No) : y<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Remove test database and access to it? (Press y|Y for Yes, any other key for No): y<\/p>\r\n<p style=\"text-align: left;\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y<\/p>\r\n<p style=\"text-align: left;\">\u00a0 \u00a0 \u00a0 \u00a0)<\/p>\r\n<p>&nbsp;<\/p>\r\n<p class=\"p1\"><b>\u00a0 \u00a0 \u00a0MariaDB Server<\/b><\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0 \u00a0(<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0Enter current password for root (enter for none): ENTER<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>Set root password? [Y\/n]: Y<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/span>New password: EXAMPLE_PASSWORD<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>Re-enter new password: EXAMPLE_PASSWORD<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>Remove anonymous users? [Y\/n] Y<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>Disallow root login remotely? [Y\/n] Y<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>Remove test database and access to it? [Y\/n] Y<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>Reload privilege tables now? [Y\/n] Y<\/p>\r\n<p class=\"p3\">\u00a0 \u00a0 \u00a0)<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0Once you&#8217;ve secure the installation, login to the RDMS as root:<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0<strong>$ sudo mysql -u root -p<\/strong><\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 Enter your database server root password and press <b>(ENTER) <\/b>to proceed. Then, type the command below to create your\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 first <b>(test_database)<\/b> database.<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 MySQL server.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0 mysql&gt; CREATE database test_database;<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0 MariaDB server.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 \u00a0MariaDB [(none)]&gt; CREATE database test_database;<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 \u00a0Output.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 Query OK, 1 row affected (0.00 sec)<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 Next step, list the databases in the server by running the <b>(SHOW DATABASES)<\/b> command.<\/p>\r\n<p class=\"p1\">\u00a0 \u00a0 MySQL server.<\/p>\r\n<p class=\"p2\">\u00a0 \u00a0 mysql&gt; SHOW DATABASES;<\/p>\r\n<p>&nbsp;<\/p>\r\n<p class=\"p1\"><strong>MariaDB server.<\/strong><\/p>\r\n<p class=\"p2\">MariaDB [(none)]&gt; SHOW DATABASES;<\/p>\r\n<p class=\"p1\">Your (test_database) should be in the list below.<\/p>\r\n<p class=\"p2\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\r\n<p class=\"p2\">| Database <span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>|<\/p>\r\n<p class=\"p2\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\r\n<p class=\"p2\">| information_schema |<\/p>\r\n<p class=\"p2\">| mysql<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>|<\/p>\r\n<p class=\"p2\">| performance_schema |<\/p>\r\n<p class=\"p2\">| sys<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>|<\/p>\r\n<p class=\"p2\">| test_database<span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 <\/span>|<\/p>\r\n<p class=\"p2\">+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/p>\r\n<p class=\"p2\">5 rows in set (0.01 sec)<\/p>\r\n<p>&nbsp;<\/p>\r\n<p class=\"p1\">Create a <b>(test_user),<\/b> and provide it full access to the newly formed database. When testing database connectivity with PHP, you&#8217;ll need this user&#8217;s information. Substitute a powerful value for <b>(EXAMPLE_PASSWORD).<\/b><\/p>\r\n<p class=\"p1\">MySQL server.<\/p>\r\n<p class=\"p2\">mysql&gt; CREATE USER &#8216;test_user&#8217;@&#8217;localhost&#8217; IDENTIFIED WITH mysql_native_password BY &#8216;EXAMPLE_PASSWORD&#8217;;<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0\u00a0 \u00a0 \u00a0 <\/span>GRANT ALL PRIVILEGES ON test_database.* TO &#8216;test_user&#8217;@&#8217;localhost&#8217;;<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0\u00a0 \u00a0 \u00a0 <\/span>FLUSH PRIVILEGES;<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0\u00a0 \u00a0 \u00a0 <\/span>EXIT;<\/p>\r\n<p class=\"p1\">MariaDB server.<\/p>\r\n<p class=\"p2\">MariaDB [(none)]&gt; CREATE USER &#8216;test_user&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;EXAMPLE_PASSWORD&#8217;;<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>GRANT ALL PRIVILEGES ON test_database.* TO &#8216;test_user&#8217;@&#8217;localhost&#8217;;<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>FLUSH PRIVILEGES;<\/p>\r\n<p class=\"p2\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span>EXIT;<\/p>\r\n<p class=\"p1\">Your database server is prepared. You can now install a scripting language.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>\u00a0 \u00a0 \u00a0<strong> 3.How to Install PHP<\/strong><\/p>\r\n<p class=\"p1\">First Step, you&#8217;ll install the PHP package. Run the command below.<\/p>\r\n<p class=\"p2\"><strong>$ sudo apt install -y php<\/strong><\/p>\r\n<p class=\"p1\">Second Step, Since most web applications rely on some PHP extensions, install the most common ones using the command below.<\/p>\r\n<p class=\"p2\"><strong>$ sudo apt install -y php-{common,mysql,xml,xmlrpc,curl,gd,imagick,cli,dev,imap,mbstring,opcache,soap,zip,intl}<\/strong><\/p>\r\n<p class=\"p1\">Restart the Apache webserver then to load PHP.<\/p>\r\n<p class=\"p2\"><strong>$ sudo systemctl restart apache2<\/strong><\/p>\r\n<p class=\"p1\">To test PHP, create an (info.php) file in the root directory of your web server.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p class=\"p1\">After you will enter the information below into the file.<\/p>\r\n<p class=\"p2\">&lt;?php<\/p>\r\n<p class=\"p2\">phpinfo();<\/p>\r\n<p class=\"p1\">Save and close the file by pressing <b>(CTRL + X, then Y and ENTER).<\/b> Then, in a web browser, visit the URL below and replace <b>(127.0.0.1)<\/b> with your server&#8217;s correct public IP address.<\/p>\r\n<p class=\"p5\"><span class=\"s1\"><a href=\"http:\/\/127.0.0.1\/info.php\">http:\/\/127.0.0.1\/info.php<\/a><\/span><\/p>\r\n<p class=\"p1\">You should get a detailed PHP page as shown below.<\/p>\r\n<p>&nbsp;<\/p>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-196\" src=\"https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/php-300x211.jpg\" alt=\"\" width=\"555\" height=\"390\" srcset=\"https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/php-300x211.jpg 300w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/php-1024x721.jpg 1024w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/php-768x541.jpg 768w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/php-1536x1081.jpg 1536w, https:\/\/www.axencloud.com\/blog\/wp-content\/uploads\/2022\/12\/php.jpg 1770w\" sizes=\"auto, (max-width: 555px) 100vw, 555px\" \/><\/p>\r\n<p class=\"p1\"><strong>Next step, test PHP connectivity with the database that you created earlier. Open a new file for editing using nano.<\/strong><\/p>\r\n<p class=\"p2\"><strong>$ sudo nano \/var\/www\/html\/database_test.php<\/strong><\/p>\r\n<p class=\"p1\">After, enter the information below into the file.<\/p>\r\n<p class=\"p2\">&lt;?php<\/p>\r\n<p class=\"p2\">$conn = new mysqli(&#8216;localhost&#8217;, &#8216;test_user&#8217;, &#8216;EXAMPLE_PASSWORD&#8217;, &#8216;test_database&#8217;);<\/p>\r\n<p class=\"p1\">if ($conn-&gt;connect_error) {<\/p>\r\n<p class=\"p1\"><span class=\"Apple-converted-space\">\u00a0 \u00a0 <\/span>die(&#8220;Database connection failed: &#8221; . $conn-&gt;connect_error);<\/p>\r\n<p class=\"p1\">}<\/p>\r\n<p class=\"p1\">echo &#8220;Database connection was successful&#8221;;<\/p>\r\n<p class=\"p4\">Save and close the file. Then, visit the address below in a web browser and replace <b>(192.0.2.1)<\/b> with your server&#8217;s correct public IP address.<\/p>\r\n<p class=\"p5\"><span class=\"s1\"><a href=\"http:\/\/192.0.2.1\/database_test.php\">http:\/\/192.0.2.1\/database_test.php<\/a><\/span><\/p>\r\n<p class=\"p4\">You should get the output below that shows that the script has successfully connected to the database.<\/p>\r\n<p class=\"p1\">echo &#8220;Database connection was successful&#8221;;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>LAMP stands for Linux, Apache, MySQL, and PHP. It is a stack of open-source software. The first layer of the LAMP stack is the well-known Linux Operating System, which offers &#8230;<\/p>\n","protected":false},"author":1,"featured_media":188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=186"}],"version-history":[{"count":7,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":198,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/186\/revisions\/198"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/188"}],"wp:attachment":[{"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.axencloud.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}