This comprehensive guide walks you through the process of configuring a secure and dynamic website using the LAMP stack (Linux, Apache, MySQL, PHP) on Arch Linux. We'll cover installing the necessary packages, enabling virtual hosting, securing your website with SSL, and integrating PHP for dynamic content generation.
Apache: The web server that will handle incoming requests and serve website content.sudo pacman -S apache
MySQL: A robust and popular open-source database management system to store and manage website data.sudo pacman -S mysql
PHP: A versatile scripting language that allows for dynamic website development, database interaction, and more.sudo pacman -S php
Secure MySQL Installation: sudo mysql_secure_installation
This script will guide you through setting a root password, removing anonymous users, disabling remote root login, and other security measures.
Create a Virtual Host Directory: sudo mkdir /srv/http/your-domain.com
Replace your-domain.com with your actual domain name. Create a Virtual Host Configuration File: sudo nano /etc/httpd/conf.d/your-domain.com.conf
Within this file, you'll configure your virtual host. Here's an example configuration: <VirtualHost *:80> ServerName your-domain.com DocumentRoot /srv/http/your-domain.com <Directory /srv/http/your-domain.com> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Explanation: ServerName : This specifies the domain name for the website.DocumentRoot : This points to the directory where your website files will reside.<Directory> : This section defines the access permissions and settings for the website's directory.
Enable the Virtual Host: sudo a2ensite your-domain.com.conf
Restart Apache: sudo systemctl restart httpd
Open your web browser and navigate to http://your-domain.com.If you see the default Apache welcome page, your virtual host is set up successfully.
Install Necessary Packages: sudo pacman -S certbot python3-certbot-apache mod_ssl
Obtain and Install SSL Certificate: sudo certbot --apache -d your-domain.com -d www.your-domain.com
This command will use Certbot to obtain and install an SSL certificate for your domain. It will also automatically configure Apache to use the certificate and redirect HTTP traffic to HTTPS. Verify HTTPS Access: Open your web browser and navigate to https://your-domain.com. You should now be accessing your website over a secure HTTPS connection.
Enable PHP Module: Open the Apache configuration file: sudo nano /etc/httpd/conf/httpd.conf
Uncomment the LoadModule statement for PHP: #LoadModule mpm_event_module modules/mod_mpm_event.so
Create a new file for the PHP module configuration: sudo nano /etc/httpd/conf/mods-enabled/php.conf
Add the following content to the file: LoadModule mpm_prefork_module modules/mod_mpm_prefork.so LoadModule php_module modules/libphp.so AddHandler php-script .php Include conf/extra/php_module.conf
Test PHP Integration: Create a PHP info file: echo "<?php phpinfo(); ?>" | sudo tee /srv/http/your-domain.com/info.php
Restart Apache: sudo systemctl restart httpd
Access the PHP info page: Open your web browser and navigate to https://your-domain.com/info.php. You should see a page displaying information about your PHP installation.
Test Apache syntax: sudo apachectl configtest
List loaded modules: sudo apachectl -M
0 comments:
Post a Comment