{"id":12494,"date":"2022-05-02T14:03:29","date_gmt":"2022-05-02T11:03:29","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12494"},"modified":"2024-03-09T14:46:12","modified_gmt":"2024-03-09T11:46:12","slug":"install-lemp-stack-on-ubuntu","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-lemp-stack-on-ubuntu\/","title":{"rendered":"Install LEMP Stack on Ubuntu 22.04"},"content":{"rendered":"\n<p>Welcome to our tutorial on how to install LEMP stack on Ubuntu 22.04. &nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/lemp.io\/\" target=\"_blank\">LEMP Stack<\/a>&nbsp;is a group of open source tools commonly used for developing and deploying&nbsp;web applications. It consists of the Linux Operating System (Ubuntu 22.04 in this case), lightweight and powerful Nginx (Engine-X) web server, MySQL\/MariaDB RDBMS and the server-side scripting language, PHP.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install and Setup LEMP Stack on Ubuntu 22.04<\/h2>\n\n\n\n<p>Run system update<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt upgrade<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install Nginx Web Server on Ubuntu 22.04<\/h3>\n\n\n\n<p>Nginx is available on the default Ubuntu 22.04 repos. It can simply be installed by executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install nginx<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Running Apache<\/h4>\n\n\n\n<p>Once the installation is done, Nginx is started and enabled to run on system boot.<\/p>\n\n\n\n<p>To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status nginx<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf nginx.service - A high performance web server and a reverse proxy server\n     Loaded: loaded (\/lib\/systemd\/system\/nginx.service; enabled; vendor preset: enabled)\n     Active: active (running) since Mon 2022-05-02 10:33:14 UTC; 5min ago\n       Docs: man:nginx(8)\n    Process: 4544 ExecStartPre=\/usr\/sbin\/nginx -t -q -g daemon on; master_process on; (code=exited, status=0\/SUCCESS)\n    Process: 4545 ExecStart=\/usr\/sbin\/nginx -g daemon on; master_process on; (code=exited, status=0\/SUCCESS)\n   Main PID: 4649 (nginx)\n      Tasks: 3 (limit: 2241)\n     Memory: 6.0M\n        CPU: 78ms\n     CGroup: \/system.slice\/nginx.service\n             \u251c\u25004649 \"nginx: master process \/usr\/sbin\/nginx -g daemon on; master_process on;\"\n             \u251c\u25004652 \"nginx: worker process\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\"\n             \u2514\u25004653 \"nginx: worker process\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\"\n\nMay 02 10:33:14 jellyfish systemd[1]: Starting A high performance web server and a reverse proxy server...\nMay 02 10:33:14 jellyfish systemd[1]: Started A high performance web server and a reverse proxy server.\n<\/code><\/pre>\n\n\n\n<p>Check if it is enabled to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl is-enabled nginx<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>enabled<\/strong><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Allow Web Server External Access on Firewall<\/h4>\n\n\n\n<p>You can allow external access to Nginx using the ports or the Nginx application name. For example, to allow access to both Nginx HTTP and HTTPs traffic;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ufw allow 80,443\/tcp<\/code><\/pre>\n\n\n\n<p>Similarly, you can use Nginx app, <strong>Nginx Full<\/strong>, to allow both HTTP and HTTPs;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ufw allow \"Nginx Full\"<\/code><\/pre>\n\n\n\n<p>For HTTP or HTPPS, simple use <strong>Nginx HTTP<\/strong> or <strong>Nginx HTTPS<\/strong> respectively as the app names. <\/p>\n\n\n\n<p>Verify access to Nginx from browser by using the address, <strong><code>http:\/\/Server.IP_or_hostname<\/code><\/strong>. You should land on Nginx HTTP server test page which basically shows that nginx web server is successfully installed and working.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1237\" height=\"377\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/07\/nginx-test-page.png\" alt=\"Install and Setup LEMP Stack on Ubuntu 22.04\" class=\"wp-image-6424\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/07\/nginx-test-page.png?v=1594794813 1237w, https:\/\/kifarunix.com\/wp-content\/uploads\/2020\/07\/nginx-test-page-768x234.png?v=1594794813 768w\" sizes=\"(max-width: 1237px) 100vw, 1237px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Install MySQL\/MariaDB Database Server on Ubuntu 22.04<\/h3>\n\n\n\n<p>You can choose to use MySQL or MariaDB for your RDMS. In this tutorial, we are using MySQL 8 as our database system.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install mysql-server mysql-client<\/code><\/pre>\n\n\n\n<p>When installed, MariaDB is started and enabled to run on system boot.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status mysql<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf mysql.service - MySQL Community Server\n     Loaded: loaded (\/lib\/systemd\/system\/mysql.service; enabled; vendor preset: enabled)\n     Active: active (running) since Mon 2022-05-02 10:44:28 UTC; 1min 23s ago\n    Process: 5498 ExecStartPre=\/usr\/share\/mysql\/mysql-systemd-start pre (code=exited, status=0\/SUCCESS)\n   Main PID: 5506 (mysqld)\n     Status: \"Server is operational\"\n      Tasks: 37 (limit: 2241)\n     Memory: 358.2M\n        CPU: 1.208s\n     CGroup: \/system.slice\/mysql.service\n             \u2514\u25005506 \/usr\/sbin\/mysqld\n\nMay 02 10:44:26 jellyfish systemd[1]: Starting MySQL Community Server...\nMay 02 10:44:28 jellyfish systemd[1]: Started MySQL Community Server.\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Securing MariaDB<\/h4>\n\n\n\n<p>MariaDB ships with some initial security script called <code>mysql_secure_installation<\/code>. When run, this script removes all test databases, disables remote root account login and remove test user accounts as part of the initial security checks.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql_secure_installation<\/code><\/pre>\n\n\n\n<p>You can now login and create a database and database user as required by whatever application you want to run.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Install PHP and Other Required PHP Modules on Ubuntu 22.04<\/h3>\n\n\n\n<p>Next, install PHP on Ubuntu 22.04.<\/p>\n\n\n\n<p>By default, Ubuntu 22.04 ships with PHP 8.x in its default repos. Hence, installation of PHP 8.x is as simple as running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install php php-fpm php-mysql<\/code><\/pre>\n\n\n\n<p>This will install alongside itself other default PHP modules.<\/p>\n\n\n\n<p>To install Other versions of PHP, check the link below;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-php-7-1-7-2-7-3-7-4-on-ubuntu-22-04\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install PHP 7.1\/7.2\/7.3\/7.4 on Ubuntu 22.04<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Install Other Required PHP Modules<\/h4>\n\n\n\n<p>If any other required modules needs to be installed, you can simply install it by running the command, <code><strong>apt install php-extension<\/strong><\/code>, where <strong>extension<\/strong> is the name of the PHP module. For example;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install php-{bcmath,bz2,imap,intl,mbstring,soap,sybase,xml,zip}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Nginx for PHP Processing<\/h3>\n\n\n\n<p>For Nginx to process PHP pages, you need to include&nbsp;<strong>index.php<\/strong>&nbsp;as a value for the&nbsp;<strong>index<\/strong>&nbsp;parameter. Since we are using the default configuration for testing, edit the it as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/nginx\/sites-enabled\/default<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n        root \/var\/www\/html;\n\n        # Add index.php to the list if you are using PHP\n        index <strong>index.php<\/strong> index.html index.htm index.nginx-debian.html;\n...<\/code><\/pre>\n\n\n\n<p>Also, you need to configure Nginx to pass PHP scripts to FastCGI server. Uncomment the line&nbsp;<code>location ~ \\.php$<\/code>&nbsp;and configure it as shown below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        location ~ \\.php$ {\n                include snippets\/fastcgi-php.conf;\n                fastcgi_pass unix:\/run\/php\/php7.4-fpm.sock;\n        }<\/code><\/pre>\n\n\n\n<p>Save and exit the file,<\/p>\n\n\n\n<p>Test Nginx configuration syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>nginx -t<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>nginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/code><\/pre>\n\n\n\n<p>Restart Nginx and FastCGI process manager, if there is no configuration syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart nginx php8.1-fpm<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Testing Nginx PHP Processing&nbsp;on Ubuntu 22.04<\/h4>\n\n\n\n<p>You can test Nginx PHP processing to confirm that is working as required as well check the version and installed modules using the simple PHP info script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"&lt;?php phpinfo(); ?&gt;\" &gt; \/var\/www\/html\/index.php<\/code><\/pre>\n\n\n\n<p>Next, navigate to the browser and enter the address,&nbsp;<strong>http:\/\/&lt;server-IP-or-hostname&gt;\/index.php<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1035\" height=\"934\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nginx-php-ubuntu-22.04.png\" alt=\"\" class=\"wp-image-12510\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nginx-php-ubuntu-22.04.png?v=1651489252 1035w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nginx-php-ubuntu-22.04-768x693.png?v=1651489252 768w\" sizes=\"(max-width: 1035px) 100vw, 1035px\" \/><\/figure><\/div>\n\n\n<p>And there you go. Your LEMP stack is installed on Ubuntu 22.04. Ensure that all the required php modules for the specific application you want to deploy are met.<\/p>\n\n\n\n<p>Once you have verified Nginx PHP processing, remove the PHP info file;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>rm -rf \/var\/www\/html\/index.php<\/code><\/pre>\n\n\n\n<p>That marks the end of our guide on how to install and setup LEMP Stack on Ubuntu 22.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-mysql-8-on-rocky-linux-8\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install MySQL 8 on Rocky Linux 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-guacamole-mysql-database-authentication\/\" target=\"_blank\" rel=\"noreferrer noopener\">Configure Guacamole MySQL Database Authentication<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to our tutorial on how to install LEMP stack on Ubuntu 22.04. &nbsp;LEMP Stack&nbsp;is a group of open source tools commonly used for developing<\/p>\n","protected":false},"author":1,"featured_media":12497,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,299,235,342],"tags":[5007,5006,1010,4412,5008],"class_list":["post-12494","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-database","category-lemp-stack","category-php","tag-install-lemp-stack-ubuntu-22-04","tag-install-lemp-ubuntu-22-04","tag-lemp-stack","tag-ubuntu-22-04","tag-ubuntu-22-04-lemp-stack","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12494"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=12494"}],"version-history":[{"count":4,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12494\/revisions"}],"predecessor-version":[{"id":20550,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12494\/revisions\/20550"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/12497"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=12494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=12494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=12494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}