loader

If you’ve set up a LAMP (Linux, Apache, MySQL, PHP) stack on Amazon Linux 2023, you’ll need to know how to manage it efficiently. In this guide, we’ll cover common commands for restarting services, editing configuration files, troubleshooting, and more.

1. Managing Apache (httpd) Service

Apache is the web server in your LAMP stack. Here’s how to control it:

Start, Stop, or Restart Apache
# Start Apache  
sudo systemctl start httpd  

# Stop Apache  
sudo systemctl stop httpd  

# Restart Apache (use after configuration changes)  
sudo systemctl restart httpd  

# Reload Apache (without downtime)  
sudo systemctl reload httpd  

# Check Apache status  
sudo systemctl status httpd  
Enable Apache to Start on Boot
sudo systemctl enable httpd  

2. Editing Configuration Files

Locate and Edit php.ini

The PHP configuration file (php.ini) is critical for PHP settings. Use:

# Find the location of php.ini (PHP 8.1 example)  
php --ini | grep "Loaded Configuration File"  

# Edit the file with nano/vim  
sudo nano /etc/php-8.1/php.ini  
Edit Apache Configuration

Apache’s main configuration file:

sudo nano /etc/httpd/conf/httpd.conf  

For virtual hosts:

sudo nano /etc/httpd/conf.d/your-site.conf  
Edit the Hosts File

Temporarily map domains for testing:

sudo nano /etc/hosts  

3. Checking PHP Information

Create a phpinfo.php file to verify PHP is working:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/phpinfo.php  

Access it via http://your-server-ip/phpinfo.php. Remove the file afterward for security:

sudo rm /var/www/html/phpinfo.php  

4. Checking Logs for Debugging

Apache Logs
  • Access logs: /var/log/httpd/access_log

  • Error logs: /var/log/httpd/error_log

Tail logs in real-time:

sudo tail -f /var/log/httpd/error_log  
Updating Packages

Keep your system and LAMP stack updated:

sudo dnf update  
File Permissions

Fix permissions for web directories:

sudo chown -R apache:apache /var/www/html  
sudo chmod -R 755 /var/www/html  
Common PHP-Related Commands

Check PHP version:

php -v  
Author

by admin