Skip to content

Instantly share code, notes, and snippets.

@huynhsamha
Last active May 16, 2024 03:10
Show Gist options
  • Save huynhsamha/989aa8273079b00d2eadbac7d4305f32 to your computer and use it in GitHub Desktop.
Save huynhsamha/989aa8273079b00d2eadbac7d4305f32 to your computer and use it in GitHub Desktop.
Config XAMPP with NGINX on Ubuntu 16.04 AWS EC2

Install NGINX

bla bla...

Install XAMPP

# Download
wget https://www.apachefriends.org/xampp-files/7.2.2/xampp-linux-x64-7.2.2-0-installer.run

# Install
chmod +x xampp-linux-x64-5.6.33-0-installer.run
sudo ./xampp-linux-x64-7.2.2-0-installer.run

Start - Restart - Stop

Nginx

sudo service nginx start

sudo service nginx restart

Xampp

sudo /opt/lampp/lampp start

sudo /opt/lampp/lampp stop

sudo /opt/lampp/lampp restart

Configure port

Default Xampp (Apache) and Nginx listen on port 80.

Run Nginx for serve static and proxy server for apache.

Run Apache listen on other port (eg. 8058), Nginx port 80. Nginx listen 80 and proxy to 8058 for Apache.

Change port Apache

File httpd.conf

cd /opt/lampp/etc

sudo vim httpd.conf

# Changes:
Listen 80 -> Listen 8058
ServerName localhost -> Servername localhost:8058

File lampp

sudo vim /opt/lampp/lampp

# Changes
if testport 80 -> if testport 8058

Start XAMPP

sudo /opt/lampp/lampp start

Maybe error, use:

sudo /etc/init.d/apache2 stop
sudo /etc/init.d/mysql stop
sudo /etc/init.d/proftpd stop

Config Proxy Nginx for Apache

Config in /etc/nginx/sites-available. Copy file default to new file (eg. apachefile) and change as:

server {
	listen 80;
	listen [::]:80;

	server_name abc.xyz.com;

	location / {
		proxy_pass http://localhost:8058; # port Apache
        	proxy_http_version 1.1;
       		proxy_set_header Upgrade $http_upgrade;
        	proxy_set_header Connection 'upgrade';
        	proxy_set_header Host $host;
        	proxy_cache_bypass $http_upgrade;
	}
}

Soft link to sites-enable

sudo ln -s /etc/nginx/sites-availabel/apachefile /etc/nginx/sites-enable/apachefile

Restart

sudo service nginx restart

View port is running

sudo netstat -tlnp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      18009/mongod    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      28029/nginx -g daem
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1199/sshd       
tcp6       0      0 :::443                  :::*                    LISTEN      28484/httpd     
tcp6       0      0 :::80                   :::*                    LISTEN      29029/nginx -g daem
tcp6       0      0 :::21                   :::*                    LISTEN      21283/proftpd: (acc
tcp6       0      0 :::22                   :::*                    LISTEN      1289/sshd       
tcp6       0      0 :::8058                 :::*                    LISTEN      20684/httpd  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment