{"id":28,"date":"2024-02-05T16:26:05","date_gmt":"2024-02-05T16:26:05","guid":{"rendered":"https:\/\/zahiralam.com\/blog\/?p=28"},"modified":"2024-09-05T10:14:00","modified_gmt":"2024-09-05T10:14:00","slug":"write-a-tutorial-on-installing-apache-php-8","status":"publish","type":"post","link":"https:\/\/zahiralam.com\/blog\/write-a-tutorial-on-installing-apache-php-8\/","title":{"rendered":"From Zero to Web Server: Apache, PHP 8.0, and MySQL 8 Installation on Ubuntu 22.04"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li><h2>Table of Contents<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"#introduction-TlynhxjilZ\">Introduction<\/a><\/li>\n\n\n\n<li><a href=\"#step-by-step-guide-to-installing-apache-php-8-0-and-mysql-8-on-ubuntu-22-04-TlynhxjilZ\">Step-by-Step Guide to Installing Apache, PHP 8.0, and MySQL 8 on Ubuntu 22.04<\/a><\/li>\n\n\n\n<li><a href=\"#faq-installing-apache-php-8-0-and-mysql-8-on-ubuntu-22-04-for-beginners-TlynhxjilZ\">FAQ: Installing Apache, PHP 8.0, and MySQL 8 on Ubuntu 22.04 for Beginners<\/a><\/li>\n\n\n\n<li><a href=\"#conclusion-TlynhxjilZ\">Conclusion<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introduction-TlynhxjilZ\">Introduction<\/h2>\n\n\n\n<p>Embarking on the journey of setting up a web server can be daunting for beginners, but with the right guidance, installing Apache, PHP 8.0, and MySQL 8 on Ubuntu 22.04 can be a smooth process. This tutorial aims to provide a step-by-step guide to help you through the installation, highlighting potential errors and their solutions, and answering frequently asked questions to ensure a comprehensive understanding.\n\n\n\n<p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-by-step-guide-to-installing-apache-php-8-0-and-mysql-8-on-ubuntu-22-04-TlynhxjilZ\">Step-by-Step Guide to Installing Apache, PHP 8.0, and MySQL 8 on Ubuntu 22.04<\/h2>\n\n\n\n<p>Firstly, let&#8217;s start with Apache, the widely-used web server software. Open your terminal and enter the following command to update your package index:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-1\">sudo apt update<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20apt%20update\">\n                            <button class=\"copy-button\" data-label=\"sudo apt update\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>\n\n\n\n<p>Once the update is complete, install Apache using:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-2\">sudo apt install apache2<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20apt%20install%20apache2\">\n                            <button class=\"copy-button\" data-label=\"sudo apt install apache2\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>During the installation, you may be prompted to confirm the process; simply press &#8216;Y&#8217; and then &#8216;Enter&#8217; to proceed. After the installation is complete, you can verify that Apache is running by typing your server&#8217;s IP address into a web browser. If you see the default Ubuntu 22.04 Apache web page, the installation was successful.\n\n\n\n<p>You can also confirm Apache is running with:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-3\">sudo systemctl status apache2<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20systemctl%20status%20apache2\">\n                            <button class=\"copy-button\" data-label=\"sudo systemctl status apache2\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Next, we&#8217;ll install PHP 8.0. PHP is a scripting language commonly used for web development. \n\n\n\n<p>Before installing PHP, you&#8217;ll need to add a third-party repository to get the latest PHP version:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-4\">sudo add-apt-repository ppa:ondrej\/php\nsudo apt update<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20add-apt-repository%20ppa%3Aondrej%2Fphp%0Asudo%20apt%20update\">\n                            <button class=\"copy-button\" data-label=\"sudo add-apt-repository ppa:ondrej\/php\nsudo apt update\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>To install PHP 8.0 and its Apache module and common extensions execute:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-5\">sudo apt install php8.0 libapache2-mod-php8.0 php8.0-mysql php8.0-cli php8.0-curl php8.0-xml<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20apt%20install%20php8.0%20libapache2-mod-php8.0%20php8.0-mysql%20php8.0-cli%20php8.0-curl%20php8.0-xml\">\n                            <button class=\"copy-button\" data-label=\"sudo apt install php8.0 libapache2-mod-php8.0 php8.0-mysql php8.0-cli php8.0-curl php8.0-xml\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Once the installation is complete, you can check the PHP version with:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-6\">php -v<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#php%20-v\">\n                            <button class=\"copy-button\" data-label=\"php -v\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>\n\n\n\n<p>This should display the PHP version confirming that PHP 8.0 is installed.\n\n\n\n<p>Configure Apache to Use PHP\n\n\n\n<p>Edit the Apache configuration file to prioritize PHP files:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-7\">vim \/etc\/apache2\/mods-enabled\/dir.conf<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#vim%20%2Fetc%2Fapache2%2Fmods-enabled%2Fdir.conf\">\n                            <button class=\"copy-button\" data-label=\"vim \/etc\/apache2\/mods-enabled\/dir.conf\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>and Move the <code>index.php<\/code> entry to the first position:\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm<\/pre>\n\n\n\n<p>Press Esc and wq and enter to save.\n\n\n\n<p>Edit \/etc\/apache2\/apache2.conf\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-8\">vim \/etc\/apache2\/apache2.conf<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#vim%20%2Fetc%2Fapache2%2Fapache2.conf\">\n                            <button class=\"copy-button\" data-label=\"vim \/etc\/apache2\/apache2.conf\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>Search for below lines :\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;Directory \/var\/www\/&gt;\n        Options Indexes FollowSymLinks\n        AllowOverride None\n        Require all granted\n&lt;\/Directory&gt;<\/pre>\n\n\n\n<p>and replace None with All . To save press Esc and wq and enter.\n\n\n\n<p>Restart Apache to apply changes:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-9\">sudo systemctl restart apache2<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20systemctl%20restart%20apache2\">\n                            <button class=\"copy-button\" data-label=\"sudo systemctl restart apache2\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>\n\n\n\n<p>Now, let&#8217;s move on to MySQL 8, a popular database management system. Install MySQL by running:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-10\">sudo apt install mysql-server<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20apt%20install%20mysql-server\">\n                            <button class=\"copy-button\" data-label=\"sudo apt install mysql-server\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>During the installation, you may be asked to set a root password. Choose a secure password and keep it safe, as you&#8217;ll need it to manage databases. After the installation, secure your MySQL server by running:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-11\">sudo mysql_secure_installation<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20mysql_secure_installation\">\n                            <button class=\"copy-button\" data-label=\"sudo mysql_secure_installation\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>This script will guide you through several security improvements, including setting up a password for the root user if you haven&#8217;t already done so.\n\n\n\n<p>Restart Mysql:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-12\">sudo systemctl start mysql<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20systemctl%20start%20mysql\">\n                            <button class=\"copy-button\" data-label=\"sudo systemctl start mysql\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>With Apache, PHP, and MySQL installed, you should restart Apache to ensure PHP is fully integrated:\n\n\n\n<div class=\"code-block-container\">\n                        <pre class=\"wp-block-code\"><code id=\"code-13\">sudo systemctl restart apache2<\/code><\/pre>\n                        <amp-iframe sandbox=\"allow-scripts\" width=\"94\" height=\"72\" frameborder=\"0\" \n                                    src=\"https:\/\/zahiralam.com\/blog\/wp-content\/plugins\/amp-copy-code-button\/copier.html#sudo%20systemctl%20restart%20apache2\">\n                            <button class=\"copy-button\" data-label=\"sudo systemctl restart apache2\"  placeholder disabled>Copy<\/button>\n                        <\/amp-iframe>\n                    <\/div>\n\n\n\n<p>\n\n\n\n<p>Throughout the installation process, you may encounter errors such as missing packages or permission issues. If you receive an error about missing packages, ensure your package index is up to date with `sudo apt update`. For permission issues, verify that you are using `sudo` to execute commands that require administrative privileges.\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq-installing-apache-php-8-0-and-mysql-8-on-ubuntu-22-04-for-beginners-TlynhxjilZ\">FAQ: Installing Apache, PHP 8.0, and MySQL 8 on Ubuntu 22.04 for Beginners<\/h2>\n\n\n\n<p>Q: What if I can&#8217;t find PHP 8.0 in the package repository?<br>A: Ensure your system is up to date with `sudo apt update`. If PHP 8.0 is still not available, you may need to add a third-party repository to install it.\n\n\n\n<p>Q: How do I know if Apache installed correctly?<br>A: You can check by visiting your server&#8217;s IP address in a web browser. If you see the default Apache page, it&#8217;s installed correctly.\n\n\n\n<p>Q: What should I do if MySQL doesn&#8217;t ask me to set a root password?<br>A: You can set or change the root password using the `sudo mysql_secure_installation` script.\n\n\n\n<p>Q: What if `apt` doesn&#8217;t recognize `add-apt-repository`?<br>A: Install the software-properties-common package: `sudo apt install software-properties-common`.\n\n\n\n<p>Q: How do I restart Apache if it fails to restart?<br>A: Check the syntax of your Apache configuration files with `sudo apache2ctl configtest`.\n\n\n\n<p>Q: What if I can&#8217;t connect to MySQL?<br>A: Ensure the MySQL service is running with `sudo systemctl status mysql.service`. If it&#8217;s not, start it with `sudo systemctl start mysql.service`.\n\n\n\n<p>Q: How do I change the PHP version Apache uses?<br>A: Disable the current PHP version with `sudo a2dismod phpX.X` and enable the desired version with `sudo a2enmod phpY.Y`, then restart Apache.\n\n\n\n<p>Q: How can I secure my PHP installation?<br>A: Edit the `php.ini` file and disable functions that aren&#8217;t needed, set `expose_php` to Off, and ensure error reporting is configured correctly for production environments.\n\n\n\n<p>Q: How do I find my server&#8217;s IP address?<br>A: Use <code>ip addr show<\/code> or <code>ifconfig<\/code>.\n\n\n\n<p>Q: Can I install other PHP extensions?<br>A: Yes, use <code>sudo apt install php8.0-extension_name<\/code>.\n\n\n\n<div class=\"wp-block-group is-layout-constrained wp-block-group-is-layout-constrained\">\n<div class=\"wp-block-group is-vertical is-layout-flex wp-container-core-group-is-layout-68afab4e wp-block-group-is-layout-flex\">\n<p>Q: Error: MySQL service not starting\n\n\n\n<p>A: If MySQL fails to start, check the error log at <code>\/var\/log\/mysql\/error.log<\/code> for specific details and address the configuration issues mentioned.\n\n\n\n<p>\n<\/div>\n<\/div>\n\n\n\n<p>Q: How can I check if PHP is working with Apache?<br>A: Create a file named <code>info.php<\/code> in <code>\/var\/www\/html\/<\/code> with <code> <\/code>&#8216;&lt;?php echo phpinfo(); ?&gt; &#8216; <code>inside. Access it via<\/code> http:\/\/localhost\/info.php`. If configured correctly, a PHP info page should appear.\n\n\n\n<p>Q: What if I encounter an error I can&#8217;t solve?<br>A: Consult the official documentation for each software package, or seek assistance from community forums or professional support services.\n\n\n\n<p>Remember, setting up a web server is a learning process. Take your time, follow each step carefully, and you&#8217;ll have a functioning Apache, PHP, and MySQL setup on your Ubuntu 22.04 system.\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion-TlynhxjilZ\">Conclusion<\/h2>\n\n\n\n<p>The tutorial provided a comprehensive guide on installing Apache, PHP 8.0, and MySQL 8 on Ubuntu 22.04. Each step was explained briefly. Potential errors and their solutions were also discussed to ensure a smooth installation experience. The FAQ section addressed common questions, making the tutorial accessible to users of varying expertise levels.\n","protected":false},"excerpt":{"rendered":"<p>Introduction Embarking on the journey of setting up a web server can be daunting for beginners, but with the right guidance, installing Apache, PHP 8.0, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":1089,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[13,15,14,16],"class_list":["post-28","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-apache","tag-mysql-8","tag-php-8","tag-ubuntu-22-04"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/comments?post=28"}],"version-history":[{"count":17,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":1090,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/posts\/28\/revisions\/1090"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/media\/1089"}],"wp:attachment":[{"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/media?parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/categories?post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zahiralam.com\/blog\/wp-json\/wp\/v2\/tags?post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}